diff options
author | Georgi Kirilov <in.the@repo> | 2020-06-27 02:38:03 +0300 |
---|---|---|
committer | Georgi Kirilov <in.the@repo> | 2020-06-27 03:29:11 +0300 |
commit | 67c978b75b551f25ac01022e979d67589f8ae4d0 (patch) | |
tree | b364a697ad7886c1dfef7f3edebbb95900b298b9 | |
parent | 65533462ed4018d4c14e6c919bcdb8209b755ad2 (diff) | |
download | vis-toggler-67c978b75b551f25ac01022e979d67589f8ae4d0.tar.gz |
fix wrong words order in pattern
Since + is _ordered_ choice in LPeg, if two words start with the same
string, and the shorter one comes first in the pattern, the longer one
will never match.
Fix this by sorting all the words before making a pattern out of them.
-rw-r--r-- | init.lua | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -102,12 +102,20 @@ end local function preprocess(tbl) local cfg, ord = {}, P(false) + local longer_first = {} for _, options in ipairs(tbl) do for i, key in ipairs(options) do cfg[key] = {i, options} - ord = ord + key + table.insert(longer_first, key) end end + table.sort(longer_first, function(f, s) + local flen, slen = #f, #s + return flen > slen or flen == slen and f < s + end) + for _, key in ipairs(longer_first) do + ord = ord + key + end return cfg, ord end |