aboutsummaryrefslogtreecommitdiff
path: root/lib/core
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-02-05 15:45:27 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-02-05 15:47:01 -0800
commit72d699fe86ddb34473b54a0df27d21b4a9159284 (patch)
treebdb4036181b5c15d920d1500f8f67407a44d2014 /lib/core
parent0ff3219f355b4307783288800724213636920912 (diff)
Bunch of changes:
- Added shebangs to generated code output - SyntaxTree:map() -> SyntaxTree:with(), and corresponding changes to metaprogramming API - Added (return Lua 1) shorthand for (return (Lua 1)) - (1 and 2 and 3) compile rule mapping to -> (1 and (*extra arguments*)) - Don't scan for errors, just report them when compiling - Syntax changes: - Added prefix actions (e.g. #$foo) - Operator chars now include utf8 chars - Ditch "escaped nomsu" type (use (\ 1) compile action instead)
Diffstat (limited to 'lib/core')
-rw-r--r--lib/core/control_flow.nom205
-rw-r--r--lib/core/errors.nom137
-rw-r--r--lib/core/metaprogramming.nom105
-rw-r--r--lib/core/text.nom19
-rw-r--r--lib/core/things.nom23
5 files changed, 243 insertions, 246 deletions
diff --git a/lib/core/control_flow.nom b/lib/core/control_flow.nom
index 415611b..ca67394 100644
--- a/lib/core/control_flow.nom
+++ b/lib/core/control_flow.nom
@@ -64,25 +64,23 @@ test:
# If $when_true_expr is guaranteed to be truthy, we can use Lua's idiomatic
equivalent of a conditional expression: (cond and if_true or if_false)
if {.Text, .List, .Dict, .Number}.($when_true_expr.type):
- return
- Lua ("
- (\($condition as lua expr) and \($when_true_expr as lua expr) or \
- ..\($when_false_expr as lua expr))
- ")
+ return Lua ("
+ (\($condition as lua expr) and \($when_true_expr as lua expr) or \
+ ..\($when_false_expr as lua expr))
+ ")
..else:
# Otherwise, need to do an anonymous inline function (yuck, too bad lua
doesn't have a proper ternary operator!)
To see why this is necessary consider: (random()<.5 and false or 99)
- return
- Lua ("
- ((function()
- if \($condition as lua expr) then
- return \($when_true_expr as lua expr)
- else
- return \($when_false_expr as lua expr)
- end
- end)())
- ")
+ return Lua ("
+ ((function()
+ if \($condition as lua expr) then
+ return \($when_true_expr as lua expr)
+ else
+ return \($when_false_expr as lua expr)
+ end
+ end)())
+ ")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -117,15 +115,15 @@ test:
# Basic loop control
(stop $var) compiles to:
if $var:
- return (Lua "goto stop_\($var as lua identifier)")
+ return Lua "goto stop_\($var as lua identifier)"
..else:
- return (Lua "break")
+ return Lua "break"
(do next $var) compiles to:
if $var:
- return (Lua "goto continue_\($var as lua identifier)")
+ return Lua "goto continue_\($var as lua identifier)"
..else:
- return (Lua "goto continue")
+ return Lua "goto continue"
(---stop $var ---) compiles to "::stop_\($var as lua identifier)::"
(---next $var ---) compiles to "::continue_\($var as lua identifier)::"
@@ -162,18 +160,75 @@ test:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# For-each loop (lua's "ipairs()")
+(for $var in $iterable at $i $body) compiles to:
+ # This uses Lua's approach of only allowing loop-scoped variables in a loop
+ if (($iterable.type == "Action") and (($iterable, get stub) == "1 to")):
+ [$start, $stop] = [$iterable.1, $iterable.3]
+ $loop =
+ Lua ("
+ local _start = \($start as lua expr)
+ for \($var as lua identifier)=_start,\($stop as lua expr) do
+ \($i as lua identifier) = \($var as lua identifier) - _start + 1
+ ")
+ if (($iterable.type == "Action") and (($iterable, get stub) == "1 to 2 by")):
+ [$start, $stop, $step] = [$iterable.1, $iterable.3, $iterable.5]
+ $loop =
+ Lua ("
+ local _start, _step = \($start as lua expr), \($step as lua expr)
+ for \($var as lua identifier)=_start,\($stop as lua expr),_step do
+ \($i as lua identifier) = (\($var as lua identifier) - _start)/_step + 1
+ ")
+ unless $loop:
+ $loop =
+ Lua ("
+ local _iterating = _1_as_list(\($iterable as lua expr))
+ for \($i as lua identifier)=1,#_iterating do
+ \($var as lua identifier) = _iterating[\($i as lua identifier)]
+ ")
+ $lua =
+ Lua ("
+ do -- for-loop
+ \$loop
+ \;
+ ")
+ $lua, add ($body as lua)
+ if ($body has subtree \(do next)):
+ $lua, add "\n ::continue::"
+
+ if ($body has subtree \(do next $var)):
+ $lua, add "\n " (\(---next $var ---) as lua)
+
+ $lua, add "\n end"
+ if ($body has subtree \(stop $var)):
+ $lua, add "\n " (\(---stop $var ---) as lua)
+ $lua, add "\nend -- for-loop"
+ return $lua
+
+(for $var in $iterable $body) parses as
+ for $var in $iterable at (=lua "_i") $body
+
test:
+ $d = {.a = 10, .b = 20, .c = 30, .d = 40, .e = 50}
+ $result = []
+ for $k = $v in $d:
+ if ($k == "a"):
+ do next $k
+
+ if ($v == 20):
+ do next $v
+
+ $result, add "\$k = \$v"
+ assume (($result sorted) == ["c = 30", "d = 40", "e = 50"])
+
+# Numeric range for loops
+test:
+ assume ([: for $ in (1 to 5): add $] == [1, 2, 3, 4, 5])
+ assume ([: for $ in (1 to 5 by 2): add $] == [1, 3, 5])
+ assume ([: for $ in (5 to 1): add $] == [])
$nums = []
- for $x in 1 to 5:
- $nums, add $x
- assume ($nums == [1, 2, 3, 4, 5])
- $nums = []
- for $x in 1 to 5 via 2:
- $nums, add $x
- assume ($nums == [1, 3, 5])
- $nums = []
- for $outer in 1 to 100:
- for $inner in $outer to ($outer + 2):
+ for $outer in (1 to 100):
+ for $inner in ($outer to ($outer + 2)):
if ($inner == 2):
$nums, add -2
do next $inner
@@ -182,47 +237,25 @@ test:
stop $outer
assume ($nums == [1, -2, 3, -2, 3, 4, 3, 4, 5])
-# Numeric range for loops
+# These are shims, and should be phased out:
[
for $var in $start to $stop by $step $body
for $var in $start to $stop via $step $body
-] all compile to:
- # This uses Lua's approach of only allowing loop-scoped variables in a loop
- $lua =
- Lua ("
- for \($var as lua identifier)=\($start as lua expr),\($stop as lua expr),\
- ..\($step as lua expr) do
- ")
- $lua, add "\n " ($body as lua)
- if ($body has subtree \(do next)):
- $lua, add "\n ::continue::"
-
- if ($body has subtree \(do next $var)):
- $lua, add "\n " (\(---next $var ---) as lua)
-
- $lua, add "\nend -- numeric for " ($var as lua identifier) " loop"
- if ($body has subtree \(stop $var)):
- $lua =
- Lua ("
- do -- scope for (stop \($var as lua identifier))
- \$lua
- \(\(---stop $var ---) as lua)
- end -- scope for (stop \($var as lua identifier))
- ")
- return $lua
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+] all parse as (for $var in ($start to $stop by $step) $body)
(for $var in $start to $stop $body) parses as
- for $var in $start to $stop via 1 $body
+ for $var in ($start to $stop) $body
+# repeat $n times is a shorthand:
test:
$x = 0
repeat 5 times:
$x += 1
assume $x == 5
-(repeat $n times $body) parses as (for (=lua "_XXX_") in 1 to $n $body)
+(repeat $n times $body) parses as (for (=lua "_XXX_") in (1 to $n by 1) $body)
+
+# Dict iteration (lua's "pairs()")
test:
$a = [10, 20, 30, 40, 50]
$b = []
@@ -239,48 +272,9 @@ test:
$b, add $x
assume ($b == [20, 30, 40])
+ # Small memory footprint:
+ assume (1 to (1 << 31))
-# For-each loop (lua's "ipairs()")
-(for $var in $iterable at $i $body) compiles to:
- # This uses Lua's approach of only allowing loop-scoped variables in a loop
- $lua =
- Lua ("
- for \($i as lua identifier),\($var as lua identifier) in ipairs(\($iterable as lua expr)) do
- \;
- ")
- $lua, add ($body as lua)
- if ($body has subtree \(do next)):
- $lua, add "\n ::continue::"
-
- if ($body has subtree \(do next $var)):
- $lua, add "\n " (\(---next $var ---) as lua)
-
- $lua, add "\nend --for \($var as lua identifier) loop"
- if ($body has subtree \(stop $var)):
- $inner_lua = $lua
- $lua = (Lua "do -- scope for stopping for-loop\n ")
- $lua, add $inner_lua "\n "
- $lua, add (\(---stop $var ---) as lua)
- $lua, add "\nend -- end of scope for stopping for-loop"
- return $lua
-
-(for $var in $iterable $body) parses as
- for $var in $iterable at (=lua "__") $body
-
-test:
- $d = {.a = 10, .b = 20, .c = 30, .d = 40, .e = 50}
- $result = []
- for $k = $v in $d:
- if ($k == "a"):
- do next $k
-
- if ($v == 20):
- do next $v
-
- $result, add "\$k = \$v"
- assume (($result sorted) == ["c = 30", "d = 40", "e = 50"])
-
-# Dict iteration (lua's "pairs()")
[for $key = $value in $iterable $body, for $key $value in $iterable $body]
..all compile to:
$lua =
@@ -453,13 +447,12 @@ test:
")
$code, add "\nend --when"
- return
- Lua ("
- do --if $ is...
- local \(mangle "branch value") = \($branch_value as lua expr)
- \$code
- end -- if $ is...
- ")
+ return Lua ("
+ do --if $ is...
+ local \(mangle "branch value") = \($branch_value as lua expr)
+ \$code
+ end -- if $ is...
+ ")
# Do/finally
(do $action) compiles to ("
diff --git a/lib/core/errors.nom b/lib/core/errors.nom
index 6be7e7f..a05c7d4 100644
--- a/lib/core/errors.nom
+++ b/lib/core/errors.nom
@@ -18,65 +18,79 @@ use "core/control_flow"
if ($condition.type == "Action"):
when $condition.stub is:
"1 ==":
- return
- LuaCode ("
- do
- local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
- if _a ~= _b then
- _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
- _b = type_of(_b) == 'Text' and _b:as_lua() or _1_as_text(_b)
- at_1_fail(\(quote "\($condition.1.source)"),
- "Assumption failed: This value was ".._a.." but it was expected to be ".._b..".")
- end
+ return Lua ("
+ do -- Assumption:
+ local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
+ if _a ~= _b then
+ _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
+ _b = type_of(_b) == 'Text' and _b:as_lua() or _1_as_text(_b)
+ at_1_fail(\(quote "\($condition.1.source)"),
+ "Assumption failed: This value was ".._a.." but it was expected to be ".._b..".")
end
- ")
+ end
+ ")
+
"1 !=":
- return
- LuaCode ("
- do
- local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
- if _a == _b then
- _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
- at_1_fail(\(quote "\($condition.1.source)"),
- "Assumption failed: This value was ".._a.." but it wasn't expected to be.")
- end
+ return Lua ("
+ do -- Assumption:
+ local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
+ if _a == _b then
+ _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
+ at_1_fail(\(quote "\($condition.1.source)"),
+ "Assumption failed: This value was ".._a.." but it wasn't expected to be.")
end
- ")
+ end
+ ")
+
"1 >" "1 <" "1 >=" "1 <=":
- return
- LuaCode ("
- do
- local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
- if _a ~= _b then
- _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
- _b = type_of(_b) == 'Text' and _b:as_lua() or _1_as_text(_b)
- at_1_fail(\(quote "\($condition.1.source)"),
- "Assumption failed: This value was ".._a..", but it was expected to be \($condition.3)".._b..".")
- end
+ return Lua ("
+ do -- Assumption:
+ local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
+ if _a ~= _b then
+ _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
+ _b = type_of(_b) == 'Text' and _b:as_lua() or _1_as_text(_b)
+ at_1_fail(\(quote "\($condition.1.source)"),
+ "Assumption failed: This value was ".._a..", but it was expected to be \
+ ..\($condition.3)".._b..".")
end
- ")
+ end
+ ")
+
"1 is":
- return
- LuaCode ("
- do
- local _ta, _tb = type_of(\($condition.1 as lua expr)), \($condition.3 as lua expr)
- if _ta ~= _tb then
- at_1_fail(\(quote "\($condition.1.source)"),
- "Assumption failed: This value was ".._ta.." but it was expected to be ".._tb..".")
- end
+ return Lua ("
+ do -- Assumption:
+ local _a, _b = \($condition.1 as lua expr), \($condition.3 as lua expr)
+ if not _1_is(_a, _b) then
+ _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
+ at_1_fail(\(quote "\($condition.1.source)"),
+ "Assumption failed: This value (".._a..") was expected to be "..\
+ .._b..", but wasn't.")
end
- ")
- return
- LuaCode ("
- if not \($condition as lua expr) then
- at_1_fail(\(quote "\($condition.source)"), "Assumption failed: This assumption did not hold.")
- end
- ")
+ end
+ ")
+
+ "1 isn ' t" "1 is not":
+ return Lua ("
+ do -- Assumption:
+ local _a, _b = \($condition.1 as lua expr), \($condition.(#$condition) as lua expr)
+ if _1_is(_a, _b) then
+ _a = type_of(_a) == 'Text' and _a:as_lua() or _1_as_text(_a)
+ at_1_fail(\(quote "\($condition.1.source)"),
+ "Assumption failed: This value (".._a..") was expected to not be \
+ ..".._b..", but it was.")
+ end
+ end
+ ")
+
+ return Lua ("
+ if not \($condition as lua expr) then
+ at_1_fail(\(quote "\($condition.source)"), "Assumption failed: This assumption did not hold.")
+ end
+ ")
(assume $a == $b) parses as (assume ($a == $b))
(assume $a != $b) parses as (assume ($a != $b))
(test that $condition) parses as (assume $condition)
-
test:
try: fail
$worked = (no)
@@ -109,21 +123,20 @@ test:
if ($msg_lua, text, is lua id):
$fallback_lua, add free vars [($msg_lua, text)]
$fallback_lua, prepend "-- Failure:\n"
- return
- Lua ("
- do
- local _fell_through = false
- local _result = {xpcall(function()
- \($action as lua)
- _fell_through = true
- end, enhance_error)}
- if _result[1] then
- \$success_lua
- else
- \$fallback_lua
- end
+ return Lua ("
+ do
+ local _fell_through = false
+ local _result = {xpcall(function()
+ \($action as lua)
+ _fell_through = true
+ end, enhance_error)}
+ if _result[1] then
+ \$success_lua
+ else
+ \$fallback_lua
end
- ")
+ end
+ ")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/lib/core/metaprogramming.nom b/lib/core/metaprogramming.nom
index 3ac8c4a..c310fdd 100644
--- a/lib/core/metaprogramming.nom
+++ b/lib/core/metaprogramming.nom
@@ -44,8 +44,8 @@ lua> ("
end
elseif not arg_lua:is_lua_id() then
at_1_fail(SyntaxTree:is_instance(arg) and arg or nil,
- "Compile error: This does not compile to a Lua identifier, so it "..
- "can't be used as a function argument. "..
+ "Compile error: This does not compile to a Lua identifier ("..arg_lua.."),"..
+ "so it can't be used as a function argument. "..
"Hint: This should probably be a Nomsu variable instead (like $x).")
end
lua:add(i > 1 and ", " or "", arg_lua)
@@ -97,7 +97,7 @@ lua> ("
(\$action.type == "EscapedNomsu" and \$action[1].type == "Action") or
\$action.type == "MethodCall") then
at_1_fail(\$action.source, "Compile error: "..
- "This is neither an action nor an escaped action. "..
+ "This first argument to (* compiles to *) is neither an action nor an escaped action (it's a "..\$action.type.."). "..
"Hint: This should probably be an action like:\\n"
.."(foo $x) compiles to \\"(\\\\($x as lua) + 1)\\"")
end
@@ -117,6 +117,8 @@ lua> ("
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+(` $) compiles to (Lua (=lua "\$ or SyntaxTree{type='Action'}", as lua))
+
($actions all compile to $body) compiles to:
lua> ("
if \$actions.type ~= "List" then
@@ -308,22 +310,19 @@ test:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[$action parses as $body] all parse as ([$action] all parse as $body)
-external:
- (in (nomsu environment) $tree as lua expr) means:
- lua> ("
- local tree_lua = \(nomsu environment):compile(\$tree)
- if \$tree.type == 'Block' then
- tree_lua = LuaCode:from(\$tree.source, '(function()\\n ', tree_lua, '\\nend)()')
- elseif \$tree.type == 'MethodCall' and #\$tree > 2 then
- at_1_fail(\$tree, "Compile error: This must be a single value instead of "..
- (#\$tree - 1).." method calls. Hint: Replace this with a single method call.")
- end
- return tree_lua
- ")
+
+((nomsu environment), $tree as lua expr) means:
+ lua> ("
+ local tree_lua = \(nomsu environment):compile(\$tree)
+ if \$tree.type == 'Block' and #\$tree > 1 then
+ tree_lua = LuaCode:from(\$tree.source, '(function()\\n ', tree_lua, '\\nend)()')
+ end
+ return tree_lua
+ ")
# Need to make sure the proper environment is used for compilation (i.e. the caller's environment)
($tree as lua expr) compiles to
- \(in \(nomsu environment) $tree as lua expr) as lua
+ =lua "SyntaxTree{type='MethodCall', \(\(nomsu environment)), \(\($tree as lua expr))}"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -340,11 +339,11 @@ external:
")
test:
- (num args (*extra arguments*)) means (select "#" (*extra arguments*))
+ (num args (*extra arguments*)) means (#(*extra arguments*))
assume (num args 1 2 3) == 3
(extra args (*extra arguments*)) means [*extra arguments*]
assume (extra args 1 2 3) == [1, 2, 3]
- (third arg (*extra arguments*)) means (select 3 (*extra arguments*))
+ (third arg (*extra arguments*)) means ((*extra arguments*).3)
assume (third arg 5 6 7 8) == 7
(*extra arguments*) compiles to "..."
@@ -353,44 +352,6 @@ external:
($ is $kind syntax tree) means
=lua "SyntaxTree:is_instance(\$) and \$.type == \$kind"
-($tree with $t -> $replacement) compiles to ("
- \($tree as lua expr):map(function(\($t as lua expr))
- \(
- =lua ("
- \$replacement.type == 'Block' and \($replacement as lua) or 'return '..\
- ..\($replacement as lua expr):text()
- ")
- )
- end)
-")
-
-external:
- ($tree with vars $replacements) means
- =lua ("
- \$tree:map(function(\$t)
- if \$t.type == "Var" then
- return \$replacements[\$t:as_var()]
- end
- end)
- ")
-
-(tree $tree with vars $replacements) compiles to ("
- \(=lua "(\$tree):as_lua()"):map(function(t)
- if t.type == "Var" then
- return \($replacements as lua expr)[t:as_var()]
- end
- end)
-")
-
-($tree has subtree $match_tree) compiles to ("
- (function()
- local match_tree = \($match_tree as lua expr)
- for subtree in coroutine_wrap(function() \($tree as lua expr):map(yield) end) do
- if subtree == match_tree then return true end
- end
- end)()
-")
-
external:
(match $tree with $patt) means:
lua> ("
@@ -444,12 +405,24 @@ external:
if mt and mt.__type then return mt.__type end
if \$ == nil then return 'nil' end
local lua_type = \(lua type of $)
- if lua_type == 'function' then return "an Action" end
return 'a '..lua_type:capitalized()
")
-($ is $type) parses as ((type of $) == $type)
-[$ isn't $type, $ is not $type] all parse as ((type of $) != $type)
+ ($ is $type) means:
+ lua> ("
+ local class = getmetatable(\$)
+ ::check_parent::
+ if not class or not class.__type then return 'a '..lua_type:capitalized() == \$type end
+ if class.__type == \$type then return true end
+ local class_mt = getmetatable(class)
+ if class_mt.__index and class_mt.__index ~= class then
+ class = class_mt.__index
+ goto check_parent
+ end
+ return false
+ ")
+
+[$ isn't $type, $ is not $type] all parse as (not ($ is $type))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -482,6 +455,9 @@ test:
return lua
")
+# Convenience helper:
+(return Lua (*extra arguments*)) compiles to \(return \(Lua (*extra arguments*)))
+
# Literals
(yes) compiles to "(true)"
(no) compiles to "(false)"
@@ -525,3 +501,14 @@ external:
return ("
\(Nomsu syntax version).\(core version).\(Nomsu compiler version).\(lib version)
")
+
+~~~~
+# TODO: Remove shim
+($tree with $t -> $replacement) parses as
+ $tree, with ($t -> $replacement)
+
+[tree $tree with vars $replacements, $tree with vars $replacements] all parse as
+ ($tree, with $replacements)
+
+($tree has subtree $match_tree) parses as
+ $tree, contains $match_tree
diff --git a/lib/core/text.nom b/lib/core/text.nom
index 1401cf2..d7719b3 100644
--- a/lib/core/text.nom
+++ b/lib/core/text.nom
@@ -43,16 +43,15 @@ test:
($expr for $match in $text matching $patt) compiles to:
define mangler
- return
- Lua ("
- (function()
- local \(mangle "comprehension") = a_List{}
- for \($match as lua expr) in (\($text as lua expr)):gmatch(\($patt as lua expr)) do
- \(mangle "comprehension")[#\(mangle "comprehension")+1] = \($expr as lua)
- end
- return \(mangle "comprehension")
- end)()
- ")
+ return Lua ("
+ (function()
+ local \(mangle "comprehension") = a_List{}
+ for \($match as lua expr) in (\($text as lua expr)):gmatch(\($patt as lua expr)) do
+ \(mangle "comprehension")[#\(mangle "comprehension")+1] = \($expr as lua)
+ end
+ return \(mangle "comprehension")
+ end)()
+ ")
test:
assume "\n" == (newline)
diff --git a/lib/core/things.nom b/lib/core/things.nom
index 5f74b1a..6ba21cb 100644
--- a/lib/core/things.nom
+++ b/lib/core/things.nom
@@ -37,6 +37,8 @@ test:
($self, number of commas) means ((#$bits) - 1)
$csv = (a Comma Buffer)
assume $csv.is_a_buffer
+ assume ($csv is "a Comma Buffer")
+ assume ($csv is "a Buffer")
assume "\$csv" == ""
$csv, add "x"
$csv, add "y"
@@ -96,17 +98,20 @@ external:
Compile error: This is not a list of variables.
")
$class_id = ($classname.stub, as lua id)
- if $class_body:
- $class_body =
- $class_body with vars {
- : for $v in $vars:
- add ($v as lua expr, text) =
- "IndexChain" tree with ("Var" tree with "self")
- "Index" tree with ("Text" tree with $v.1)
- }
+ $class_body and=
+ $class_body, with
+ $t ->:
+ for $v in $vars:
+ if ($t == $v):
+ return
+ "IndexChain" tree with ("Var" tree with "self")
+ "Index" tree with ("Text" tree with $v.1)
+
+ if ($parent.type == "Action"):
+ $parent = ("Var" tree with $parent)
$lua =
Lua ("
- \$class_id = _1_class_named(\($parent as lua), \(quote $classname.stub)\(
+ \$class_id = _1_class_named(\($parent as lua id), \(quote $classname.stub)\(
(
Lua ("
, function(\$class_id)