mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 08:39:30 +00:00
[internal] ; operators now build a block instead of function call
This commit is contained in:
parent
6d9c3dd403
commit
5d9af414fa
5 changed files with 26 additions and 13 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
4
ideas.md
4
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue