diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-06-14 21:59:25 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-06-14 21:59:43 -0700 |
| commit | 82cfd3e54b5910843c091a9fb6ef3ad6b64ba757 (patch) | |
| tree | aed04a3910646c82447b9b4b515169005b3010af /core/text.nom | |
| parent | 282565a309aef632502a64fef0a67b0b7efcfaaa (diff) | |
More streamlining and cleanup. Especially for core/metaprogramming.nom
Diffstat (limited to 'core/text.nom')
| -rw-r--r-- | core/text.nom | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/core/text.nom b/core/text.nom index 8b75ca4..e6065c1 100644 --- a/core/text.nom +++ b/core/text.nom @@ -18,6 +18,14 @@ compile [capitalized %text, %text capitalized] to compile [%text with %sub instead of %patt, %text s/%patt/%sub] to Lua value "((\(%text as lua expr)):gsub(\(%patt as lua expr), \(%sub as lua expr)))" +action [lines in %text, lines of %text] + lua> ".." + local result = {} + for line in (\%text):gmatch('[^\n]+') do + result[#result+1] = line + end + return result + # Text literals lua> ".." do @@ -26,8 +34,8 @@ lua> ".." backspace="\\\\b", ["form feed"]="\\\\f", formfeed="\\\\f", ["vertical tab"]="\\\\v", }; for name, e in pairs(escapes) do - local lua = "'"..e.."'"; - nomsu:define_compile_action(name, function(tree) return Lua.Value(tree.source, lua); end); + local lua = "'"..e.."'" + _ENV["A"..name:as_lua_id()] = compile_time(function(tree) return Lua.Value(tree.source, lua) end) end local colors = { ["reset color"]="\\\\27[0m", bright="\\\\27[1m", dim="\\\\27[2m", underscore="\\\\27[4m", @@ -42,10 +50,10 @@ lua> ".." for name, c in pairs(colors) do local color = "'"..c.."'"; local reset = "'"..colors["reset color"].."'"; - nomsu:define_compile_action(name, function(tree) return Lua.Value(tree.source, color); end); - nomsu:define_compile_action(name.." %", function(\%) - return Lua.Value(tree.source, color, "..", \(% as lua), "..", reset); - end); + _ENV["A"..name:as_lua_id()] = compile_time(function(tree) return Lua.Value(tree.source, color) end) + _ENV["A"..name:as_lua_id().."_1"] = compile_time(function(tree, text) + return Lua.Value(tree.source, color, "..", nomsu:tree_to_lua(text), "..", reset); + end) end end |
