Skip to content

Commit

Permalink
lib.xsd_regexp: implement \i, \I, \c, and \C
Browse files Browse the repository at this point in the history
  • Loading branch information
eugeneia committed Jan 11, 2018
1 parent 6fcebb8 commit 1187fc7
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/lib/xsd_regexp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,6 @@ function compile_quantifier (quantifier)
end

function compile_atom (atom)
-- NYI: \i, \I, \c, \C
local function is_special_escape (s)
return member(s, "\\|.-^?*+{}()[]")
end
Expand All @@ -385,6 +384,12 @@ function compile_atom (atom)
local function is_space (s)
return member(s, " \t\n\r")
end
local function is_NameStartChar (s)
return GC.L(s:byte()) or member(s, ":_")
end
local function is_NameChar (s)
return is_NameStartChar(s) or GC.Nd(s:byte()) or member(s, "-.")
end
local function is_digit (s)
return GC.Nd(s:byte())
end
Expand All @@ -403,6 +408,14 @@ function compile_atom (atom)
return match.satisfies(is_space)
elseif atom.escape == "S" then
return match._not(match.satisfies(is_space))
elseif atom.escape == "i" then
return match.satisfies(is_NameStartChar)
elseif atom.escape == "I" then
return match._not(match.satisfies(is_NameStartChar))
elseif atom.escape == "c" then
return match.satisfies(is_NameChar)
elseif atom.escape == "C" then
return match._not(match.satisfies(is_NameChar))
elseif atom.escape == "d" then
return match.satisfies(is_digit)
elseif atom.escape == "D" then
Expand Down Expand Up @@ -601,4 +614,20 @@ function selftest ()
test {regexp="\\P{Ps}",
accept={"}", "]", ")", "A", "b", "y", "Z", "0", "-", " "},
reject={"(", "[", "{"}}

test {regexp="\\P{Ps}",
accept={"}", "]", ")", "A", "b", "y", "Z", "0", "-", " "},
reject={"(", "[", "{"}}

test {regexp="\\w",
accept={"F", "0", "a", "~"},
reject={"-", " ", ".", "\t"}}

test {regexp="\\i",
accept={"a", "B", "_", ":"},
reject={"-", "1", " ", "."}}

test {regexp="\\C",
accept={"~", " ", "\t", "\n"},
reject={"a", "B", "1", ".", "_", ":"}}
end

0 comments on commit 1187fc7

Please sign in to comment.