1
0
Fork 0
mirror of https://github.com/Reuh/anselme.git synced 2025-10-27 16:49:31 +00:00

Operator priority cleanup

This commit is contained in:
Étienne Fildadut 2024-01-02 17:25:10 +01:00
parent 68a109391f
commit ba1824a904
3 changed files with 9 additions and 7 deletions

View file

@ -30,7 +30,7 @@ local common = {
-- list of operators and their priority that are handled through regular function calls & can be overloaded/etc. by the user
regular_operators = {
prefixes = {
{ ">", 3.1 }, -- just above _=_
{ ">", 4 }, -- just above _=_
{ "!", 11 },
{ "-", 11 },
{ "*", 11 },
@ -44,9 +44,9 @@ local common = {
{ ";", 1 },
{ "#", 2 }, { "->", 2 },
{ "|>", 5 }, { "&", 5 }, { "|", 5 },
{ "==", 7 }, { "!=", 7 }, { ">=", 7 }, { "<=", 7 }, { "<", 7 }, { ">", 7 },
{ "+", 8 }, { "-", 8 },
{ "//", 9 }, { "/", 9 }, { "*", 9 }, { "%", 9 },
{ "==", 6 }, { "!=", 6 }, { ">=", 6 }, { "<=", 6 }, { "<", 6 }, { ">", 6 },
{ "+", 7 }, { "-", 7 },
{ "//", 8 }, { "/", 8 }, { "*", 8 }, { "%", 8 },
{ "^", 10 },
{ "::", 11 },
{ ".", 14 },
@ -59,8 +59,9 @@ local common = {
["$_"] = 2,
["_,_"] = 2,
["_=_"] = 3,
["_implicit*_"] = 9, -- just aboce _*_
["_!_"] = 12,
["_()"] = 13
["_()"] = 13 -- just above _!
-- generated at run-time for regular operators
}
}

View file

@ -9,7 +9,7 @@ local Call, Identifier, ArgumentTuple = ast.Call, ast.Identifier, ast.ArgumentTu
return infix {
operator = "*",
identifier = "_*_",
priority = operator_priority["_*_"]+.1, -- just above / so 1/2x gives 1/(2x)
priority = operator_priority["_implicit*_"],
match = function(self, str, current_priority, primary)
return self.priority > current_priority and identifier:match(str)

View file

@ -50,6 +50,7 @@ Probably wise to look into how other do it. LSP: https://microsoft.github.io/lan
---
Default arguments and initial variables values should pass the type check associated with the variable / parameter.
Issue: dispatch is decided before evaluating default values.
---
@ -67,7 +68,7 @@ Syntax modifications:
Could interpret the left operand as a string when it is an identifier, like how _._ works.
Would feel good to have less nodes. But because we can doesn't mean we should. Also Assignment is reused in a few other places.
- remove operators if possible, i'd like to avoid the code looking like a bunch of sigils
- remove operators if possible, i'd like to avoid the code looking like a bunch of sigils. Could be replaced by functions: _|>_, _::_
---