diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2019-02-05 15:45:27 -0800 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2019-02-05 15:47:01 -0800 |
| commit | 72d699fe86ddb34473b54a0df27d21b4a9159284 (patch) | |
| tree | bdb4036181b5c15d920d1500f8f67407a44d2014 /syntax_tree.moon | |
| parent | 0ff3219f355b4307783288800724213636920912 (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 'syntax_tree.moon')
| -rw-r--r-- | syntax_tree.moon | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/syntax_tree.moon b/syntax_tree.moon index 278e22b..1800fcb 100644 --- a/syntax_tree.moon +++ b/syntax_tree.moon @@ -24,6 +24,7 @@ class SyntaxTree __eq: (other)=> return false if type(@) != type(other) or #@ != #other or getmetatable(@) != getmetatable(other) + return false if @type != other.type for i=1,#@ return false if @[i] != other[i] return true @@ -44,7 +45,20 @@ class SyntaxTree }) get_source_file: => @@source_code_for_tree[@] get_source_code: => @@source_code_for_tree[@]\sub(@source.start, @source.stop-1) - map: (fn)=> + + add: (...)=> + n = #@ + for i=1,select('#', ...) + @[n+i] = select(i, ...) + @stub = nil + + with: (fn)=> + if type(fn) == 'table' + replacements = fn + fn = (t)-> + for k,v in pairs(replacements) + if k == t then return v + replacement = fn(@) if replacement == false then return nil if replacement @@ -60,7 +74,7 @@ class SyntaxTree for k,v in pairs(@) replacement[k] = v if SyntaxTree\is_instance(v) - r = v\map(fn) + r = v\with(fn) continue if r == v or r == nil changes = true replacement[k] = r @@ -68,6 +82,13 @@ class SyntaxTree replacement = SyntaxTree(replacement) return replacement + contains: (subtree)=> + if subtree == @ then return true + for k,v in pairs(@) + if SyntaxTree\is_instance(v) + return true if v\contains(subtree) + return false + get_args: => assert(@type == "Action" or @type == "MethodCall", "Only actions and method calls have arguments") args = {} |
