From b6d3cbd61cd08e39d20a569b7c5ece6bb25897dd Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Tue, 1 Jan 2019 15:05:58 -0800 Subject: Misc changes, including text indented interpolations are now indented relative to the text, not the opening '("', code objects can now remove all free vars, the REPL uses global vars. Error API is changing a bit. --- tools/repl.nom | 57 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 19 deletions(-) (limited to 'tools') diff --git a/tools/repl.nom b/tools/repl.nom index 983de5f..4240ddc 100755 --- a/tools/repl.nom +++ b/tools/repl.nom @@ -42,25 +42,44 @@ repeat: if ((size of $buff) == 0): stop $buff = ($buff, joined) - - # TODO: support local variables spoof file $buff try: - $ret = (run $buff) - ..and if it barfs $err: say $err - ..or if it succeeds: - if (type of $ret) is: - "nil": - do nothing - - "boolean": - say "= \("yes" if $ret else "no")" - - "table": - if $ret.as_nomsu: - say "= \($ret, as nomsu)" - ..else: + $tree = ($buff parsed) + ..and if it barfs $err: + say $err + do next + + unless $tree: + do next + + for $chunk in $tree: + try: + $lua = ($chunk as lua) + ..and if it barfs $err: say $err + + unless $lua: + do next + + # TODO: this is a bit hacky, it just defaults variables to global + so that stuff mostly works across multiple lines. It would be + nicer if local variables actually worked. + $lua, remove free vars + try: + $ret = (run $lua) + ..and if it barfs $err: say $err + ..or if it succeeds: + if (type of $ret) is: + "nil": + do nothing + + "boolean": + say "= \("yes" if $ret else "no")" + + "table": + if $ret.as_nomsu: + say "= \($ret, as nomsu)" + ..else: + say "= \$ret" + + else: say "= \$ret" - - else: - say "= \$ret" -- cgit v1.2.3