Class: LydownParser
- Inherits:
-
Object
- Object
- LydownParser
- Defined in:
- lib/lydown/parsing.rb
Overview
Treetop.load ‘lydown/parsing/lydown’
Class Method Summary collapse
Class Method Details
.format_parser_error(source, parser, opts) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lydown/parsing.rb', line 22 def self.format_parser_error(source, parser, opts) msg = opts[:source_filename] ? "#{opts[:source_filename]}: " : "" if opts[:nice_error] msg << "Unexpected character at line #{parser.failure_line} column #{parser.failure_column}:\n" else msg << "#{parser.failure_reason}:\n" end msg << " #{source.lines[parser.failure_line - 1].chomp}\n #{' ' * parser.failure_column}^" msg end |
.parse(source, opts = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/lydown/parsing.rb', line 10 def self.parse(source, opts = {}) parser = self.new ast = parser.parse(source) unless ast error_msg = format_parser_error(source, parser, opts) STDERR.puts error_msg raise LydownError, error_msg else ast.to_stream end end |