class Gobstones::Parser::TreetopParser

Public Class Methods

new() click to toggle source
# File lib/gobstones/parser/treetop_parser.rb, line 8
def initialize
  Treetop.load grammar_file
  @parser = GobstonesParser.new
end

Public Instance Methods

failure_column() click to toggle source
# File lib/gobstones/parser/treetop_parser.rb, line 29
def failure_column
  @parser.failure_column
end
failure_line() click to toggle source
# File lib/gobstones/parser/treetop_parser.rb, line 25
def failure_line
  @parser.failure_line
end
failure_reason() click to toggle source
# File lib/gobstones/parser/treetop_parser.rb, line 21
def failure_reason
  @parser.failure_reason
end
parse(code) click to toggle source
# File lib/gobstones/parser/treetop_parser.rb, line 13
def parse(code)
  code_without_comments = remove_comments_from(code)
  result = @parser.parse(code_without_comments)
  raise ParseError.new(self, code_without_comments) if result.nil?

  result.value
end
remove_comments_from(code) click to toggle source
# File lib/gobstones/parser/treetop_parser.rb, line 33
def remove_comments_from(code)
  code.
    gsub(single_line_c_style_comments_regex, '').
    gsub(single_line_haskell_style_comments_regex, '').
    gsub(multi_line_c_style_comments_regex, '').
    gsub(multi_line_haskell_style_comments_regex, '')
end

Private Instance Methods

base_path() click to toggle source
# File lib/gobstones/parser/treetop_parser.rb, line 47
def base_path
  __dir__
end
grammar_file() click to toggle source
# File lib/gobstones/parser/treetop_parser.rb, line 43
def grammar_file
  File.join(base_path, 'grammar/gobstones')
end
multi_line_c_style_comments_regex() click to toggle source
# File lib/gobstones/parser/treetop_parser.rb, line 59
def multi_line_c_style_comments_regex
  /\/\*.*?\*\//m
end
multi_line_haskell_style_comments_regex() click to toggle source
# File lib/gobstones/parser/treetop_parser.rb, line 63
def multi_line_haskell_style_comments_regex
  /{-.*?-}/m
end
single_line_c_style_comments_regex() click to toggle source
# File lib/gobstones/parser/treetop_parser.rb, line 51
def single_line_c_style_comments_regex
  /\/\/.*$/
end
single_line_haskell_style_comments_regex() click to toggle source
# File lib/gobstones/parser/treetop_parser.rb, line 55
def single_line_haskell_style_comments_regex
  /--.*$/
end