aboutsummaryrefslogtreecommitdiffstats
path: root/alv/cell.moon
diff options
context:
space:
mode:
authors-ol <s+removethis@s-ol.nu>2025-03-18 11:47:22 +0000
committers-ol <s+removethis@s-ol.nu>2025-03-18 12:06:18 +0000
commitb6cbc69461dc054019f50f8971704f6ef9de63ab (patch)
treed2b8942b780f668ccbe57b52dd8d65f61613e935 /alv/cell.moon
parentbuiltins: switch takes single array as value (diff)
downloadalive-wip.tar.gz
alive-wip.zip
language: [array] and {struct} literalswip
Diffstat (limited to 'alv/cell.moon')
-rw-r--r--alv/cell.moon34
1 files changed, 30 insertions, 4 deletions
diff --git a/alv/cell.moon b/alv/cell.moon
index 7b6cf61..7f2c027 100644
--- a/alv/cell.moon
+++ b/alv/cell.moon
@@ -155,6 +155,10 @@ class RootCell extends Cell
head: => Constant.sym 'do'
tail: => @children
+ new: (...) =>
+ super ...
+ @tag = Tag.parse '0'
+
stringify: =>
buf = ''
buf ..= @white[0]
@@ -172,12 +176,34 @@ class RootCell extends Cell
--
-- @tparam table parts
-- @treturn Cell
- @parse: (...) ->
- tag, children, white = parse_args (Tag.parse '0'), ...
- RootCell tag, children, white
+ @parse: (parts) =>
+ _, children, white = parse_args nil, parts
+ @@ nil, children, white
+
+-- @type ArrayCell
+class ArrayCell extends RootCell
+ head: => Constant.sym 'mkarray'
+ tail: => @children
+ stringify: => '[' .. super! .. ']'
+
+ new: (...) =>
+ Cell.__init @, ...
+ assert #@children > 0, Error 'syntax', "array literal can't be empty"
+
+-- @type StructCell
+class StructCell extends RootCell
+ head: => Constant.sym 'mkstruct'
+ tail: => @children
+ stringify: => '{' .. super! .. '}'
+
+ new: (...) =>
+ Cell.__init @, ...
+ assert #@children > 0, Error 'syntax', "struct literal can't be empty"
+ assert #@children % 2 == 0, Error 'syntax', "struct literal can't have uneven number values"
{
:Cell
:RootCell
- :TemplateString
+ :ArrayCell
+ :StructCell
}