diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-06-22 10:50:15 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-06-22 10:50:15 -0300 |
commit | 4eb4419163dd6c97665b9481e9581ff32496b392 (patch) | |
tree | 85bbac8be5fb03d340a6a901fd15599dd699d8da /test.lua | |
parent | e3f612f58dc0201beb3a86e1a5d8df9cd9158698 (diff) | |
download | lpeg-4eb4419163dd6c97665b9481e9581ff32496b392.tar.gz lpeg-4eb4419163dd6c97665b9481e9581ff32496b392.tar.bz2 lpeg-4eb4419163dd6c97665b9481e9581ff32496b392.zip |
Accumulator pattern added to the 're' module
Diffstat (limited to 'test.lua')
-rwxr-xr-x | test.lua | 7 |
1 files changed, 7 insertions, 0 deletions
@@ -1517,6 +1517,13 @@ c = re.compile([[ | |||
1517 | ]], {tonumber = tonumber, add = function (a,b) return a + b end}) | 1517 | ]], {tonumber = tonumber, add = function (a,b) return a + b end}) |
1518 | assert(c:match("3 401 50") == 3 + 401 + 50) | 1518 | assert(c:match("3 401 50") == 3 + 401 + 50) |
1519 | 1519 | ||
1520 | -- test for accumulator captures | ||
1521 | c = re.compile([[ | ||
1522 | S <- number (%s+ number >> add)* | ||
1523 | number <- %d+ -> tonumber | ||
1524 | ]], {tonumber = tonumber, add = function (a,b) return a + b end}) | ||
1525 | assert(c:match("3 401 50") == 3 + 401 + 50) | ||
1526 | |||
1520 | -- tests for look-ahead captures | 1527 | -- tests for look-ahead captures |
1521 | x = {re.match("alo", "&(&{.}) !{'b'} {&(...)} &{..} {...} {!.}")} | 1528 | x = {re.match("alo", "&(&{.}) !{'b'} {&(...)} &{..} {...} {!.}")} |
1522 | checkeq(x, {"", "alo", ""}) | 1529 | checkeq(x, {"", "alo", ""}) |