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

Instance Method Details

#contains_error_token?Boolean

Checks to see if the grammar uses the error terminal anywhere.

Returns:

  • (Boolean)


59
60
61
# File 'lib/antelope/grammar/symbols.rb', line 59

def contains_error_token?
  all_productions.any? { |_| _.items.any?(&:error?) }
end

#nonterminalsArray<Symbol>

A list of all nonterminals in the grammar.

Returns:

  • (Array<Symbol>)

See Also:



26
27
28
# File 'lib/antelope/grammar/symbols.rb', line 26

def nonterminals
  @_nonterminals ||= productions.keys
end

#symbolsArray<Token::Terminal, Symbol>

A list of all symbols in the grammar; includes both terminals and nonterminals.

Returns:

See Also:



51
52
53
# File 'lib/antelope/grammar/symbols.rb', line 51

def symbols
  @_symbols ||= terminals + nonterminals
end

#terminalsArray<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.

Returns:



14
15
16
17
18
19
20
# File 'lib/antelope/grammar/symbols.rb', line 14

def terminals
  @_terminals ||= begin
    @compiler.options.fetch(:terminals) { [] }.map do |v|
      Token::Terminal.new(*v)
    end
  end
end

#typed_nonterminalsArray<Token::Nonterminal>

A list of all nonterminals, with types.

Returns:



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.options[:nonterminals].each do |data|
      data[1].each do |nonterm|
        typed << Token::Nonterminal.new(nonterm, data[0])
      end
    end
    typed
  end
end