diff options
| author | Undecidable Robot <undecidabot@gmail.com> | 2016-05-30 13:10:48 +0800 |
|---|---|---|
| committer | Undecidable Robot <undecidabot@gmail.com> | 2016-05-30 13:10:48 +0800 |
| commit | 855c4e7bf1cfb8dc0056bd204a9d2c6b1ef54abf (patch) | |
| tree | c64b6c8fcd577f5704c0c2b2714e7fb9e950503d | |
| parent | c904c47fab8d06e2bfe91ae852e95b41d6e309e1 (diff) | |
| parent | 06fcbfd8d3f1c1cd0ae76d726778cebc3bcde9bd (diff) | |
| download | lpeglabel-855c4e7bf1cfb8dc0056bd204a9d2c6b1ef54abf.tar.gz lpeglabel-855c4e7bf1cfb8dc0056bd204a9d2c6b1ef54abf.tar.bz2 lpeglabel-855c4e7bf1cfb8dc0056bd204a9d2c6b1ef54abf.zip | |
Merge branch 'master' of https://github.com/sqmedeiros/lpeglabel
| -rw-r--r-- | lpcode.c | 5 | ||||
| -rw-r--r-- | testlabel.lua | 9 |
2 files changed, 13 insertions, 1 deletions
| @@ -192,10 +192,13 @@ int checkaux (TTree *tree, int pred) { | |||
| 192 | if (!checkaux(sib1(tree), pred)) return 0; | 192 | if (!checkaux(sib1(tree), pred)) return 0; |
| 193 | /* else return checkaux(sib2(tree), pred); */ | 193 | /* else return checkaux(sib2(tree), pred); */ |
| 194 | tree = sib2(tree); goto tailcall; | 194 | tree = sib2(tree); goto tailcall; |
| 195 | case TChoice: case TLabChoice: /* labeled failure */ | 195 | case TChoice: |
| 196 | if (checkaux(sib2(tree), pred)) return 1; | 196 | if (checkaux(sib2(tree), pred)) return 1; |
| 197 | /* else return checkaux(sib1(tree), pred); */ | 197 | /* else return checkaux(sib1(tree), pred); */ |
| 198 | tree = sib1(tree); goto tailcall; | 198 | tree = sib1(tree); goto tailcall; |
| 199 | case TLabChoice: /* labeled failure */ | ||
| 200 | /* in a labeled ordered choice we do not know whether sib2 will be evaluated */ | ||
| 201 | tree = sib1(tree); goto tailcall; | ||
| 199 | case TCapture: case TGrammar: case TRule: | 202 | case TCapture: case TGrammar: case TRule: |
| 200 | /* return checkaux(sib1(tree), pred); */ | 203 | /* return checkaux(sib1(tree), pred); */ |
| 201 | tree = sib1(tree); goto tailcall; | 204 | tree = sib1(tree); goto tailcall; |
diff --git a/testlabel.lua b/testlabel.lua index d4cc815..1962fbf 100644 --- a/testlabel.lua +++ b/testlabel.lua | |||
| @@ -101,6 +101,15 @@ assert(p:match("aa") == nil) | |||
| 101 | p = (m.P"a" + m.T(0))^0 | 101 | p = (m.P"a" + m.T(0))^0 |
| 102 | assert(p:match("aa") == 3) | 102 | assert(p:match("aa") == 3) |
| 103 | 103 | ||
| 104 | -- Bug reported by Matthew Allen | ||
| 105 | -- some optmizations performed by LPeg should not be | ||
| 106 | -- applied in case of labeled choices | ||
| 107 | p = m.Lc(m.P"A", m.P(true), 1) + m.P("B") | ||
| 108 | assert(p:match("B") == 2) | ||
| 109 | |||
| 110 | p = m.Lc(m.P"A", m.P(false), 1) + m.P("B") | ||
| 111 | assert(p:match("B") == 2) | ||
| 112 | |||
| 104 | 113 | ||
| 105 | --[[ | 114 | --[[ |
| 106 | S -> A /{1} 'a' | 115 | S -> A /{1} 'a' |
