it works?
This commit is contained in:
parent
a6372171c0
commit
1f1f6c0732
|
@ -109,6 +109,7 @@ do local tstring = selfify({})
|
||||||
["\n"] = setmetatable({["\r"] = setmetatable({}, {__index=tstring})}, {__index=tstring}),
|
["\n"] = setmetatable({["\r"] = setmetatable({}, {__index=tstring})}, {__index=tstring}),
|
||||||
["\r"] = setmetatable({["\n"] = setmetatable({}, {__index=tstring})}, {__index=tstring}),
|
["\r"] = setmetatable({["\n"] = setmetatable({}, {__index=tstring})}, {__index=tstring}),
|
||||||
[1] = linecount,
|
[1] = linecount,
|
||||||
|
[2] = function(state, token, rule) if token == "\r" or token == "\n" then collect_fallback(state, "\n") end end,
|
||||||
}, {__index = tokens.base})
|
}, {__index = tokens.base})
|
||||||
tokens.string.escapes = tsescapes
|
tokens.string.escapes = tsescapes
|
||||||
tsescapes.string = tokens.string
|
tsescapes.string = tokens.string
|
||||||
|
@ -127,7 +128,6 @@ do local tstring = selfify({})
|
||||||
end
|
end
|
||||||
|
|
||||||
function tsescapes.digit(state, token)
|
function tsescapes.digit(state, token)
|
||||||
print(state, token)
|
|
||||||
local digit = string.find("1234567890", token, 1, true)
|
local digit = string.find("1234567890", token, 1, true)
|
||||||
local num = state.in_digit
|
local num = state.in_digit
|
||||||
if digit then
|
if digit then
|
||||||
|
@ -144,9 +144,19 @@ do local tstring = selfify({})
|
||||||
collect_fallback(state, string.char(num))
|
collect_fallback(state, string.char(num))
|
||||||
state.in_digit = nil
|
state.in_digit = nil
|
||||||
state.c = nil
|
state.c = nil
|
||||||
|
if not digit then
|
||||||
|
collect_fallback(state, token)
|
||||||
|
end
|
||||||
return "string"
|
return "string"
|
||||||
end
|
end
|
||||||
tsescapes.digitc = setmetatable(selfify({[""] = tsescapes.digit, digitc = "self", string = tstring}), {__index=tstring})
|
tsescapes.digitc = setmetatable(selfify({[""] = tsescapes.digit, string = tstring}, "digitc"), {__index=tstring})
|
||||||
|
tsescapes.digitc[1]=function(state, token, rule)
|
||||||
|
if rule == nil then
|
||||||
|
collect_fallback(state, string.char(state.in_digit))
|
||||||
|
state.in_digit = nil
|
||||||
|
state.c = nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
tsescapes.hex = setmetatable(selfify({string = tokens.string, digit = "hexdigit"}), {__index=tokens.base})
|
tsescapes.hex = setmetatable(selfify({string = tokens.string, digit = "hexdigit"}), {__index=tokens.base})
|
||||||
function tsescapes.hex.hexdigit(state, token)
|
function tsescapes.hex.hexdigit(state, token)
|
||||||
|
@ -197,7 +207,7 @@ do local tstring = selfify({})
|
||||||
state[COLLECT] = nil
|
state[COLLECT] = nil
|
||||||
return "tokens"
|
return "tokens"
|
||||||
else
|
else
|
||||||
state[#state+1] = token
|
collect_fallback(state, token)
|
||||||
return "self"
|
return "self"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -134,8 +134,8 @@ return {
|
||||||
stream = stream,
|
stream = stream,
|
||||||
parse = parse,
|
parse = parse,
|
||||||
-- common utility function
|
-- common utility function
|
||||||
selfify = function(t)
|
selfify = function(t, id)
|
||||||
t.self = t
|
t[id or "self"] = t
|
||||||
return t
|
return t
|
||||||
end,
|
end,
|
||||||
-- common hook
|
-- common hook
|
||||||
|
|
Loading…
Reference in New Issue