aboutsummaryrefslogtreecommitdiffstats
path: root/ast.moon
diff options
context:
space:
mode:
authors-ol <s-ol@users.noreply.github.com>2020-02-01 23:51:40 +0000
committers-ol <s-ol@users.noreply.github.com>2020-02-01 23:55:30 +0000
commit177cd265947bfd9db20ad1a99ae07c76b6b4f147 (patch)
tree49af71e06770925abb0ab1fd2e89be077281b74c /ast.moon
parentfirst-class scopes (diff)
downloadalive-177cd265947bfd9db20ad1a99ae07c76b6b4f147.tar.gz
alive-177cd265947bfd9db20ad1a99ae07c76b6b4f147.zip
macros and scopes
Diffstat (limited to 'ast.moon')
-rw-r--r--ast.moon27
1 files changed, 20 insertions, 7 deletions
diff --git a/ast.moon b/ast.moon
index 7996c0f..99b200a 100644
--- a/ast.moon
+++ b/ast.moon
@@ -86,9 +86,17 @@ class Xpr
@white[i/2] = parts[i+1]
expand: (scope) =>
- scope = Scope @, scope
- for child in *@
- child\expand scope
+ head = @[1]
+ head\expand scope
+
+ @scope = Scope @, scope
+
+ if head.value.type == 'macro'
+ macro = head.value\getc!
+ macro scope, @
+ else
+ for child in *@[2,]
+ child\expand scope
link: =>
head = @head!
@@ -128,10 +136,15 @@ class Xpr
make_nexpr: (...) -> Xpr 'naked', ...
__tostring: =>
- if @tag
- "<Xpr[#{@tag}] #{@value}>"
- else
- "<Xpr #{@value}>"
+ if @style == 'naked'
+ return 'ROOT'
+
+ buf = "("
+ buf ..= "[#{@tag}]" if @tag
+ buf ..= "#{@[1].raw}"
+ buf ..= " ..." if #@ > 1
+ buf ..= ")"
+ buf
{
:Atom