module Grammar

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.

Public Class Methods

parse_grammar(text, original, source_map) click to toggle source

Parse the preprocessed emerald text and print failure if it fails the parsing stage

# 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