Class: Aurum::Grammar
- Inherits:
-
Object
- Object
- Aurum::Grammar
- Defined in:
- lib/aurum/grammar.rb
Class Method Summary collapse
- .character_classes(&block) ⇒ Object
- .lexer(input) ⇒ Object
- .method_missing(name, input) ⇒ Object
- .precedences(&block) ⇒ Object
- .productions(&block) ⇒ Object
- .start_from(start_symbol) ⇒ Object
- .tokens(&block) ⇒ Object
Class Method Details
.character_classes(&block) ⇒ Object
181 182 183 184 |
# File 'lib/aurum/grammar.rb', line 181 def self.character_classes &block @lexical_sepcification = LexicalSpecification.new unless @lexical_sepcification @lexical_sepcification.character_classes.instance_eval &block end |
.lexer(input) ⇒ Object
201 202 203 204 205 206 207 |
# File 'lib/aurum/grammar.rb', line 201 def self.lexer input @productions = ProductionDefinition.new unless @productions @lexical_sepcification.definitions[:initial].merge!(@productions.__literals) generator = Aurum::LexicalTableGenerator.new @lexical_sepcification.definitions table, accepts = generator.lexical_table Aurum::Lexer.new table, accepts, generator.lexical_states, input end |
.method_missing(name, input) ⇒ Object
218 219 220 221 222 223 224 |
# File 'lib/aurum/grammar.rb', line 218 def self.method_missing name, input name_string = name.to_s if name_string =~ /^parse_/ start_nonterminal = name_string.split(/^parse_/).last self.start_from(start_nonterminal).parse self.lexer(input) end end |
.precedences(&block) ⇒ Object
191 192 193 194 |
# File 'lib/aurum/grammar.rb', line 191 def self.precedences &block @precedences = OperatorPrecedenceDefinition.new unless @precedences @precedences.instance_eval &block end |
.productions(&block) ⇒ Object
196 197 198 199 |
# File 'lib/aurum/grammar.rb', line 196 def self.productions &block @productions = ProductionDefinition.new unless @productions @productions.instance_eval &block end |
.start_from(start_symbol) ⇒ Object
209 210 211 212 213 214 215 216 |
# File 'lib/aurum/grammar.rb', line 209 def self.start_from start_symbol @productions = ProductionDefinition.new unless @productions @precedences = OperatorPrecedenceDefinition.new unless @precedences generator = Aurum::ParsingTableGenerator.new @productions.__definitions, @precedences.precedences, @precedences.associativities productions = generator.start_from(Aurum::Symbol.new(start_symbol.to_s, false)).productions table, lookeahead_level = generator.parsing_table Aurum::Parser.new productions, table end |
.tokens(&block) ⇒ Object
186 187 188 189 |
# File 'lib/aurum/grammar.rb', line 186 def self.tokens &block @lexical_sepcification = LexicalSpecification.new unless @lexical_sepcification @lexical_sepcification.instance_eval &block end |