Class: Gobstones::Parser::TreetopParser
- Inherits:
-
Object
- Object
- Gobstones::Parser::TreetopParser
- Defined in:
- lib/gobstones/parser/treetop_parser.rb
Instance Method Summary collapse
- #failure_column ⇒ Object
- #failure_line ⇒ Object
- #failure_reason ⇒ Object
-
#initialize ⇒ TreetopParser
constructor
A new instance of TreetopParser.
- #parse(code) ⇒ Object
- #remove_comments_from(code) ⇒ Object
Constructor Details
#initialize ⇒ TreetopParser
Returns a new instance of TreetopParser.
8 9 10 11 |
# File 'lib/gobstones/parser/treetop_parser.rb', line 8 def initialize Treetop.load grammar_file @parser = GobstonesParser.new end |
Instance Method Details
#failure_column ⇒ Object
29 30 31 |
# File 'lib/gobstones/parser/treetop_parser.rb', line 29 def failure_column @parser.failure_column end |
#failure_line ⇒ Object
25 26 27 |
# File 'lib/gobstones/parser/treetop_parser.rb', line 25 def failure_line @parser.failure_line end |
#failure_reason ⇒ Object
21 22 23 |
# File 'lib/gobstones/parser/treetop_parser.rb', line 21 def failure_reason @parser.failure_reason end |
#parse(code) ⇒ Object
13 14 15 16 17 18 19 |
# 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) ⇒ Object
33 34 35 36 37 38 39 |
# 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 |