aboutsummaryrefslogtreecommitdiffstats
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
parentlib: fix midi on Lua 5.1 (diff)
downloadalive-a3b3db30e1d1ac22852d6c06ea62f0c5e3bc11da.tar.gz
alive-a3b3db30e1d1ac22852d6c06ea62f0c5e3bc11da.zip
add Dummy AST node
-rw-r--r--alv-lib/array-.moon5
-rw-r--r--alv-lib/testing.moon6
-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
7 files changed, 93 insertions, 25 deletions
diff --git a/alv-lib/array-.moon b/alv-lib/array-.moon
index 68557cd..1e7e781 100644
--- a/alv-lib/array-.moon
+++ b/alv-lib/array-.moon
@@ -1,6 +1,5 @@
-import Array, Op, PureOp, Builtin, Constant, Error, const, any, T from require 'alv.base'
-import Cell from require 'alv.cell'
-import Tag from require 'alv.tag'
+import Array, Op, PureOp, Builtin, RTNode, Constant, Error, const, any, T from require 'alv.base'
+import Cell, Tag, Dummy from require 'alv.ast'
builtins = require 'alv.builtins'
unpack or= table.unpack
diff --git a/alv-lib/testing.moon b/alv-lib/testing.moon
index a321e43..7abe9f6 100644
--- a/alv-lib/testing.moon
+++ b/alv-lib/testing.moon
@@ -1,5 +1,5 @@
import Constant, Op, Builtin, Input, Error, T, any, const from require "alv.base"
-import Tag, Cell from require "alv"
+import Cell, Tag, Dummy from require "alv.ast"
assert_ = Constant.meta
meta:
@@ -33,7 +33,7 @@ By default, the message contains the failing check expression."
tag = @tag\clone Tag.parse '-1'
inner = Cell tag, {
- Constant.literal T.opdef, assertOp, 'assert'
+ Dummy.literal T.opdef, assertOp
tail[1]
tail[2] or Constant.str "assertion failed: #{tail[1]\stringify 2}"
}
@@ -76,7 +76,7 @@ If not, throws an error."
assert #tail > 1, "'expect=' takes at least two arguments"
children = {
- Constant.literal T.opdef, expectOp, 'assert'
+ Dummy.literal T.opdef, expectOp
tail[1]
}
for arg in *tail[2,]
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`.