Class: Maps::Parser
- Inherits:
-
Object
- Object
- Maps::Parser
- Includes:
- Grammar
- Defined in:
- lib/rookout/processor/paths/canopy/maps.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(input, actions, types) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Methods included from Grammar
#_read___, #_read_apostrophe_string, #_read_atom, #_read_boolean_, #_read_chr, #_read_comp_expression, #_read_comp_expression_ex, #_read_float_, #_read_func_call, #_read_func_call_access, #_read_list, #_read_map_access, #_read_namespace, #_read_null_, #_read_number, #_read_opt_, #_read_string, #_read_undefined_, #_read_unicode_set, #_read_unicode_set_with_numbers, #_read_variable, #_read_variable_access
Constructor Details
#initialize(input, actions, types) ⇒ Parser
Returns a new instance of Parser.
2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 |
# File 'lib/rookout/processor/paths/canopy/maps.rb', line 2796 def initialize(input, actions, types) @input = input @input_size = input.size @actions = actions @types = types @offset = 0 @cache = Hash.new { |h,k| h[k] = {} } @failure = 0 @expected = [] end |
Class Method Details
.format_error(input, offset, expected) ⇒ Object
2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 |
# File 'lib/rookout/processor/paths/canopy/maps.rb', line 2819 def self.format_error(input, offset, expected) lines, line_no, position = input.split(/\n/), 0, 0 while position <= offset position += lines[line_no].size + 1 line_no += 1 end , line = "Line #{line_no}: expected #{expected * ", "}\n", lines[line_no - 1] += "#{line}\n" position -= line.size + 1 += " " * (offset - position) return + "^" end |
Instance Method Details
#parse ⇒ Object
2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 |
# File 'lib/rookout/processor/paths/canopy/maps.rb', line 2807 def parse tree = _read_comp_expression if tree != FAILURE and @offset == @input_size return tree end if @expected.empty? @failure = @offset @expected << "<EOF>" end raise ParseError, Parser.format_error(@input, @failure, @expected) end |