aboutsummaryrefslogtreecommitdiff
path: root/nomnom
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-11-02 14:38:24 -0700
committerBruce Hill <bruce@bruce-hill.com>2018-11-02 14:39:23 -0700
commit307dea18815ba4a06a3098edb170d7ad90708815 (patch)
treebce78eb28fa03c9939a92e08e47564afc984c988 /nomnom
parentd0c3c57f7b25c8d912c426e48cb5ab09cd738f65 (diff)
Changed stub convention to (foo 1 baz 2) -> foo_1_baz instead of
foo_1_baz_2, removed "smext", made some cleanup changes.
Diffstat (limited to 'nomnom')
-rw-r--r--nomnom/ast.nom3
-rw-r--r--nomnom/code_obj.nom269
-rw-r--r--nomnom/compile.nom49
-rw-r--r--nomnom/decompile.nom39
-rw-r--r--nomnom/parser.nom2
5 files changed, 161 insertions, 201 deletions
diff --git a/nomnom/ast.nom b/nomnom/ast.nom
index 4d261aa..ef41b26 100644
--- a/nomnom/ast.nom
+++ b/nomnom/ast.nom
@@ -32,7 +32,7 @@ object (Syntax Tree):
return %children
my action [as lua] "\
- ..a_Syntax_Tree_with_1(\(call ({} 's metatable).as_lua with [%me]))"
+ ..a_Syntax_Tree_with(\(call ({} 's metatable).as_lua with [%me]))"
my action [as nomsu] "\
..(a Syntax Tree with \(call ({} 's metatable).as_nomsu with [%me]))"
my action [as text] "\
@@ -86,4 +86,3 @@ object (Syntax Tree):
unless ((% is text) or (%.type == "Comment")): %args::add %
return %args
-(Syntax Tree).map = (Syntax Tree).map_1
diff --git a/nomnom/code_obj.nom b/nomnom/code_obj.nom
index 8379f36..c8d2784 100644
--- a/nomnom/code_obj.nom
+++ b/nomnom/code_obj.nom
@@ -2,103 +2,89 @@
# This file contains objects that are used to track code positions and incrementally
build up generated code, while keeping track of where it came from, and managing
indentation levels.
-use "lib/object.nom"
+use "lib/things.nom"
-object (Hole):
- externally (Hole from %lua) means:
- return (Hole {lua:%lua})
- my action [as lua]: return %me.lua
- my action [as nomsu]:
- return "(Hole {lua:\(%me.lua)})"
- my action [as text]:
- barf "Not implemented"
- my action [as smext]:
- barf "Must fill in holes before smexting"
+a (Code Buffer) is a thing:
+ that can (set up) by:
+ assume %its.source
+ %old_bits = (%its.bits if (%its.bits is a "List") else [%its.bits])
+ %its.bits = []
+ if (type of %its.source) is:
+ "Text":
+ %its.source = (Source from text %its.source)
+ "Syntax Tree":
+ %its.source = %its.source.source
-object (Code):
- my action [set up]:
- assume %me.source
- %old_bits = (%me.bits if (%me.bits is a "List") else [%me.bits])
- %me.bits = []
- if (%me.source is text):
- %me.source = (Source from text %me.source)
- for % in %old_bits: %me::add %
-
- my action [as text]:
- barf "Not implemented"
- my action [as smext]:
- if (%me.__str == (nil)):
- set {%buff:[], %indent:0}
- for %bit in %me.bits:
+ for % in %old_bits: %its::add %
+
+ whose (text) means:
+ if (%its._text == (nil)):
+ %buff = []
+ %indent = 0
+ for %bit in %its.bits:
if (%bit is text):
%spaces = (%bit::matching "\n([ ]*)[^\n]*$")
if %spaces: %indent = (size of %spaces.1)
..else:
- %bit = (%bit::as smext)
+ %bit = (%bit::text)
if (%indent > 0):
%bit = (%bit::with "\n" -> "\n\(" "::* %indent)")
-
%buff::add %bit
-
- %me.__str = (%buff::joined)
-
- return %me.__str
-
- my action [as lua]:
- barf
- return "\
- ..\(%me.class.name::as lua id)_from_1_2(\(..)
- (%me.source::as lua) if %me.source else "nil"
- .., \(%me.bits::as lua))"
-
- my action [as nomsu] "\
- ..(\(%me.class.name) \((%me.source::as nomsu) if %me.source else "(nil)") \(..)
- %me.bits::as nomsu
- ..)"
-
- my action [size] (size of (%me::as smext))
- my action [mark as dirty]:
- %me.__str = (nil)
- %me._trailing_line_len = (nil)
- %me._num_lines = (nil)
-
- my action [add %new_bits]:
+ %its._text = (%buff::joined)
+ return %its._text
+
+ whose (lua code) means "\
+ ..a_\(%its.class.name::as lua id)_with{source=\(..)
+ (%its.source::as lua) if %its.source else "nil"
+ .., \(%its.bits::as lua)}"
+
+ whose (nomsu code) means "\
+ ..(a \(%its.class.name) with {source: \((%its.source::as nomsu) if %its.source else "(nil)"), bits: \(..)
+ %its.bits::as nomsu
+ ..})"
+
+ whose (size) means (size of (%its::text))
+
+ that can (mark as dirty) by:
+ %its._text = (nil)
+ %its._trailing_line_len = (nil)
+ %its._num_lines = (nil)
+
+ that can (add %new_bits) by:
unless (%new_bits is a "List"):
%new_bits = [%new_bits]
for % in %new_bits:
if (% == ""): do next %
-
#if ((% isn't text) and (% isn't a (Code))):
% = (%::as lua)
- %me.bits::add %
-
- %me::mark as dirty
+ %its.bits::add %
+ %its::mark as dirty
- my action [trailing line length]:
- if (%me._trailing_line_len == (nil)):
- %me._trailing_line_len = (size of ((%me::as smext)::matching "[^\n]*$"))
- return %me._trailing_line_len
+ whose (trailing line length) means:
+ if (%its._trailing_line_len == (nil)):
+ %its._trailing_line_len = (size of ((%its::text)::matching "[^\n]*$"))
+ return %its._trailing_line_len
- my action [number of lines]:
- unless %me._num_lines:
+ whose (number of lines) means:
+ unless %its._num_lines:
%num_lines = 1
- for % in %me:
+ for % in %its:
if (% is text):
%num_lines += (size of (%::all matches of "\n"))
..else:
%num_lines += ((%::number of lines) - 1)
- %me._num_lines = %num_lines
+ %its._num_lines = %num_lines
- return %me._num_lines
+ return %its._num_lines
- my action [is multiline, is multi-line] ((%me::number of lines) > 1)
- my action [is one line, is single line] ((%me::number of lines) == 1)
- my action [add %values joined with %joiner]:
- %me::add %values joined with %joiner or %joiner
- my action [add %values joined with %joiner or %wrapping_joiner]:
+ whose [is multiline, is multi-line] all mean ((%its::number of lines) > 1)
+ whose [is one line, is single line] all mean ((%its::number of lines) == 1)
+ that can (add %values joined with %joiner) by:
+ %its::add %values joined with %joiner or %joiner
+ that can [add %values joined with %joiner or %wrapping_joiner] by:
%line_len = 0
- %bits = %me.bits
+ %bits = %its.bits
for %value in %values at %i:
if (%i > 1):
if (%line_len > 80):
@@ -108,65 +94,71 @@ object (Code):
%bits::add %value
unless (%value is text):
- %value = (%value::as smext)
+ %value = (%value::text)
%line = (%value::matching "\n([^\n]*)$")
if %line:
%line_len = (size of %line)
..else:
%line_len += (size of %value)
-
- %me::mark as dirty
+ %its::mark as dirty
- my action [prepend %]:
- #if ((% isn't text) and (% isn't a %me.__type)):
+ that can (prepend %) by:
+ #if ((% isn't text) and (% isn't a %its.__type)):
% = (%::as lua)
- %me.bits::add % at index 1
- %me::mark as dirty
+ %its.bits::add % at index 1
+ %its::mark as dirty
- my action [parenthesize]:
- %me.bits::add "(" at index 1
- %me.bits::add ")"
- %me::mark as dirty
+ that can (parenthesize) by:
+ %its.bits::add "(" at index 1
+ %its.bits::add ")"
+ %its::mark as dirty
-object (Lua Code) extends (Code):
- my action [add free vars %vars]:
+a (Lua Buffer) is a thing:
+ that has [..]
+ text, lua code, nomsu code, trailing line length, size, number of lines,
+ is multiline, is multi-line, is one line, is single line,
+ ..like a (Code Buffer)
+ that can [..]
+ set up, mark as dirty, add %, prepend %, parenthesize,
+ add % joined with %, add % joined with % or %,
+ ..like a (Code Buffer)
+
+ that can (add free vars %vars) by:
if ((size of %vars) == 0): return
- %seen = (%v = (yes) for %v in %me.free_vars)
+ %seen = (%v = (yes) for %v in %its.free_vars)
for %var in %vars:
assume (%var is text)
unless %seen.%var:
- %me.free_vars::add %var
+ %its.free_vars::add %var
%seen.%var = (yes)
- %me::mark as dirty
+ %its::mark as dirty
- my action [remove free vars %vars]:
+ that can (remove free vars %vars) by:
if ((size of %vars) == 0): return
%removals = {}
for %var in %vars:
assume (%var is text)
%removals.%var = (yes)
- %stack = [%me]
+ %stack = [%its]
repeat while ((size of %stack) > 0):
%lua = (%stack::pop)
for %i in (size of %lua.free_vars) to 1 by -1:
if %removals.(%lua.free_vars.%i):
- lua> "table.remove(\%lua.free_vars, \%i)"
- #TODO: reinstate this
- #%lua.free_vars::remove at index %i
-
+ %lua.free_vars::remove at index %i
for % in %lua.bits:
unless (% is text): %stack::add %
- %me::mark as dirty
+ %its::mark as dirty
- my action [declare locals] (%me::declare locals (nil))
- my action [declare locals %to_declare]:
+ that can (declare locals) by (%its::declare locals (nil))
+ that can (declare locals %to_declare) by:
unless %to_declare:
- set {%to_declare:[], %seen:{}}
- for %lua in recursive %me:
+ %to_declare = []
+ %seen = {}
+ for %lua in recursive %its:
for %var in %lua.free_vars:
unless %seen.%var:
%seen.%var = (yes)
@@ -176,70 +168,43 @@ object (Lua Code) extends (Code):
unless (% is text): recurse %lua on %
if ((size of %to_declare) > 0):
- %me::remove free vars %to_declare
- %me::prepend "local \(%to_declare::joined with ", ");\n"
+ %its::remove free vars %to_declare
+ %its::prepend "local \(%to_declare::joined with ", ");\n"
return %to_declare
- my action [as statements] (%me::as statements "" ";")
- my action [as statements %prefix] (%me::as statements %prefix ";")
- my action [as statements %prefix %suffix]:
- unless %me.is_value: return %me
- %statements = (Lua Code from %me.source [])
+ whose (as statements) means (%its::as statements with "")
+ whose (as statements with %prefix) means:
+ unless %its.is_value: return %its
+ %statements = (a Lua Buffer with {source:%its.source})
if ((%prefix or "") != ""):
%statements::add %prefix
- %statements::add %me
- if (%suffix != ""):
- %statements::add (%suffix or ";")
+ %statements::add %its
+ %statements::add ";"
return %statements
- my action [variables]:
+ that can (mark as value) by:
+ %its.is_value = (yes)
+
+ that can (mark as variable) by:
+ %its.is_variable = (yes)
+ %its.is_value = (yes)
+
+ that can (variables) by:
%vars = []
- for %code in recursive %me:
+ for %code in recursive %its:
if %code.is_variable:
- %vars::add (%code::as smext)
+ %vars::add (%code::text)
for % in %code.bits:
unless (% is text): recurse %code on %
return %vars
- externally (Lua Code from %source %bits) means:
- assume %source
- unless (%bits is a "List"): %bits = [%bits]
- if (%source is a "Syntax Tree"):
- %source = %source.source
- return (Lua Code {source:%source, bits:%bits, is_value:no, free_vars:[]})
-
- externally (Lua Code from %source) means (Lua Code from %source [])
- externally (Lua Value from %source %bits) means:
- assume %source
- unless (%bits is a "List"): %bits = [%bits]
- if (%source is a "Syntax Tree"):
- %source = %source.source
- return (Lua Code {source:%source, bits:%bits, is_value:yes, free_vars:[]})
-
- externally (Lua Value from %source) means (Lua Value from %source [])
- externally (Lua Variable from %source) means (Lua Variable from %source [])
- externally (Lua Variable from %source %bits) means:
- assume %source
- unless (%bits is a "List"): %bits = [%bits]
- if (%source is a "Syntax Tree"):
- %source = %source.source
- return (..)
- Lua Code {..}
- source:%source, bits:%bits, is_value:yes, is_variable:yes, free_vars:[]
-
-# TODO: remove this shim
-(Lua Code).add_free_vars = (Lua Code).add_free_vars_1
-(Lua Code).remove_free_vars = (Lua Code).remove_free_vars_1
-(Lua Code).declare_locals = (Lua Code).declare_locals_1
-(Lua Code).as_statements = (Lua Code).as_statements_1_2
-object (Nomsu Code) extends (Code):
- externally (Nomsu Code from %source %bits) means:
- if (%bits is text): %bits = [%bits]
- if (%source is a "Syntax Tree"):
- %source = %source.source
- return (Nomsu Code {source:%source, bits:%bits})
-
- externally (Nomsu Code from %source) means (Nomsu Code from %source [])
- externally (Nomsu Code %bits) means (Nomsu Code from (nil) %bits)
- externally (Nomsu Code) means (Nomsu Code from (nil) [])
+a (Nomsu Buffer) is a thing:
+ that has [..]
+ text, lua code, nomsu code, trailing line length, size, number of lines,
+ is multiline, is multi-line, is one line, is single line,
+ ..like a (Code Buffer)
+ that can [..]
+ set up, mark as dirty, add %, prepend %, parenthesize,
+ add % joined with %, add % joined with % or %,
+ ..like a (Code Buffer)
diff --git a/nomnom/compile.nom b/nomnom/compile.nom
index 70f32b8..8241ef2 100644
--- a/nomnom/compile.nom
+++ b/nomnom/compile.nom
@@ -45,7 +45,7 @@ externally (%tree compiled with %compile_actions) means:
# TODO: restore this:
#%args = [%tree, %compile_actions]
%args = [%nomsu, %tree]
- for % in (%tree::get args): %args::add %
+ for % in (%tree::arguments): %args::add %
%result = (call %compile_action with %args)
if (%result == (nil)):
report compile error at %tree "\
@@ -64,13 +64,13 @@ externally (%tree compiled with %compile_actions) means:
return %result
- %lua = (Lua Value from %tree)
+ %lua = (a Lua Buffer with {source:%tree})
if %tree.target:
# Method call
%target_lua = (%tree.target compiled with %compile_actions)
if (..)
- ((%target_lua::as smext)::matches "^%(.*%)$") or (..)
- (%target_lua::as smext)::matches "^[_a-zA-Z][_a-zA-Z0-9]*$"
+ ((%target_lua::text)::matches "^%(.*%)$") or (..)
+ (%target_lua::text)::matches "^[_a-zA-Z][_a-zA-Z0-9]*$"
..:
%lua::add [%target_lua, ":"]
..else:
@@ -93,14 +93,14 @@ externally (%tree compiled with %compile_actions) means:
if ((size of %values) == 1):
%arg_lua = %values.1
..else:
- %arg_lua = (Lua Value from %tok ["("])
+ %arg_lua = (a Lua Buffer with {source:%tok, is_value:yes, bits:["("]})
%arg_lua::add %values joined with " and nil or "
%arg_lua::add ")"
..else:
- %arg_lua = (Lua Value from %tok ["((function()"])
+ %arg_lua = (a Lua Buffer with {source:%tok, is_value:yes, bits:["((function()"]})
for %v in %values at %i:
if %v.is_value:
- %v = (%v::as statements ("return " if (%i == (size of %values) else "")))
+ %v = (%v::as statements with ("return " if (%i == (size of %values) else "")))
%arg_lua::add ["\n ", %v]
%arg_lua::add "\nend)())"
@@ -124,8 +124,7 @@ externally (%tree compiled with %compile_actions) means:
return %lua
"EscapedNomsu":
- #return (Lua Value from %tree ((%tree.1)::as lua))
- %lua = (Lua Value from %tree ["a_Syntax_Tree_with_1{type=", quote %tree.(1).type])
+ %lua = (a Lua Buffer with {source:%tree, is_value:yes, bits:["a_Syntax_Tree_with{type=", quote %tree.(1).type]})
set {%needs_comma:no, %i:1}
(% as shmua) means:
if (% is a "Lua number"): return "\%"
@@ -152,7 +151,7 @@ externally (%tree compiled with %compile_actions) means:
return %lua
"Block":
- %lua = (Lua Code from %tree)
+ %lua = (a Lua Buffer with {source:%tree})
%lua::add (..)
((%line compiled with %compile_actions)::as statements) for %line in %tree
..joined with "\n"
@@ -160,7 +159,7 @@ externally (%tree compiled with %compile_actions) means:
return %lua
"Text":
- %lua = (Lua Value from %tree)
+ %lua = (a Lua Buffer with {source:%tree})
%lua_bits = []
%string_buffer = ""
for % in %tree:
@@ -178,7 +177,7 @@ externally (%tree compiled with %compile_actions) means:
..Can't use this as a string interpolation value, since it doesn't have a value."
if (%.type != "Text"):
- %bit_lua = (Lua Value from % ["tostring(", %bit_lua, ")"])
+ %bit_lua = (a Lua Buffer with {source:%, is_value:yes, bits:["tostring(", %bit_lua, ")"]})
%lua_bits::add %bit_lua
if ((%string_buffer != "") or ((size of %lua_bits) == 0)):
@@ -188,13 +187,13 @@ externally (%tree compiled with %compile_actions) means:
return %lua
"List":
- %lua = (Lua Value from %tree ["List{"])
+ %lua = (a Lua Buffer with {source:%tree, is_value:yes, bits:["List{"]})
%lua::add ((% compiled with %compile_actions) for % in %tree) joined with ", " or ",\n "
%lua::add "}"
return %lua
"Dict":
- %lua = (Lua Value from %tree ["Dict{"])
+ %lua = (a Lua Buffer with {source:%tree, is_value:yes, bits:["Dict{"]})
%lua::add ((% compiled with %compile_actions) for % in %tree) joined with ", " or ",\n "
%lua::add "}"
return %lua
@@ -208,24 +207,24 @@ externally (%tree compiled with %compile_actions) means:
%value_lua = (..)
(%value compiled with %compile_actions) if %value else (..)
- Lua Value from %key ["true"]
+ a Lua Buffer with {source:%key, is_value:yes, bits:["true"]}
unless %value_lua.is_value:
report compile error at %tree.2 "\
..Can't use this as a dict value, since it's not an expression."
- %key_str = ((%key_lua::as smext)::matching "^[\"']([a-zA-Z_][a-zA-Z0-9_]*)['\"]$")
+ %key_str = ((%key_lua::text)::matching "^[\"']([a-zA-Z_][a-zA-Z0-9_]*)['\"]$")
if:
%key_str:
- return (Lua Code from %tree [%key_str, "=", %value_lua])
- ((%key_lua::as smext).1 == "["):
+ return (a Lua Buffer with {source:%tree, bits:[%key_str, "=", %value_lua]})
+ ((%key_lua::text).1 == "["):
# NOTE: this *must* use a space after the [ to avoid freaking out
Lua's parser if the inner expression is a long string. Lua
parses x[[[y]]] as x("[y]"), not as x["y"]
- return (Lua Code from %tree ["[ ", %key_lua, "]=", %value_lua])
+ return (a Lua Buffer with {source:%tree, bits:["[ ", %key_lua, "]=", %value_lua]})
else:
- return (Lua Code from %tree ["[", %key_lua, "]=", %value_lua])
+ return (a Lua Buffer with {source:%tree, bits:["[", %key_lua, "]=", %value_lua]})
"IndexChain":
%lua = (%tree.1 compiled with %compile_actions)
@@ -233,7 +232,7 @@ externally (%tree compiled with %compile_actions) means:
report compile error at %tree.1 "\
..Can't index into this, since it's not an expression."
- %first_char = (%lua::as smext).1
+ %first_char = (%lua::text).1
if (any of [%first_char == "{", %first_char == "\"", %first_char == "["]):
%lua::parenthesize
for %i in 2 to (size of %tree):
@@ -243,7 +242,7 @@ externally (%tree compiled with %compile_actions) means:
report compile error at %key "\
..Can't use this as an index, since it's not an expression."
- %key_lua_str = (%key_lua::as smext)
+ %key_lua_str = (%key_lua::text)
%lua_id = (%key_lua_str::matching "^['\"]([a-zA-Z_][a-zA-Z0-9_]*)['\"]$")
if:
%lua_id:
@@ -260,16 +259,16 @@ externally (%tree compiled with %compile_actions) means:
return %lua
"Number":
- return (Lua Value from %tree ["\(%tree.1)"])
+ return (a Lua Buffer with {source:%tree, is_value:yes, bits:["\(%tree.1)"]})
"Var":
- return (Lua Variable from %tree [%tree.1::as lua id])
+ return (a Lua Buffer with {source:%tree, is_value:yes, is_variable:yes, bits:[%tree.1::as lua id]})
"FileChunks":
barf "\
..Can't convert FileChunks to a single block of lua, since each chunk's compilation depends on the earlier chunks"
"Comment":
# TODO: de-implement?
- return (Lua Code from %tree "-- \(%tree.1::with "\n" -> "\n-- ")")
+ return (a Lua Buffer with {source:%tree, bits:["-- \(%tree.1::with "\n" -> "\n-- ")"]})
"Error":
barf (%tree as a pretty error)
diff --git a/nomnom/decompile.nom b/nomnom/decompile.nom
index 7db61c8..11ec233 100644
--- a/nomnom/decompile.nom
+++ b/nomnom/decompile.nom
@@ -8,7 +8,7 @@ externally (%tree decompiled inline) means:
assume (%tree is a "Syntax Tree")
if %tree.type is:
"Action":
- %nomsu = (Nomsu Code from %tree)
+ %nomsu = (a Nomsu Buffer with {source: %tree})
if %tree.target:
%target_nomsu = (%tree.target decompiled inline)
if %tree.target.type is:
@@ -44,17 +44,17 @@ externally (%tree decompiled inline) means:
..:
%inner_nomsu::parenthesize
- %nomsu = (Nomsu Code from %tree ["\\", %inner_nomsu])
+ %nomsu = (a Nomsu Buffer with {source: %tree, bits: ["\\", %inner_nomsu]})
return %nomsu
"Block":
- %nomsu = (Nomsu Code from %tree [":"])
+ %nomsu = (a Nomsu Buffer with {source: %tree, bits: [":"]})
for %line in %tree at %i:
%nomsu::add [" " if (%i == 1) else "; ", %line decompiled inline]
return %nomsu
"Text":
- %nomsu = (Nomsu Code from %tree [])
+ %nomsu = (a Nomsu Buffer with {source: %tree, bits: []})
for %text in recursive %tree:
for %bit in %text at %i:
if (%bit is text): %nomsu::add %bit
@@ -78,10 +78,10 @@ externally (%tree decompiled inline) means:
else:
%nomsu::add ["\\(", %bit decompiled inline, ")"]
- return (Nomsu Code from %tree ["\"", %nomsu, "\""])
+ return (a Nomsu Buffer with {source: %tree, bits: ["\"", %nomsu, "\""]})
"List" "Dict":
- %nomsu = (Nomsu Code from %tree ["[" if (%tree.type == "List") else "{"])
+ %nomsu = (a Nomsu Buffer with {source: %tree, bits: ["[" if (%tree.type == "List") else "{"]})
for %item in %tree at %i:
if (%i > 1): %nomsu::add ", "
%nomsu::add (%item decompiled inline)
@@ -94,7 +94,7 @@ externally (%tree decompiled inline) means:
if (..)
all of [%key.type == "Text", (size of %key) == 1, %key.1 is a nomsu identifier]
..:
- %nomsu = (Nomsu Code from %key [%key.1])
+ %nomsu = (a Nomsu Buffer with {source: %key, bits: [%key.1]})
..else:
%nomsu = (%key decompiled inline)
@@ -107,7 +107,7 @@ externally (%tree decompiled inline) means:
return %nomsu
"IndexChain":
- %nomsu = (Nomsu Code from %tree)
+ %nomsu = (a Nomsu Buffer with {source: %tree})
for %bit in %tree at %i:
if (%i > 1): %nomsu::add "."
if (..)
@@ -128,9 +128,9 @@ externally (%tree decompiled inline) means:
return %nomsu
"Number":
- return (Nomsu Code from %tree [(%tree.1 as hex) if %tree.hex else "\(%tree.1)"])
+ return (a Nomsu Buffer with {source: %tree, bits: [(%tree.1 as hex) if %tree.hex else "\(%tree.1)"]})
"Var":
- return (Nomsu Code from %tree ["%\(%tree.1)"])
+ return (a Nomsu Buffer with {source: %tree, bits: ["%\(%tree.1)"]})
"Comment": return (nil)
"FileChunks":
barf "Can't inline a FileChunks"
@@ -141,7 +141,7 @@ externally (%tree decompiled inline) means:
%MAX_LINE = 90
externally (%tree decompiled) means:
- %nomsu = (Nomsu Code from %tree)
+ %nomsu = (a Nomsu Buffer with {source: %tree})
# For concision:
(recurse on %t) means:
@@ -167,8 +167,7 @@ externally (%tree decompiled) means:
%indented = (%t decompiled)
if (%t.type == "Action"):
%indented = (..)
- Nomsu Code from %t [..]
- "(..)\n ", %indented
+ a Nomsu Buffer with {source: %t, bits: ["(..)\n ", %indented]}
return %indented
@@ -253,13 +252,12 @@ externally (%tree decompiled) means:
..else: %nomsu::add "\n"
return (..)
- Nomsu Code from %tree [..]
- ":\n ", %nomsu
+ a Nomsu Buffer with {source: %tree, bits: [":\n ", %nomsu]}
"Text":
# Multi-line text has more generous wrap margins
%max_line = ((1.5 * %MAX_LINE) rounded down)
- %nomsu = (Nomsu Code from %tree)
+ %nomsu = (a Nomsu Buffer with {source: %tree})
(add text from %tree) means:
for %bit in %tree at %i:
if (%bit is text):
@@ -301,8 +299,7 @@ externally (%tree decompiled) means:
add text from %tree
return (..)
- Nomsu Code from %tree [..]
- "\"\\\n ..", %nomsu, "\""
+ a Nomsu Buffer with {source: %tree, bits: ["\"\\\n ..", %nomsu, "\""]}
"List" "Dict":
if ((size of %tree) == 0):
@@ -321,9 +318,9 @@ externally (%tree decompiled) means:
..else: %nomsu::add ", "
return (..)
- Nomsu Code from %tree [..]
- "[..]\n " if (%tree.type == "List") else "{..}\n "
- %nomsu
+ a Nomsu Buffer with {..}
+ source: %tree, bits: [..]
+ "[..]\n " if (%tree.type == "List") else "{..}\n ", %nomsu
"DictEntry":
set {%key:%tree.1, %value:%tree.2}
diff --git a/nomnom/parser.nom b/nomnom/parser.nom
index 13d6112..fe237e8 100644
--- a/nomnom/parser.nom
+++ b/nomnom/parser.nom
@@ -32,7 +32,7 @@ set {..}
%source = (..)
Source {filename:%userdata.filename, start:%t.start, stop:%t.stop}
set {%t.start: nil, %t.stop: nil, %t.source: %source}
- %t = (Syntax Tree %t)
+ %t = (a Syntax Tree with %t)
(Syntax Tree).source_code_for_tree.%t = %userdata.source
return %t
..with fallback %key ->: