Sha256: 0da8f961ab65461d4a5dc56228830b2f860e10dffe7741d9ea31632a2d11aca9

Contents?: true

Size: 940 Bytes

Versions: 1

Compression:

Stored size: 940 Bytes

Contents

module Treetop
  class Protometagrammar
    class NonterminalSymbolExpressionBuilder < ParsingExpressionBuilder
      def build
        seq(notp(naked_keyword), nonterminal_symbol) do
          def value(grammar)
            nonterminal_symbol.value(grammar)
          end
        
          def nonterminal_symbol
            elements[1]
          end
        end
      end

      def naked_keyword
        seq(:keyword, notp(alphanumeric_char))
      end

      def nonterminal_symbol
        seq(alpha_char, zero_or_more(alphanumeric_char)) do
          def value(grammar)
            grammar.nonterminal_symbol(name)
          end

          def name
            text_value.to_sym
          end
        end
      end

      def alpha_char
        char_class('A-Za-z_')
      end

      def numeric_char
        char_class('0-9')
      end

      def alphanumeric_char
        choice(alpha_char, numeric_char)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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