aboutsummaryrefslogtreecommitdiff
path: root/lib/text.nom
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-01-25 17:34:49 -0800
committerBruce Hill <bitbucket@bruce-hill.com>2018-01-25 17:36:05 -0800
commitc79bea44016daf43f05300b772011b14125fa0df (patch)
tree10dbbc3bef495662be829b73893660622bd2d2c1 /lib/text.nom
parentf769351556cceed58ab6bf844c671114ec1862c2 (diff)
Overhaul of compiling API (eliminated some of the expr/statements
helpers and forced the use of {expr=..., locals=...}-type syntax. This helped fix up all of the cases like loops where locals were being mishandled and led to some cleaner code.
Diffstat (limited to 'lib/text.nom')
-rw-r--r--lib/text.nom64
1 files changed, 33 insertions, 31 deletions
diff --git a/lib/text.nom b/lib/text.nom
index 0bd7a8a..982db63 100644
--- a/lib/text.nom
+++ b/lib/text.nom
@@ -13,41 +13,43 @@ action [%texts joined with %glue]
parse [joined %texts, %texts joined] as: %texts joined with ""
compile [capitalized %text capitalized] to
- "(\(%text as lua)):gsub('%l', string.upper, 1)"
+ {expr:"(\(%text as lua expr)):gsub('%l', string.upper, 1)"}
compile [%text with %sub instead of %patt, %text s/%patt/%sub] to
- "((\(%text as lua)):gsub(\(%patt as lua), \(%sub as lua)))"
+ {expr:"((\(%text as lua expr)):gsub(\(%patt as lua expr), \(%sub as lua expr)))"}
-compile [indented %text, %text indented] to "\%text:gsub('\\n','\\n'..(' '))"
-compile [dedented %obj, %obj dedented] to "nomsu:dedent(\(%obj as lua))"
-compile [%text indented %n times] to "\%text:gsub('\\n','\\n'..(' '):rep(\%n))"
+compile [indented %text, %text indented] to {expr:"\%text:gsub('\\n','\\n'..(' '))"}
+compile [dedented %obj, %obj dedented] to {expr:"nomsu:dedent(\(%obj as lua expr))"}
+compile [%text indented %n times] to {expr:"\%text:gsub('\\n','\\n'..(' '):rep(\%n))"}
# Text literals
-lua do> ".."
- local escapes = {
- nl="\\\\n", newline="\\\\n", tab="\\\\t", bell="\\\\a", cr="\\\\r", ["carriage return"]="\\\\r",
- backspace="\\\\b", ["form feed"]="\\\\f", formfeed="\\\\f", ["vertical tab"]="\\\\v",
- };
- local colors = {
- ["reset color"]="\\\\27[0m", bright="\\\\27[1m", dim="\\\\27[2m", underscore="\\\\27[4m",
- blink="\\\\27[5m", inverse="\\\\27[7m", hidden="\\\\27[8m",
-
- black="\\\\27[30m", red="\\\\27[31m", green="\\\\27[32m", yellow="\\\\27[33m", blue="\\\\27[34m",
- magenta="\\\\27[35m", cyan="\\\\27[36m", white="\\\\27[37m",
-
- ["on black"]="\\\\27[40m", ["on red"]="\\\\27[41m", ["on green"]="\\\\27[42m", ["on yellow"]="\\\\27[43m",
- ["on blue"]="\\\\27[44m", ["on magenta"]="\\\\27[45m", ["on cyan"]="\\\\27[46m", ["on white"]="\\\\27[47m",
- };
- for name, e in pairs(escapes) do
- local lua = "'"..e.."'";
- nomsu:define_compile_action(name, \(__line_no__), function() return {expr=text}; end, \(__src__ 1));
- end
- for name, c in pairs(colors) do
- local color = "'"..c.."'";
- local reset = "'"..colors["reset color"].."'";
- nomsu:define_compile_action(name, \(__line_no__), function() return {expr=color}; end, \(__src__ 1));
- nomsu:define_compile_action(name.." %", \(__line_no__), function(\%)
- return {expr=color..".."..nomsu:tree_to_lua(\%).expr..".."..reset};
- end, \(__src__ 1));
+lua> ".."
+ do
+ local escapes = {
+ nl="\\\\n", newline="\\\\n", tab="\\\\t", bell="\\\\a", cr="\\\\r", ["carriage return"]="\\\\r",
+ 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, \(!! code location !!), function() return {expr=text}; end);
+ end
+ local colors = {
+ ["reset color"]="\\\\27[0m", bright="\\\\27[1m", dim="\\\\27[2m", underscore="\\\\27[4m",
+ blink="\\\\27[5m", inverse="\\\\27[7m", hidden="\\\\27[8m",
+
+ black="\\\\27[30m", red="\\\\27[31m", green="\\\\27[32m", yellow="\\\\27[33m", blue="\\\\27[34m",
+ magenta="\\\\27[35m", cyan="\\\\27[36m", white="\\\\27[37m",
+
+ ["on black"]="\\\\27[40m", ["on red"]="\\\\27[41m", ["on green"]="\\\\27[42m", ["on yellow"]="\\\\27[43m",
+ ["on blue"]="\\\\27[44m", ["on magenta"]="\\\\27[45m", ["on cyan"]="\\\\27[46m", ["on white"]="\\\\27[47m",
+ };
+ for name, c in pairs(colors) do
+ local color = "'"..c.."'";
+ local reset = "'"..colors["reset color"].."'";
+ nomsu:define_compile_action(name, \(!! code location !!), function() return {expr=color}; end);
+ nomsu:define_compile_action(name.." %", \(!! code location !!), function(\%)
+ return {expr=color..".."..nomsu:tree_to_lua(\%).expr..".."..reset};
+ end);
+ end
end