lib/raabro.rb in raabro-1.3.3 vs lib/raabro.rb in raabro-1.4.0

- old
+ new

@@ -1,9 +1,10 @@ +# frozen_string_literal: true module Raabro - VERSION = '1.3.3' + VERSION = '1.4.0' class Input attr_accessor :string, :offset attr_reader :options @@ -77,14 +78,23 @@ @children = successful_children end def string; @input.string[@offset, @length]; end - def strinp; @input.string[@offset, @length].strip; end + def strinp; string.strip; end alias strim strinp def nonstring(l=7); @input.string[@offset, l]; end + def stringd; string.downcase; end + alias strind stringd + def stringpd; strinp.downcase; end + alias strinpd stringpd + + def symbol; strinp.to_sym; end + def symbold; symbol.downcase; end + alias symbod symbold + def lookup(name=nil) name = name ? name.to_s : nil return self if @name && name == nil @@ -464,29 +474,39 @@ r.result = 0 if c.result != 1 end if r.result == 1 - i = 0 + on_elt = false + count = 0 + empty_stack = 0 loop do - st = i > 0 ? _parse(seppa, input) : nil - et = st == nil || st.result == 1 ? _parse(eltpa, input) : nil + on_elt = ! on_elt - break if st && et && st.empty? && et.result == 0 - break if st && et && st.empty? && et.empty? + cr = _parse(on_elt ? eltpa : seppa, input) - r.children << st if st - r.children << et if et + empty_stack = cr.empty? ? empty_stack + 1 : 0 + cr.result = 0 if empty_stack > 1 + # + # prevent "no progress" - break if et == nil - break if et.result != 1 + r.children.push(cr) - i = i + 1 + if cr.result != 1 + if on_elt && count > 0 + lsep = r.children[-2] + lsep.result = 0 + input.offset = lsep.offset + end + break + end + + count += 1 end - r.result = 0 if jseq && i == 0 + r.result = 0 if jseq && count < 1 end if r.result == 1 && endpa c = _parse(endpa, input) r.children << c