diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2014-07-06 23:21:18 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2014-07-06 23:21:18 +0200 |
commit | ed0275bf230dfa5ef7d8e48d81948d4a52b193c7 (patch) | |
tree | 94accdfa3f8437d3b3cd5c091d992946e822f596 | |
parent | ce31f05f5fb463bf71f6eb86a94720839e686ba2 (diff) | |
download | lualibs-ed0275bf230dfa5ef7d8e48d81948d4a52b193c7.tar.gz |
sync with Context as of 2014-07-06
-rw-r--r-- | lualibs-lpeg.lua | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/lualibs-lpeg.lua b/lualibs-lpeg.lua index c203d80..79e75a7 100644 --- a/lualibs-lpeg.lua +++ b/lualibs-lpeg.lua @@ -897,17 +897,35 @@ end function lpeg.utfchartabletopattern(list) -- goes to util-lpg local tree = { } local hash = { } - for i=1,#list do - local t = tree - for c in gmatch(list[i],".") do - local tc = t[c] - if not tc then - tc = { } - t[c] = tc + local n = #list + if n == 0 then + -- we could always use this branch + for s in next, list do + local t = tree + for c in gmatch(s,".") do + local tc = t[c] + if not tc then + tc = { } + t[c] = tc + end + t = tc + end + hash[t] = s + end + else + for i=1,n do + local t = tree + local s = list[i] + for c in gmatch(s,".") do + local tc = t[c] + if not tc then + tc = { } + t[c] = tc + end + t = tc end - t = tc + hash[t] = s end - hash[t] = list[i] end return make(tree,hash) end |