diff --git a/anselme/common/init.lua b/anselme/common/init.lua index f40fcdf..4b7508f 100644 --- a/anselme/common/init.lua +++ b/anselme/common/init.lua @@ -39,11 +39,9 @@ local common = { { "%", 11 }, }, suffixes = { - { ";", 1 }, { "!", 12 } }, infixes = { - { ";", 1 }, { "#", 2 }, { "->", 2 }, { "=", 3 }, { "&", 5 }, { "|", 5 }, @@ -58,6 +56,8 @@ local common = { }, -- list of all operators and their priority operator_priority = { + ["_;"] = 1, + ["_;_"] = 1, [";_"] = 1, ["$_"] = 2, ["_,_"] = 2, diff --git a/anselme/parser/expression/secondary/infix/semicolon.lua b/anselme/parser/expression/secondary/infix/semicolon.lua index 17c0d5e..604ed55 100644 --- a/anselme/parser/expression/secondary/infix/semicolon.lua +++ b/anselme/parser/expression/secondary/infix/semicolon.lua @@ -1,9 +1,19 @@ local infix_or_suffix = require("anselme.parser.expression.secondary.infix.infix_or_suffix") - local operator_priority = require("anselme.common").operator_priority +local ast = require("anselme.ast") +local Block = ast.Block + return infix_or_suffix { operator = ";", identifier = "_;_", - priority = operator_priority["_;_"] + priority = operator_priority["_;_"], + + build_ast = function(self, left, right) + if Block:is(left) then + left:add(right) + else + return Block:new(left, right) + end + end } diff --git a/anselme/parser/expression/secondary/suffix/semicolon.lua b/anselme/parser/expression/secondary/suffix/semicolon.lua index 823b1eb..5a92b2f 100644 --- a/anselme/parser/expression/secondary/suffix/semicolon.lua +++ b/anselme/parser/expression/secondary/suffix/semicolon.lua @@ -1,9 +1,19 @@ local suffix = require("anselme.parser.expression.secondary.suffix.suffix") - local operator_priority = require("anselme.common").operator_priority +local ast = require("anselme.ast") +local Block, Nil = ast.Block, ast.Nil + return suffix { operator = ";", identifier = "_;", - priority = operator_priority["_;"] + priority = operator_priority["_;"], + + build_ast = function(self, left) + if Block:is(left) then + left:add(Nil:new()) + else + return Block:new(left, Nil:new()) + end + end } diff --git a/anselme/stdlib/base.lua b/anselme/stdlib/base.lua index d6e2844..41ea762 100644 --- a/anselme/stdlib/base.lua +++ b/anselme/stdlib/base.lua @@ -2,9 +2,6 @@ local ast = require("anselme.ast") local Nil, String = ast.Nil, ast.String return { - { "_;_", "(left, right)", function(state, left, right) return right end }, - { "_;", "(left)", function(state, left) return Nil:new() end }, - { "print", "(a)", function(state, a) diff --git a/ideas.md b/ideas.md index f9ceec2..e092e2d 100644 --- a/ideas.md +++ b/ideas.md @@ -79,10 +79,6 @@ Then again, performance has never been a goal of Anselme. --- -Redesign the Node hierarchy to avoid cycles. - ---- - Macros. Could be implemented by creating functions to build AST nodes from Anselme that can also take quotes as arguments.