Module: Grammar
- Defined in:
- lib/emerald/grammar.rb
Overview
Interface which interacts with emerald context free grammar. Parses the preprocessed Emerald and prints out success if the parser was successful and failure if there was an error when parsing. Returns an abstract syntax tree.
Defined Under Namespace
Classes: ParserError, PreProcessorError
Class Method Summary collapse
-
.parse_grammar(text, original, source_map) ⇒ Object
Parse the preprocessed emerald text and print failure if it fails the parsing stage.
Class Method Details
.parse_grammar(text, original, source_map) ⇒ Object
Parse the preprocessed emerald text and print failure if it fails the parsing stage
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/emerald/grammar.rb', line 69 def self.parse_grammar(text, original, source_map) parsed = @parser.parse(text) if parsed.nil? source_line = source_map[@parser.failure_line][:source_line] if source_line.nil? raise PreProcessorError.new( @parser.failure_line, @parser.failure_reason, text ) end raise ParserError.new( source_line, @parser.failure_reason, original ) end parsed end |