Class: Antelope::Grammar

Inherits:
Object
  • Object
show all
Includes:
Generation, Loading, Precedences, Productions, Symbols
Defined in:
lib/antelope/grammar.rb,
lib/antelope/grammar/token.rb,
lib/antelope/grammar/loading.rb,
lib/antelope/grammar/symbols.rb,
lib/antelope/grammar/generation.rb,
lib/antelope/grammar/precedence.rb,
lib/antelope/grammar/production.rb,
lib/antelope/grammar/precedences.rb,
lib/antelope/grammar/productions.rb,
lib/antelope/grammar/token/error.rb,
lib/antelope/grammar/token/epsilon.rb,
lib/antelope/grammar/token/terminal.rb,
lib/antelope/grammar/token/nonterminal.rb

Overview

Defines a grammar from an Ace file. This handles setting up productions, loading from files, symbols, precedence, and generation.

Defined Under Namespace

Modules: Generation, Loading, Precedences, Productions, Symbols Classes: Precedence, Production, Token

Constant Summary collapse

DEFAULT_MODIFIERS =

The default modifiers for generation. It's not really recommended to (heh) modify this; however, adding your own modifier is always acceptable.

[
  [:recognizer,  Generation::Recognizer ],
  [:constructor, Generation::Constructor],
  [:tableizer,   Generation::Tableizer  ]
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Generation

#find_generators, #generate

Methods included from Loading

included

Methods included from Precedences

#generate_precedence, #precedence, #precedence_for

Methods included from Productions

#all_productions, #default_production, #find_token, #generate_production_for, #generate_productions, #productions, #type_for

Methods included from Symbols

#contains_error_token?, #nonterminals, #symbols, #terminals, #typed_nonterminals

Constructor Details

#initialize(name, output, compiler) ⇒ Grammar

Initialize.

Parameters:

  • name (String)
  • output (String)

    the output directory. Automagically turned into a Pathname.

  • compiler (Compiler)


54
55
56
57
58
# File 'lib/antelope/grammar.rb', line 54

def initialize(name, output, compiler)
  @name     = name
  @output   = Pathname.new(output)
  @compiler = compiler
end

Instance Attribute Details

#compilerCompiler (readonly)

The compiler for the Ace file.

Returns:

  • (Compiler)


46
47
48
# File 'lib/antelope/grammar.rb', line 46

def compiler
  @compiler
end

#nameString

The name of the grammar. This is normally assumed from a file name.

Returns:

  • (String)


35
36
37
# File 'lib/antelope/grammar.rb', line 35

def name
  @name
end

#outputPathname

The output directory for the grammar. This is normally the same directory as the Ace file.

Returns:

  • (Pathname)


41
42
43
# File 'lib/antelope/grammar.rb', line 41

def output
  @output
end

#statesSet<Generation::Recognizer::State>

Used by a generation class; this is all the generated states of the grammar.



29
30
31
# File 'lib/antelope/grammar.rb', line 29

def states
  @states
end

Instance Method Details

#optionsHash

Extra options from the compiler. This can be used by generators for output information.

Returns:

  • (Hash)


64
65
66
# File 'lib/antelope/grammar.rb', line 64

def options
  compiler.options[:extra]
end