lib/minjs/lex.rb in minjs-0.1.3 vs lib/minjs/lex.rb in minjs-0.1.5

- old
+ new

@@ -12,13 +12,11 @@ str = str.gsub(/\r\n/, "\n") @codes = str.codepoints @pos = 0 @lit_cache = [] @lit_nextpos = [] - if options[:debug] - @debug = true - end + @logger = options[:logger] end def next_input_element(options = {}) if @lit_cache[@pos] ret = @lit_cache[@pos] @@ -389,11 +387,10 @@ while !(@codes[@pos] == 0x2f) if @codes[@pos].nil? raise ParseError.new("no `/' end of regular expression", self) end if line_terminator?(@codes[@pos]) - debug_lit raise ParseError.new("regular expression has line terminator in body", self) end if @codes[@pos] == 0x5c # \ @pos += 1 if line_terminator?(@codes[@pos]) @@ -533,10 +530,11 @@ end def decimal_digits pos0 = @pos code = @codes[@pos] + return nil if code.nil? if code >= 0x30 and code <= 0x39 @pos += 1 while true code = @codes[@pos] if code >= 0x30 and code <= 0x39 @@ -650,11 +648,10 @@ # if next literal is 'l', position is forwarded # def match_lit(l, options = {}) eval_lit { t = fwd_lit(options) - STDERR.puts "match_lit #{t} <=> #{l} #{t==l}" if @debug t == l ? t : nil } end def next_lit(options = {}) @@ -715,11 +712,11 @@ to = (@error_pos || @pos) end @codes[from,to].pack("U*") end - def debug_str(pos = nil) + def debug_str(pos = nil, line = nil, col = nil) if pos.nil? pos = @error_pos if pos.nil? pos = @pos end @@ -729,11 +726,14 @@ pos0 = 20 elsif pos >= 0 pos0 = pos pos = 0 end + if col and col > 2 + pos0 = col - 2; + end t = '' - t << @codes[pos..(pos+80)].collect{|u| u == 10 ? 0x20 : u}.pack("U*") + t << @codes[pos..(pos+80)].pack("U*") t << "\n" t << (' ' * pos0) + "^" t end