mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-27 16:49:31 +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 },
|
{ "%", 11 },
|
||||||
},
|
},
|
||||||
suffixes = {
|
suffixes = {
|
||||||
{ ";", 1 },
|
|
||||||
{ "!", 12 }
|
{ "!", 12 }
|
||||||
},
|
},
|
||||||
infixes = {
|
infixes = {
|
||||||
{ ";", 1 },
|
|
||||||
{ "#", 2 }, { "->", 2 },
|
{ "#", 2 }, { "->", 2 },
|
||||||
{ "=", 3 },
|
{ "=", 3 },
|
||||||
{ "&", 5 }, { "|", 5 },
|
{ "&", 5 }, { "|", 5 },
|
||||||
|
|
@ -58,6 +56,8 @@ local common = {
|
||||||
},
|
},
|
||||||
-- list of all operators and their priority
|
-- list of all operators and their priority
|
||||||
operator_priority = {
|
operator_priority = {
|
||||||
|
["_;"] = 1,
|
||||||
|
["_;_"] = 1,
|
||||||
[";_"] = 1,
|
[";_"] = 1,
|
||||||
["$_"] = 2,
|
["$_"] = 2,
|
||||||
["_,_"] = 2,
|
["_,_"] = 2,
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,19 @@
|
||||||
local infix_or_suffix = require("anselme.parser.expression.secondary.infix.infix_or_suffix")
|
local infix_or_suffix = require("anselme.parser.expression.secondary.infix.infix_or_suffix")
|
||||||
|
|
||||||
local operator_priority = require("anselme.common").operator_priority
|
local operator_priority = require("anselme.common").operator_priority
|
||||||
|
|
||||||
|
local ast = require("anselme.ast")
|
||||||
|
local Block = ast.Block
|
||||||
|
|
||||||
return infix_or_suffix {
|
return infix_or_suffix {
|
||||||
operator = ";",
|
operator = ";",
|
||||||
identifier = "_;_",
|
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 suffix = require("anselme.parser.expression.secondary.suffix.suffix")
|
||||||
|
|
||||||
local operator_priority = require("anselme.common").operator_priority
|
local operator_priority = require("anselme.common").operator_priority
|
||||||
|
|
||||||
|
local ast = require("anselme.ast")
|
||||||
|
local Block, Nil = ast.Block, ast.Nil
|
||||||
|
|
||||||
return suffix {
|
return suffix {
|
||||||
operator = ";",
|
operator = ";",
|
||||||
identifier = "_;",
|
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
|
local Nil, String = ast.Nil, ast.String
|
||||||
|
|
||||||
return {
|
return {
|
||||||
{ "_;_", "(left, right)", function(state, left, right) return right end },
|
|
||||||
{ "_;", "(left)", function(state, left) return Nil:new() end },
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"print", "(a)",
|
"print", "(a)",
|
||||||
function(state, 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.
|
Macros.
|
||||||
|
|
||||||
Could be implemented by creating functions to build AST nodes from Anselme that can also take quotes as arguments.
|
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