diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-04-14 12:04:23 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-04-14 12:04:23 -0300 |
commit | 3f7797419e4d7493e1364290a5b127d1cb45e3bf (patch) | |
tree | 8dd91b0d008d5ea9f9c96eada86510495c97d1e3 /test.lua | |
parent | d9f83dded93a35fb333c4e1bd371c401f7129fd1 (diff) | |
download | lpeg-3f7797419e4d7493e1364290a5b127d1cb45e3bf.tar.gz lpeg-3f7797419e4d7493e1364290a5b127d1cb45e3bf.tar.bz2 lpeg-3f7797419e4d7493e1364290a5b127d1cb45e3bf.zip |
Removed 'unsigned char' limit on number of rules in grammars
Added a new tree-type node 'TXInfo', which follows 'TRule' nodes,
to store extra information about a node. (In this case, the rule
number, with an 'unsigned short' field.)
Diffstat (limited to 'test.lua')
-rwxr-xr-x | test.lua | 25 |
1 files changed, 22 insertions, 3 deletions
@@ -406,7 +406,7 @@ assert(p:match('abcx') == 5 and p:match('ayzx') == 5 and not p:match'abc') | |||
406 | 406 | ||
407 | 407 | ||
408 | do | 408 | do |
409 | -- large dynamic Cc | 409 | print "testing large dynamic Cc" |
410 | local lim = 2^16 - 1 | 410 | local lim = 2^16 - 1 |
411 | local c = 0 | 411 | local c = 0 |
412 | local function seq (n) | 412 | local function seq (n) |
@@ -985,10 +985,10 @@ for i = 1, 10 do | |||
985 | assert(p:match("aaaaaaaaaaa") == 11 - i + 1) | 985 | assert(p:match("aaaaaaaaaaa") == 11 - i + 1) |
986 | end | 986 | end |
987 | 987 | ||
988 | print"+" | ||
989 | 988 | ||
990 | 989 | ||
991 | -- tests for back references | 990 | print "testing back references" |
991 | |||
992 | checkerr("back reference 'x' not found", m.match, m.Cb('x'), '') | 992 | checkerr("back reference 'x' not found", m.match, m.Cb('x'), '') |
993 | checkerr("back reference 'b' not found", m.match, m.Cg(1, 'a') * m.Cb('b'), 'a') | 993 | checkerr("back reference 'b' not found", m.match, m.Cg(1, 'a') * m.Cb('b'), 'a') |
994 | 994 | ||
@@ -1171,9 +1171,28 @@ t = {p:match('abacc')} | |||
1171 | checkeq(t, {'a', 'aa', 20, 'a', 'aaa', 'aaa'}) | 1171 | checkeq(t, {'a', 'aa', 20, 'a', 'aaa', 'aaa'}) |
1172 | 1172 | ||
1173 | 1173 | ||
1174 | do print"testing large grammars" | ||
1175 | local lim = 1000 -- number of rules | ||
1176 | local t = {} | ||
1177 | |||
1178 | for i = 3, lim do | ||
1179 | t[i] = m.V(i - 1) -- each rule calls previous one | ||
1180 | end | ||
1181 | t[1] = m.V(lim) -- start on last rule | ||
1182 | t[2] = m.C("alo") -- final rule | ||
1183 | |||
1184 | local P = m.P(t) -- build grammar | ||
1185 | assert(P:match("alo") == "alo") | ||
1186 | |||
1187 | t[#t + 1] = m.P("x") -- one more rule... | ||
1188 | checkerr("too many rules", m.P, t) | ||
1189 | end | ||
1190 | |||
1191 | |||
1174 | ------------------------------------------------------------------- | 1192 | ------------------------------------------------------------------- |
1175 | -- Tests for 're' module | 1193 | -- Tests for 're' module |
1176 | ------------------------------------------------------------------- | 1194 | ------------------------------------------------------------------- |
1195 | print"testing 're' module" | ||
1177 | 1196 | ||
1178 | local re = require "re" | 1197 | local re = require "re" |
1179 | 1198 | ||