Sha256: 991dbc90eaa12236950f68c3282de36e6591a4db5d0b77b9464e24781d557adc

Contents?: true

Size: 1.47 KB

Versions: 1

Compression:

Stored size: 1.47 KB

Contents

module Treetop
  module Runtime
    class SyntaxNode

      def to_ruby(dependencies)
        if nonterminal?
          value = ""
          elements.each { |element| value << element.to_ruby(dependencies) }
          _add_dependency(dependencies, extract(value))
          rewrite_ruby(value)
        else
          _add_dependency(dependencies, extract(text_value))
          rewrite_ruby(text_value)
        end
      end

      def to_compiled_ruby
        if nonterminal?
          value = ""
          elements.each { |element| value << element.to_compiled_ruby }
          compile_ruby(value)
        else
          compile_ruby(text_value)
        end
      end

      def to_javascript(dependencies)
        if nonterminal?
          value = ""
          elements.each { |element| value << element.to_javascript(dependencies) }
          _add_dependency(dependencies, extract(value))
          rewrite_javascript(value)
        else
          _add_dependency(dependencies, extract(text_value))
          rewrite_javascript(text_value)
        end
      end

      def compile_ruby(value)
        value
      end

      def rewrite_ruby(value)
        value
      end

      def rewrite_javascript(value)
        value
      end

      def extract(value)
      end

    private

      def _add_dependency(dependencies, value)
        return if value.nil?
        dependencies << value
        dependencies.flatten!
        dependencies.compact!
        dependencies.uniq!
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
soroban-0.7.2 lib/soroban/parser/rewrite.rb