From ba1824a904369a39f6cf3c063a27f2d5deadd036 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Tue, 2 Jan 2024 17:25:10 +0100 Subject: [PATCH] Operator priority cleanup --- anselme/common/init.lua | 11 ++++++----- .../secondary/infix/implicit_multiplication.lua | 2 +- ideas.md | 3 ++- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/anselme/common/init.lua b/anselme/common/init.lua index acf07a8..fde5f2c 100644 --- a/anselme/common/init.lua +++ b/anselme/common/init.lua @@ -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 } } diff --git a/anselme/parser/expression/secondary/infix/implicit_multiplication.lua b/anselme/parser/expression/secondary/infix/implicit_multiplication.lua index 4757e06..e5c80da 100644 --- a/anselme/parser/expression/secondary/infix/implicit_multiplication.lua +++ b/anselme/parser/expression/secondary/infix/implicit_multiplication.lua @@ -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) diff --git a/ideas.md b/ideas.md index 74f6d87..4600a14 100644 --- a/ideas.md +++ b/ideas.md @@ -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: _|>_, _::_ ---