Sha256: 6ebab292c3343434e95a8d90df7d174dfdaad325059047c81c7cf12df5ae2882
Contents?: true
Size: 1000 Bytes
Versions: 12
Compression:
Stored size: 1000 Bytes
Contents
module Parser module Lexer::Explanation # Like #advance, but also pretty-print the token and its position # in the stream to `stdout`. def advance type, (val, range) = super puts decorate(range, "\e[0;32m#{type} #{val.inspect}\e[0m", "#{state.to_s.ljust(12)} #{@cond} #{@cmdarg}\e[0m") [ type, [val, range] ] end def state=(new_state) puts " \e[1;33m>>> STATE SET <<<\e[0m " + "#{new_state.to_s.ljust(12)} #{@cond} #{@cmdarg}".rjust(66) super end private def decorate(range, token, info) from, to = range.begin.column, range.end.column line = range.source_line line[from...to] = "\e[4m#{line[from...to]}\e[0m" tail_len = to - from - 1 tail = "~" * (tail_len >= 0 ? tail_len : 0) decoration = "#{" " * from}\e[1;31m^#{tail}\e[0m #{token} ". ljust(70) + info [ line, decoration ] end end end
Version data entries
12 entries across 12 versions & 1 rubygems