aboutsummaryrefslogtreecommitdiffstats
path: root/alv
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2022-02-04 00:49:32 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-02 14:24:49 +0000
commita3b3db30e1d1ac22852d6c06ea62f0c5e3bc11da (patch)
tree32221fb1eeb814644d1ea58b59f17a7216488eb7 /alv
parentlib: fix midi on Lua 5.1 (diff)
downloadalive-a3b3db30e1d1ac22852d6c06ea62f0c5e3bc11da.tar.gz
alive-a3b3db30e1d1ac22852d6c06ea62f0c5e3bc11da.zip
add Dummy AST node
Diffstat (limited to 'alv')
-rw-r--r--alv/ast.moon12
-rw-r--r--alv/builtins.moon3
-rw-r--r--alv/cell.moon20
-rw-r--r--alv/dummy.moon61
-rw-r--r--alv/result/const.moon11
5 files changed, 88 insertions, 19 deletions
diff --git a/alv/ast.moon b/alv/ast.moon
index b8c14e6..9f0b819 100644
--- a/alv/ast.moon
+++ b/alv/ast.moon
@@ -31,3 +31,15 @@
--
-- @function stringify
-- @treturn string the exact string this Node was parsed from
+
+import Cell from require 'alv.cell'
+import Constant from require 'alv.result.const'
+import Dummy from require 'alv.dummy'
+import Tag from require 'alv.tag'
+
+{
+ :Cell
+ :Constant
+ :Dummy
+ :Tag
+}
diff --git a/alv/builtins.moon b/alv/builtins.moon
index a015bc6..5fe5e99 100644
--- a/alv/builtins.moon
+++ b/alv/builtins.moon
@@ -11,6 +11,7 @@ import Constant from require 'alv.result'
import Error from require 'alv.error'
import RTNode from require 'alv.rtnode'
import Cell from require 'alv.cell'
+import Dummy from require 'alv.dummy'
import Scope from require 'alv.scope'
import Tag from require 'alv.tag'
import op_invoke from require 'alv.invoke'
@@ -407,7 +408,7 @@ trace = Constant.meta
tag = @tag\clone Tag.parse '-1'
inner = Cell tag, {
- Constant.literal T.opdef, traceOp, 'trace'
+ Dummy.literal T.opdef, traceOp
Constant.str tail[1]\stringify 2
tail[1]
}
diff --git a/alv/cell.moon b/alv/cell.moon
index 36d5f43..1b035f4 100644
--- a/alv/cell.moon
+++ b/alv/cell.moon
@@ -17,13 +17,6 @@ class Cell
--- members
-- @section members
- new: (@tag=Tag.blank!, @children, @white) =>
- if not @white
- @white = [' ' for i=1,#@children]
- @white[0] = ''
-
- assert #@white == #@children, "mismatched whitespace length"
-
--- get the head of the cell.
--
-- @treturn AST
@@ -125,6 +118,19 @@ class Cell
--- static functions
-- @section static
+ --- construct a new Cell.
+ --
+ -- @classmethod
+ -- @tparam[opt] Tag tag
+ -- @tparam {AST,...} children
+ -- @tparam[opt] {string,...} white whitespace strings
+ new: (@tag=Tag.blank!, @children, @white) =>
+ if not @white
+ @white = [' ' for i=1,#@children]
+ @white[0] = ''
+
+ assert #@white == #@children, "mismatched whitespace length"
+
parse_args = (tag, parts) ->
if not parts
parts, tag = tag, nil
diff --git a/alv/dummy.moon b/alv/dummy.moon
new file mode 100644
index 0000000..ec16aa5
--- /dev/null
+++ b/alv/dummy.moon
@@ -0,0 +1,61 @@
+----
+-- Dummy AST Node.
+--
+-- Implements the `AST` interface.
+--
+-- @classmod Dummy
+import RTNode from require 'alv.rtnode'
+import Constant from require 'alv.result.const'
+import Error from require 'alv.error'
+
+class Dummy
+--- members
+-- @section members
+
+ --- the contained node.
+ --
+ -- @tfield RTNode node
+
+--- AST interface
+--
+-- `Dummy` implements the `AST` interface.
+-- @section ast
+
+ --- evaluate this Dummy.
+ --
+ -- returns `node`
+ -- @treturn RTNode `node`
+ eval: => @node
+
+ --- create a clone with its own identity.
+ --
+ -- returns a ref to `node`.
+ --
+ -- @tparam Tag parent
+ -- @treturn Cell
+ clone: => @
+
+ --- stringify this Dummy.
+ --
+ -- throws an error, `Dummy` nodes cannot be stringified.
+ stringify: => error Error, 'implementation', "cannot stringify Dummy"
+
+--- static functions
+-- @section static
+
+ --- construct a new Dummy from a `RTNode`.
+ --
+ -- @classmethod
+ -- @tparam RTNode node
+ new: (@node) =>
+
+ --- construct a new Dummy from a plain value.
+ --
+ -- @tparam Type type
+ -- @tparam any value
+ -- @tparam string raw string
+ @literal: (...) -> @@ RTNode result: Constant ...
+
+{
+ :Dummy
+}
diff --git a/alv/result/const.moon b/alv/result/const.moon
index e4367e7..bace973 100644
--- a/alv/result/const.moon
+++ b/alv/result/const.moon
@@ -67,8 +67,6 @@ class Constant extends Result
-- @tparam Scope scope the scope to evaluate in
-- @treturn RTNode the evaluation result
eval: (scope) =>
- return RTNode result: @ if @literal
-
switch @type
when T.num, T.str
RTNode result: @
@@ -173,15 +171,6 @@ class Constant extends Result
-- @treturn Constant
@bang: -> Constant T.bang, true
- --- create a forced-literal Constant.
- --
- -- For internal use in `Builtin`s only.
- --
- -- @treturn Constant
- @literal: (...) ->
- with Constant ...
- .literal = true
-
--- wrap and document a value.
--
-- wraps `args.value` using `wrap`, then assigns `meta`.