Sha256: d2604cf3ad981cb614caae4ac505dca53cfdcd60233179ee43c60fb31678b190

Contents?: true

Size: 1.24 KB

Versions: 1

Compression:

Stored size: 1.24 KB

Contents

module Treetop
  class Protometagrammar
    class TerminalSymbolExpressionBuilder < ParsingExpressionBuilder
      module TerminalStringSyntaxNode
        def prefix
          elements[1].text_value
        end
      
        def value
          TerminalSymbol.new(prefix)
        end
      end
    
      def build
        seq(choice(single_quoted_string, double_quoted_string, :character_class, :anything_symbol),
            :trailing_block) do
          def value(grammar = nil)
            trailing_block.value(terminal.value)
          end
        
          def terminal
            elements[0]
          end
        
          def trailing_block
            elements[1]
          end
        end
      end
    
      def double_quoted_string
        seq('"', zero_or_more(double_quoted_string_char), '"') do
          include TerminalStringSyntaxNode
        end
      end
    
      def double_quoted_string_char
        seq(notp('"'), choice(escaped('"'), any))
      end
    
      def single_quoted_string
        seq("'", zero_or_more(single_quoted_string_char), "'") do
          include TerminalStringSyntaxNode
        end
      end
    
      def single_quoted_string_char
        seq(notp("'"), choice(escaped("'"), any))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
treetop-0.1.0 lib/treetop/protometagrammar/terminal_symbol_expression_builder.rb