module Antelope::Grammar::Symbols

Manages a list of the symbols in the grammar.

Public Instance Methods

contains_error_token?() click to toggle source

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

@return [Boolean]

# File lib/antelope/grammar/symbols.rb, line 59
def contains_error_token?
  all_productions.any? { |_| _.items.any?(&:error?) }
end
nonterminals() click to toggle source

A list of all nonterminals in the grammar.

@return [Array<Symbol>] @see productions

# File lib/antelope/grammar/symbols.rb, line 26
def nonterminals
  @_nonterminals ||= productions.keys
end
symbols() click to toggle source

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

@return [Array<Token::Terminal, Symbol>] @see terminals @see nonterminals

# File lib/antelope/grammar/symbols.rb, line 51
def symbols
  @_symbols ||= terminals + nonterminals
end
terminals() click to toggle source

A list of all terminals in the grammar. Checks the compiler options for terminals, and then returns an array of terminals. Caches the result.

@return [Array<Token::Terminal>]

# 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_nonterminals() click to toggle source

A list of all nonterminals, with types.

@return [Array<Token::Nonterminal>>]

# 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