Skip to content

Commit

Permalink
Rudimentary implementation of ParseEscapes :>
Browse files Browse the repository at this point in the history
  • Loading branch information
Denneisk committed Sep 18, 2023
1 parent 4783951 commit 4d909fd
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions lua/entities/gmod_wire_expression2/base/tokenizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -268,39 +268,31 @@ function Tokenizer:Next()

if self:At() == "\"" then
self:NextChar()
local buffer, nbuffer = {}, 0
while true do
local m = self:ConsumePattern("^[^\"\\]*[\"\\]", true)

if m then
nbuffer = nbuffer + 1
buffer[nbuffer] = m:sub(1, -2)

-- See if the last char in the match was a quote or an escape char
if m:sub( -1, -1) == "\"" then
break
local m = self:ConsumePattern("^[^\"]*[\"]", true)

if m then
m = m:sub(1, -2)
m = WireLib.ParseEscapes(m)

-- Warn on bad escapes
local pos = 1
while true do
local match
pos, _, match = m:find("(\\.)", pos)
if pos then
pos = pos + 1
match = match:gsub("%G", " ")
self:Warning("Invalid escape " .. match)
else -- Escape
local c = self:At()

if not Escapes[c] then
self:Warning("Invalid escape \\" .. c)
c = '\\' .. c
else
c = Escapes[c]
end

self:NextChar(true)

nbuffer = nbuffer + 1
buffer[nbuffer] = c
break
end
else
self:ConsumePattern("^.*", true)
return self:Error("Missing \" to end string")
end
else
self:ConsumePattern("^.*", true)
return self:Error("Missing \" to end string")
end

return Token.new(TokenVariant.String, table.concat(buffer, '', 1, nbuffer))
return Token.new(TokenVariant.String, m)
end

if E2Lib.GrammarLookup[self:At()] then
Expand Down

0 comments on commit 4d909fd

Please sign in to comment.