Module: Antelope::Grammar::Symbols
- Included in:
- Antelope::Grammar
- Defined in:
- lib/antelope/grammar/symbols.rb
Overview
Manages a list of the symbols in the grammar.
Instance Method Summary collapse
-
#contains_error_token? ⇒ Boolean
Checks to see if the grammar uses the
error
terminal anywhere. -
#nonterminals ⇒ Array<Symbol>
A list of all nonterminals in the grammar.
-
#symbols ⇒ Array<Token::Terminal, Symbol>
A list of all symbols in the grammar; includes both terminals and nonterminals.
-
#terminals ⇒ Array<Token::Terminal>
A list of all terminals in the grammar.
-
#typed_nonterminals ⇒ Array<Token::Nonterminal>
A list of all nonterminals, with types.
Instance Method Details
#contains_error_token? ⇒ Boolean
Checks to see if the grammar uses the error
terminal
anywhere.
59 60 61 |
# File 'lib/antelope/grammar/symbols.rb', line 59 def contains_error_token? all_productions.any? { |_| _.items.any?(&:error?) } end |
#nonterminals ⇒ Array<Symbol>
A list of all nonterminals in the grammar.
26 27 28 |
# File 'lib/antelope/grammar/symbols.rb', line 26 def nonterminals @_nonterminals ||= productions.keys end |
#symbols ⇒ Array<Token::Terminal, Symbol>
A list of all symbols in the grammar; includes both terminals and nonterminals.
51 52 53 |
# File 'lib/antelope/grammar/symbols.rb', line 51 def symbols @_symbols ||= terminals + nonterminals end |
#terminals ⇒ Array<Token::Terminal>
A list of all terminals in the grammar. Checks the compiler options for terminals, and then returns an array of terminals. Caches the result.
14 15 16 17 18 19 20 |
# File 'lib/antelope/grammar/symbols.rb', line 14 def terminals @_terminals ||= begin @compiler..fetch(:terminals) { [] }.map do |v| Token::Terminal.new(*v) end end end |
#typed_nonterminals ⇒ Array<Token::Nonterminal>
A list of all nonterminals, with types.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/antelope/grammar/symbols.rb', line 33 def typed_nonterminals @_typed_nonterminals ||= begin typed = [] compiler.[:nonterminals].each do |data| data[1].each do |nonterm| typed << Token::Nonterminal.new(nonterm, data[0]) end end typed end end |