Class: Syme::Parser
- Inherits:
-
Object
- Object
- Syme::Parser
- Defined in:
- lib/syme/bootstrap/parser.rb
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
A new instance of Parser.
-
#parse(string) ⇒ Object
The #parse_string method is defined in the parser C extension.
- #parse_file(name) ⇒ Object
-
#show_syntax_error ⇒ Object
Parsing callbacks.
- #syntax_error(pos) ⇒ Object
Constructor Details
#initialize ⇒ Parser
Returns a new instance of Parser.
3 4 5 |
# File 'lib/syme/bootstrap/parser.rb', line 3 def initialize @error_position = 0 end |
Instance Method Details
#parse(string) ⇒ Object
The #parse_string method is defined in the parser C extension.
9 10 11 12 13 14 |
# File 'lib/syme/bootstrap/parser.rb', line 9 def parse(string) @string = string ast = parse_string string show_syntax_error unless ast ast end |
#parse_file(name) ⇒ Object
16 17 18 19 |
# File 'lib/syme/bootstrap/parser.rb', line 16 def parse_file(name) string = IO.read name parse string end |
#show_syntax_error ⇒ Object
Parsing callbacks
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/syme/bootstrap/parser.rb', line 23 def show_syntax_error error_line = nil count = 0 @string.each_line do |line| count += line.size if count > @error_position error_line = line break end end = <<-EOM #{error_line.chomp} #{" " *(error_line.size - (count - @error_position))}^ EOM raise Syntax::SyntaxError, end |
#syntax_error(pos) ⇒ Object
43 44 45 |
# File 'lib/syme/bootstrap/parser.rb', line 43 def syntax_error(pos) @error_position = pos end |