Sha256: ad36301868aba83b275e70a6317cd68cf2a8d15c56fc0c0399f68aebc34f4794
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true class Language class Parser attr_accessor :input, :buffer, :output, :root, :cursor def initialize(root:, input:, cursor: 0, buffer: "", output: Output.new) @root = root @input = input @cursor = cursor @buffer = buffer @output = output end def parse(check_end_of_input: true) @root.parse(self) unless @cursor == @input.size || !check_end_of_input raise NotEndOfInput, self end if @output.present? @output else Output.new(@buffer.empty? ? nil : @buffer) end end def consume(n) raise EndOfInput, self unless @cursor + n <= @input.size @buffer += @input[@cursor, n] @cursor += n end def aka(name) if @buffer.empty? @output = Output.new({ name => @output }) else @output[name] = Output.new(@buffer) @buffer = "" end end def next?(string) @input[@cursor...(@cursor + string.size)] == string end def buffer? @buffer != "" end def output? @output.present? end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
language-ruby-1.1.0 | lib/language/parser.rb |