summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2014-03-22 18:33:53 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2014-03-22 18:33:53 +0000
commit780096df34e25789b94df958112f58826303d256 (patch)
tree05cbb48d782cac75d484de40fdacb4bda1415121
parent4cec5510089783f34f69206f990cb34c5d57dcb8 (diff)
downloadlace-780096df34e25789b94df958112f58826303d256.tar.gz
Cache full lexes of rulesets
-rw-r--r--lib/lace/lex.lua8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/lace/lex.lua b/lib/lace/lex.lua
index af891af..9cc2a51 100644
--- a/lib/lace/lex.lua
+++ b/lib/lace/lex.lua
@@ -100,12 +100,18 @@ local function lex_one_line(line)
return lexer_line_cache[line][1], lexer_line_cache[line][2]
end
+local cached_full_lexes = {}
+
--- Lexically analyse a ruleset.
-- @tparam string ruleset The ruleset to lex.
-- @tparam string sourcename The name of the source to go into debug info.
-- @treturn table A list of lexed lines, each line being a table of tokens
-- with their associated debug information.
function M.string(ruleset, sourcename)
+ if cached_full_lexes[sourcename] and
+ cached_full_lexes[sourcename][ruleset] then
+ return cached_full_lexes[sourcename][ruleset]
+ end
local lines = {}
local ret = { source = sourcename, lines = lines }
local n = 1
@@ -131,6 +137,8 @@ function M.string(ruleset, sourcename)
lines[n] = linetab
n = n + 1
end
+ cached_full_lexes[sourcename] = cached_full_lexes[sourcename] or {}
+ cached_full_lexes[sourcename][ruleset] = ret
return ret
end