Class: RippleParser

Inherits:
Object
  • Object
show all
Defined in:
lib/lydown/translation/ripple.rb

Class Method Summary collapse

Class Method Details

.format_parser_error(source, parser, opts) ⇒ Object



25
26
27
28
29
# File 'lib/lydown/translation/ripple.rb', line 25

def self.format_parser_error(source, parser, opts)
  msg = "#{parser.failure_reason} at #{parser.failure_line}:#{parser.failure_column}\n"
  # msg << "  #{source.lines[parser.failure_line - 1].chomp}\n #{' ' * parser.failure_column}^"
  msg
end

.parse(source, opts = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/lydown/translation/ripple.rb', line 8

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
  end
  ast
end

.translate(source, opts) ⇒ Object



19
20
21
22
23
# File 'lib/lydown/translation/ripple.rb', line 19

def self.translate(source, opts)
  ast = parse(source)
  stream = ''
  ast.translate(stream, opts.merge(source: source))
end