Commit cc3d7c6e authored by François Perrad's avatar François Perrad
Browse files

refactor compile

parent fbaaedc5
Pipeline #177184 passed with stages
in 20 seconds
......@@ -10,7 +10,6 @@ local char = string.char
local error = error
local tonumber = tonumber
local tostring = tostring
local smatch = string.match
local sub = string.sub
local gmatch = string.gmatch
local gsub = string.gsub
......@@ -47,6 +46,29 @@ local future_op = {
['|'] = true,
}
local is_hexa = {
['0'] = true, ['1'] = true, ['2'] = true, ['3'] = true, ['4'] = true,
['5'] = true, ['6'] = true, ['7'] = true, ['8'] = true, ['9'] = true,
['A'] = true, ['B'] = true, ['C'] = true, ['D'] = true, ['E'] = true, ['F'] = true,
['a'] = true, ['b'] = true, ['c'] = true, ['d'] = true, ['e'] = true, ['f'] = true,
}
local is_word = {
['0'] = true, ['1'] = true, ['2'] = true, ['3'] = true, ['4'] = true,
['5'] = true, ['6'] = true, ['7'] = true, ['8'] = true, ['9'] = true,
['A'] = true, ['B'] = true, ['C'] = true, ['D'] = true, ['E'] = true, ['F'] = true,
['G'] = true, ['H'] = true, ['I'] = true, ['J'] = true, ['K'] = true, ['L'] = true,
['M'] = true, ['N'] = true, ['O'] = true, ['P'] = true, ['Q'] = true, ['R'] = true,
['S'] = true, ['T'] = true, ['U'] = true, ['V'] = true, ['W'] = true, ['X'] = true,
['Y'] = true, ['Z'] = true,
['_'] = true,
['a'] = true, ['b'] = true, ['c'] = true, ['d'] = true, ['e'] = true, ['f'] = true,
['g'] = true, ['h'] = true, ['i'] = true, ['j'] = true, ['k'] = true, ['l'] = true,
['m'] = true, ['n'] = true, ['o'] = true, ['p'] = true, ['q'] = true, ['r'] = true,
['s'] = true, ['t'] = true, ['u'] = true, ['v'] = true, ['w'] = true, ['x'] = true,
['y'] = true, ['z'] = true,
}
local function compile (patt)
local exist = {}
local function uniq (name)
......@@ -81,13 +103,12 @@ local function compile (patt)
local j = i
while i <= #s do
c = sub(s, i, i)
if not smatch(c, '[%d%a_]') then
if not is_word[c] then
if c == ',' then
op[#op+1] = uniq(sub(s, j, i - 1))
j = i + 1
elseif c == '%' then
c = sub(s, i+1, i+2)
if not smatch(c, '%x%x') then
if not is_hexa[sub(s, i+1, i+1)] or not is_hexa[sub(s, i+2, i+2)] then
error("invalid triplet found at position " .. tostring(start + i), 3)
end
i = i + 2
......@@ -110,13 +131,6 @@ local function compile (patt)
return ops
end
local is_hexa = {
['0'] = true, ['1'] = true, ['2'] = true, ['3'] = true, ['4'] = true,
['5'] = true, ['6'] = true, ['7'] = true, ['8'] = true, ['9'] = true,
['A'] = true, ['B'] = true, ['C'] = true, ['D'] = true, ['E'] = true, ['F'] = true,
['a'] = true, ['b'] = true, ['c'] = true, ['d'] = true, ['e'] = true, ['f'] = true,
}
local end_oper = {
['1'] = { ['/'] = true, ['?'] = true, ['#'] = true },
['+'] = { ['?'] = true, ['#'] = true },
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment