diff options
| author | s-ol <s-ol@users.noreply.github.com> | 2020-01-30 09:44:23 +0000 |
|---|---|---|
| committer | s-ol <s-ol@users.noreply.github.com> | 2020-01-30 09:44:23 +0000 |
| commit | f526eb9f1ad140a0566c4f18e19b5ce17d6ea2b1 (patch) | |
| tree | 708fc4cb5100d62f64231d53954e106e28a5ee99 /ast.moon | |
| parent | support tagging (diff) | |
| download | alive-f526eb9f1ad140a0566c4f18e19b5ce17d6ea2b1.tar.gz alive-f526eb9f1ad140a0566c4f18e19b5ce17d6ea2b1.zip | |
more types &c
Diffstat (limited to 'ast.moon')
| -rw-r--r-- | ast.moon | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -1,3 +1,9 @@ +unescape = (str) -> + str = str\gsub '\\"', '"' + str = str\gsub "\\'", "'" + str = str\gsub "\\\\", "\\" + str + class Atom new: (@raw, @style='', @value) => @@ -9,12 +15,15 @@ class Atom @raw when '"' "\"#{@raw}\"" + when "'" + "'#{@raw}'" else - error! + error "unknown atom style: '#{@style}'" - @make_num: (match) -> Atom match, '', tonumber match + @make_num: (match, ...) -> Atom match, '', tonumber match @make_sym: (match) -> Atom match, '', match - @make_str: (match) -> Atom match, '"', match + @make_strd: (match) -> Atom match, '"', unescape match + @make_strq: (match) -> Atom match, "'", unescape match class Xpr new: (parts, @style='(', tag) => @@ -29,12 +38,13 @@ class Xpr @tag = tag.value _walk_sexpr: => - if @style == '(' - coroutine.yield @ - + -- depth first for frag in *@ frag\_walk_sexpr! + if @style == '(' + coroutine.yield @ + walk_sexpr: => coroutine.wrap -> @_walk_sexpr! @@ -48,9 +58,11 @@ class Xpr switch @style when 'naked' buf - else + when '(' tag = if @tag then "[#{@tag}]" else '' '(' .. tag .. buf .. ')' + else + error "unknown sexpr style: '#{@style}'" make_sexpr: (tag, parts) -> if parts |
