diff options
Diffstat (limited to 'ast.moon')
| -rw-r--r-- | ast.moon | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -1,3 +1,6 @@ +import Constant from require 'base' +unpack or= table.unpack + unescape = (str) -> str = str\gsub '\\"', '"' str = str\gsub "\\'", "'" @@ -5,7 +8,8 @@ unescape = (str) -> str class Atom - new: (@raw, @style='', @value) => + new: (@raw, @style='', value) => + @value = Constant value _walk_sexpr: => @@ -25,6 +29,8 @@ class Atom @make_strd: (match) -> Atom match, '"', unescape match @make_strq: (match) -> Atom match, "'", unescape match + __tostring: => @stringify! + class Xpr new: (parts, @style='(', tag) => @white = {} @@ -35,7 +41,7 @@ class Xpr @white[i/2] = parts[i+1] if tag - @tag = tag.value + @tag = tag.value\getc! _walk_sexpr: => -- depth first @@ -45,6 +51,9 @@ class Xpr if @style == '(' coroutine.yield @ + head: => @[1].value + tail: => unpack [p.value for p in *@[2,]] + walk_sexpr: => coroutine.wrap -> @_walk_sexpr! @@ -72,6 +81,8 @@ class Xpr make_nexpr: (parts) -> Xpr parts, 'naked' + __tostring: => @stringify! + { :Atom :Xpr |
