diff options
Diffstat (limited to 'src/bin/printtokens.lua')
-rw-r--r-- | src/bin/printtokens.lua | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/bin/printtokens.lua b/src/bin/printtokens.lua index 49827da..316b439 100644 --- a/src/bin/printtokens.lua +++ b/src/bin/printtokens.lua @@ -50,18 +50,37 @@ defs[-1] = function(state, token, rule) error("Unknown option: " .. token) end end +defs['-l'] = function(state, token, rule) + state.print_lineno = true + return "self" +end defs['--'] = parser.selfify({[parser.FALLBACK] = defs[parser.FALLBACK], [parser.EOZ] = defs[parser.EOZ]}) local state = parser.parse(defs, arg) local luatokens = require "cratera.luatokens" local file = state.file local tokens = luatokens.defs -local state, err, etoken, estate = parser.parse(tokens, function() return file:read(8192) end) -if state then +local print_lineno = state.print_lineno +--local state, err, etoken, estate = parser.parse(tokens, function() return file:read(8192) end) +local f, s, i = parser.stream(tokens, function() return file:read(8192) end) +local lastline +local lasttoken = 0 +for pos, state, transemsg, etoken, estate in f, s, i do + if not state then + print("Parse error") + break + end + if (state.line or 1) ~= lastline then + lastline = state.line or 1 + print("line", lastline) + end for i,v in ipairs(state) do + lasttoken = lasttoken + 1 v = luatokens.reverse_keywords[v] or luatokens.reverse_tokens[v] or v - print(i, v) -- TODO formatting + print(lasttoken, v) -- TODO formatting + state[i] = nil + end + if not transemsg then + break end -else - print("Parse error") end |