diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2024-06-06 03:09:00 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2024-06-06 03:09:00 -0300 |
commit | d865925d050f13e1097721d2b1f3ae352b49c484 (patch) | |
tree | 05d1c2bd1435571a1c4ae4064b2d50535cc87692 /src | |
parent | 1f8140c95ced6b7ce291e16c26c80800fa4f1f9d (diff) |
Fix long string parsing
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/printtokens.lua | 29 | ||||
-rw-r--r-- | src/cratera/luatokens.lua | 11 |
2 files changed, 32 insertions, 8 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 diff --git a/src/cratera/luatokens.lua b/src/cratera/luatokens.lua index 90d0c61..632cf27 100644 --- a/src/cratera/luatokens.lua +++ b/src/cratera/luatokens.lua @@ -1,6 +1,6 @@ --[[ This file is part of Cratera Compiler - Copyright (C) 2019 Soni L. + Copyright (C) 2019, 2024 Soni L. This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by @@ -387,7 +387,12 @@ end do local tlongstring = {} defs.longstring = tlongstring do local tllongstring_proper = selfify({[parser.FALLBACK] = "self", ["]"] = function(state, token) state.longstring_close = 0 return "maybe_end" end}) - tllongstring_proper[1] = false -- placeholder for newline handling + tlongstring[1] = false -- first newline is skipped(!) + tllongstring_proper[1] = function(state, token, rule) + if token == "\n" or token == "\r" then + collect_fallback(state, "\n") + end + end tllongstring_proper[2] = collect_fallback do local tllmaybe_end = selfify({defs = defs}, "maybe_end") @@ -425,7 +430,7 @@ do local tlongstring = {} end tlongstring.longstring_proper = tllongstring_proper - mknewline(tlongstring, 1, tllongstring_proper) + mknewline(tllongstring_proper, 1) setmetatable(tlongstring, {__index=tllongstring_proper}) end end |