diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-01-31 13:54:19 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-01-31 13:54:19 +0000 |
| commit | 227c2f0ed83dda049173700ebfa39b664cc84065 (patch) | |
| tree | 38057dfb393a89f7de6b8fdeb822adac8e34e222 /ast.moon | |
| parent | more types &c (diff) | |
| download | alive-227c2f0ed83dda049173700ebfa39b664cc84065.tar.gz alive-227c2f0ed83dda049173700ebfa39b664cc84065.zip | |
comments, actual working things
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 |
