aboutsummaryrefslogtreecommitdiff
path: root/test.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-14 12:04:23 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-04-14 12:04:23 -0300
commit3f7797419e4d7493e1364290a5b127d1cb45e3bf (patch)
tree8dd91b0d008d5ea9f9c96eada86510495c97d1e3 /test.lua
parentd9f83dded93a35fb333c4e1bd371c401f7129fd1 (diff)
downloadlpeg-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-xtest.lua25
1 files changed, 22 insertions, 3 deletions
diff --git a/test.lua b/test.lua
index 8f9f574..f57cdec 100755
--- a/test.lua
+++ b/test.lua
@@ -406,7 +406,7 @@ assert(p:match('abcx') == 5 and p:match('ayzx') == 5 and not p:match'abc')
406 406
407 407
408do 408do
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)
986end 986end
987 987
988print"+"
989 988
990 989
991-- tests for back references 990print "testing back references"
991
992checkerr("back reference 'x' not found", m.match, m.Cb('x'), '') 992checkerr("back reference 'x' not found", m.match, m.Cb('x'), '')
993checkerr("back reference 'b' not found", m.match, m.Cg(1, 'a') * m.Cb('b'), 'a') 993checkerr("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')}
1171checkeq(t, {'a', 'aa', 20, 'a', 'aaa', 'aaa'}) 1171checkeq(t, {'a', 'aa', 20, 'a', 'aaa', 'aaa'})
1172 1172
1173 1173
1174do 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)
1189end
1190
1191
1174------------------------------------------------------------------- 1192-------------------------------------------------------------------
1175-- Tests for 're' module 1193-- Tests for 're' module
1176------------------------------------------------------------------- 1194-------------------------------------------------------------------
1195print"testing 're' module"
1177 1196
1178local re = require "re" 1197local re = require "re"
1179 1198