From 87afa51baa3e616780994256dfcac3ddf26954cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Tue, 9 Jan 2024 17:57:13 +0100 Subject: [PATCH] [language] Remove _|>_ operator, replace with *_ --- anselme/ast/Choice.lua | 7 ++---- anselme/common/init.lua | 2 +- anselme/parser/expression/primary/text.lua | 6 ----- .../expression/secondary/infix/choice.lua | 17 ------------- anselme/parser/expression/secondary/init.lua | 1 - anselme/stdlib/init.lua | 5 ++++ anselme/stdlib/language/frFR.lua | 2 ++ anselme/stdlib/text.lua | 5 ++-- test/tests/choice block.ans | 8 +++---- test/tests/choice function.ans | 6 ++--- ...e line interpolation with choice event.ans | 7 +++--- ...ce line interpolation with event flush.ans | 4 ++-- ...ice line interpolation with text event.ans | 8 +++---- test/tests/choice preserve tags.ans | 8 ++++--- test/tests/choice simple.ans | 4 ++-- test/tests/choice text interleaved.ans | 8 +++---- test/tests/choice with decorators.ans | 24 +++++++++---------- test/tests/flush.ans | 6 +++-- test/tests/nested flush.ans | 6 +++-- test/tests/resume anchors.ans | 4 ++-- ...me from paragraph with nested choice 2.ans | 10 ++++---- ...me from paragraph with nested choice 3.ans | 10 ++++---- ...me from paragraph with nested choice 4.ans | 10 ++++---- ...sume from paragraph with nested choice.ans | 10 ++++---- test/tests/return in choice.ans | 2 +- ...t line interpolation with choice event.ans | 4 ++-- 26 files changed, 86 insertions(+), 98 deletions(-) delete mode 100644 anselme/parser/expression/secondary/infix/choice.lua diff --git a/anselme/ast/Choice.lua b/anselme/ast/Choice.lua index c1bedd3..7493830 100644 --- a/anselme/ast/Choice.lua +++ b/anselme/ast/Choice.lua @@ -20,11 +20,8 @@ Choice = ast.abstract.Runtime { fn(self.func, ...) end, - _format = function(self, ...) - return ("%s |> %s"):format(self.text:format(...), self.func:format_right(...)) - end, - _format_priority = function(self) - return operator_priority["_|>_"] + _format = function(self, state, prio, ...) + return ("write choice(%s, %s)"):format(self.text:format(state, operator_priority["_,_"], ...), self.func:format_right(state, operator_priority["_,_"], ...)) end, build_event_data = function(self, state, event_buffer) diff --git a/anselme/common/init.lua b/anselme/common/init.lua index fde5f2c..e375ff1 100644 --- a/anselme/common/init.lua +++ b/anselme/common/init.lua @@ -43,7 +43,7 @@ local common = { infixes = { { ";", 1 }, { "#", 2 }, { "->", 2 }, - { "|>", 5 }, { "&", 5 }, { "|", 5 }, + { "&", 5 }, { "|", 5 }, { "==", 6 }, { "!=", 6 }, { ">=", 6 }, { "<=", 6 }, { "<", 6 }, { ">", 6 }, { "+", 7 }, { "-", 7 }, { "//", 8 }, { "/", 8 }, { "*", 8 }, { "%", 8 }, diff --git a/anselme/parser/expression/primary/text.lua b/anselme/parser/expression/primary/text.lua index 8b753e8..5db5e81 100644 --- a/anselme/parser/expression/primary/text.lua +++ b/anselme/parser/expression/primary/text.lua @@ -14,12 +14,6 @@ return string { local start_source = source:clone() local interpolation, rem = string.parse(self, source, str, limit_pattern) - -- restore | when chaining with a choice operator - if rem:match("^>") then - rem = "|" .. rem - source:increment(-1) - end - -- remove terminal space local last = interpolation.list[#interpolation.list] if ast.String:is(last) then last.string = last.string:gsub("%s$", "") end diff --git a/anselme/parser/expression/secondary/infix/choice.lua b/anselme/parser/expression/secondary/infix/choice.lua deleted file mode 100644 index d2bf01b..0000000 --- a/anselme/parser/expression/secondary/infix/choice.lua +++ /dev/null @@ -1,17 +0,0 @@ -local infix = require("anselme.parser.expression.secondary.infix.infix") - -local operator_priority = require("anselme.common").operator_priority - -local ast = require("anselme.ast") -local Call, Identifier, ArgumentTuple, ParameterTuple, Function = ast.Call, ast.Identifier, ast.ArgumentTuple, ast.ParameterTuple, ast.Function - -return infix { - operator = "|>", - identifier = "_|>_", - priority = operator_priority["_|>_"], - - build_ast = function(self, left, right) - right = Function:new(ParameterTuple:new(), right) - return Call:new(Identifier:new(self.identifier), ArgumentTuple:new(left, right)) - end -} diff --git a/anselme/parser/expression/secondary/init.lua b/anselme/parser/expression/secondary/init.lua index c3cb5de..62e8127 100644 --- a/anselme/parser/expression/secondary/init.lua +++ b/anselme/parser/expression/secondary/init.lua @@ -10,7 +10,6 @@ local secondaries = { r("infix.tuple"), r("infix.tag"), r("infix.translate"), - r("infix.choice"), r("infix.and"), r("infix.or"), r("infix.equal"), diff --git a/anselme/stdlib/init.lua b/anselme/stdlib/init.lua index 16bd409..4157ddc 100644 --- a/anselme/stdlib/init.lua +++ b/anselme/stdlib/init.lua @@ -3,6 +3,11 @@ local parser = require("anselme.parser") local function define_lua(state, list) for _, fn in ipairs(list) do state.scope:define_lua("@"..fn[1], fn[2], fn[3], true) + if fn.alias then + for _, alias in ipairs(fn.alias) do + state.scope:define_lua("@"..alias, fn[2], fn[3], true) + end + end end end local function load(state, l) diff --git a/anselme/stdlib/language/frFR.lua b/anselme/stdlib/language/frFR.lua index 30c5064..4463953 100644 --- a/anselme/stdlib/language/frFR.lua +++ b/anselme/stdlib/language/frFR.lua @@ -79,4 +79,6 @@ return [[ :@fusionner branche = stdlib.merge branch :@persister = stdlib.persist + +:@écrire choix = stdlib.write choice ]] diff --git a/anselme/stdlib/text.lua b/anselme/stdlib/text.lua index f24599f..afc6044 100644 --- a/anselme/stdlib/text.lua +++ b/anselme/stdlib/text.lua @@ -31,7 +31,7 @@ return { -- choice { - "_|>_", "(txt::is text, fn)", + "write choice", "(text::is text, fn=attached block(keep return=true))", function(state, text, func) if func:contains_current_resume_target(state) then func:call(state, ArgumentTuple:new()) @@ -40,7 +40,8 @@ return { event_manager:write(state, Choice:new(text, func)) end return Nil:new() - end + end, + alias = { "*_" } }, -- translation diff --git a/test/tests/choice block.ans b/test/tests/choice block.ans index 8a5f0e9..c07d5d9 100644 --- a/test/tests/choice block.ans +++ b/test/tests/choice block.ans @@ -1,11 +1,11 @@ :@choice = 2 -| ye |> +*| ye | no -| ne |> +*| ne | ok choice = 1 -| ho |> +*| ho | plop -| oh |> +*| oh | plup diff --git a/test/tests/choice function.ans b/test/tests/choice function.ans index 1d2e4fb..56d4265 100644 --- a/test/tests/choice function.ans +++ b/test/tests/choice function.ans @@ -1,11 +1,11 @@ :$ f - | neol |> + *| neol | nah -| ho |> +*| ho |plop f! -| oh |> +*| oh |ok f! :@choice=3 \ No newline at end of file diff --git a/test/tests/choice line interpolation with choice event.ans b/test/tests/choice line interpolation with choice event.ans index 17c3587..e99783e 100644 --- a/test/tests/choice line interpolation with choice event.ans +++ b/test/tests/choice line interpolation with choice event.ans @@ -2,10 +2,11 @@ :$ jump button 1 # |A - | Suprise choice! |> () + *| Suprise choice! + () return("JOIN") -| Press {jump button!} to jump. |> +*| Press {jump button!} to jump. |ok -| No |> +*| No |ko diff --git a/test/tests/choice line interpolation with event flush.ans b/test/tests/choice line interpolation with event flush.ans index 456f777..de2b3b9 100644 --- a/test/tests/choice line interpolation with event flush.ans +++ b/test/tests/choice line interpolation with event flush.ans @@ -5,7 +5,7 @@ return("SPLIT") -| Press {jump button!} to jump. |> +*| Press {jump button!} to jump. | ok -| No |> +*| No | ko diff --git a/test/tests/choice line interpolation with text event.ans b/test/tests/choice line interpolation with text event.ans index 39ffe5c..95ef233 100644 --- a/test/tests/choice line interpolation with text event.ans +++ b/test/tests/choice line interpolation with text event.ans @@ -5,13 +5,13 @@ 1 # | left return(" joystick") -| Press {jump button!} to jump. |> +*| Press {jump button!} to jump. |ok -| No |> +*| No |ko :@choice = 1 -| Other |> +*| Other |ok -| Use {move axis!} to move. |> +*| Use {move axis!} to move. |ko diff --git a/test/tests/choice preserve tags.ans b/test/tests/choice preserve tags.ans index 0e97ace..c217bde 100644 --- a/test/tests/choice preserve tags.ans +++ b/test/tests/choice preserve tags.ans @@ -2,15 +2,17 @@ :$ f 42 # - | a |> + *| a | b f! -| c |> () +*| c + () "k":"v" # f! - | d |> () + *| d + () | e | f diff --git a/test/tests/choice simple.ans b/test/tests/choice simple.ans index a8790b9..8636d2c 100644 --- a/test/tests/choice simple.ans +++ b/test/tests/choice simple.ans @@ -1,5 +1,5 @@ -| ye |> +*| ye | no -| ne |> +*| ne | ok :@choice = 2 diff --git a/test/tests/choice text interleaved.ans b/test/tests/choice text interleaved.ans index 76bc753..ad79bba 100644 --- a/test/tests/choice text interleaved.ans +++ b/test/tests/choice text interleaved.ans @@ -1,14 +1,14 @@ :@choice = 1 :f = $_ - | a |> + *| a |-> a - | aa |> + *| aa |-> aa - | ab |> + *| ab |-> ab | x - | b |> + *| b |-> b f! \ No newline at end of file diff --git a/test/tests/choice with decorators.ans b/test/tests/choice with decorators.ans index bf5a286..0fe4e27 100644 --- a/test/tests/choice with decorators.ans +++ b/test/tests/choice with decorators.ans @@ -1,36 +1,36 @@ if(1) - | a |> + *| a | -> a -| b |> +*| b | -> b :@choice = 1 -if(1, $| a |> _) +if(1, $*| a) | -> a -| b |> +*| b | -> b choice = 2 -if((), $| a |> _) +if((), $*| a) | -> a -| b |> +*| b | -> b choice = 1 -| a |> +*| a | -> a -25 # | b |> +25 # *| b | -> b choice = 2 -12 # if((), $| a |> _) +12 # if((), $*| a) | -> a -3 # | b |> +3 # *| b | -> b choice = 1 -12 # if(1, $| a |> _) +12 # if(1, $*| a) | -> a -3 # | b |> +3 # *| b | -> b choice = 1 diff --git a/test/tests/flush.ans b/test/tests/flush.ans index cc8d131..8ae1483 100644 --- a/test/tests/flush.ans +++ b/test/tests/flush.ans @@ -1,7 +1,9 @@ :@choice = 1 | a -| b |> () +*| b + () | c -| d |> () +*| d + () diff --git a/test/tests/nested flush.ans b/test/tests/nested flush.ans index 9820bd8..b86ba80 100644 --- a/test/tests/nested flush.ans +++ b/test/tests/nested flush.ans @@ -10,9 +10,11 @@ if(1) if(1) |e -| f |> () +*| f + () :@choice = 1 if(1) |g -| h |> () +*| h + () diff --git a/test/tests/resume anchors.ans b/test/tests/resume anchors.ans index 8857583..3b3b161 100644 --- a/test/tests/resume anchors.ans +++ b/test/tests/resume anchors.ans @@ -10,7 +10,7 @@ :x = 8 ($_)!from(anchor) |a - | A |> + *| A | b c = #pouet g! @@ -18,7 +18,7 @@ _ | f | g - | B |> + *| B | boum |h {x} diff --git a/test/tests/resume from paragraph with nested choice 2.ans b/test/tests/resume from paragraph with nested choice 2.ans index 783873c..e09e09a 100644 --- a/test/tests/resume from paragraph with nested choice 2.ans +++ b/test/tests/resume from paragraph with nested choice 2.ans @@ -1,17 +1,17 @@ :@choice=1 :g = "g"!script($_) - | a |> + *| a |-> a #p!checkpoint - | aa |> + *| aa |-> aa - | ab |> + *| ab |-> ab - | b |> + *| b |-> b choice = 2 |autoflush - | c |> + *| c |-> c choice = 1 diff --git a/test/tests/resume from paragraph with nested choice 3.ans b/test/tests/resume from paragraph with nested choice 3.ans index 9f7e9dd..761a249 100644 --- a/test/tests/resume from paragraph with nested choice 3.ans +++ b/test/tests/resume from paragraph with nested choice 3.ans @@ -1,17 +1,17 @@ :@choice = 1 :h = "h"!script($_) if(1) - | a |> + *| a |-> a #p!checkpoint - | aa |> + *| aa |-> aa - | ab |> + *| ab |-> ab choice = 1 - | b |> + *| b |-> b - | c |> + *| c |-> c choice = 1 diff --git a/test/tests/resume from paragraph with nested choice 4.ans b/test/tests/resume from paragraph with nested choice 4.ans index bda2426..bdab8ca 100644 --- a/test/tests/resume from paragraph with nested choice 4.ans +++ b/test/tests/resume from paragraph with nested choice 4.ans @@ -1,16 +1,16 @@ :@choice = 1 :i = "i"!script($_) - | a |> + *| a |-> a #p!checkpoint - | aa |> + *| aa |-> aa - | ab |> + *| ab |-> ab - | b |> + *| b |-> b if(1) - | c |> + *| c |-> c | i: diff --git a/test/tests/resume from paragraph with nested choice.ans b/test/tests/resume from paragraph with nested choice.ans index 841c908..edefab3 100644 --- a/test/tests/resume from paragraph with nested choice.ans +++ b/test/tests/resume from paragraph with nested choice.ans @@ -1,18 +1,18 @@ :@choice = 2 :f = "f"!script($_) - | a |> + *| a |-> a #p!checkpoint - | aa |> + *| aa |-> aa - | ab |> + *| ab |-> ab - | b |> + *| b |-> b choice = 2 - | c |> + *| c |-> c choice=1 diff --git a/test/tests/return in choice.ans b/test/tests/return in choice.ans index cf95753..6f3dc98 100644 --- a/test/tests/return in choice.ans +++ b/test/tests/return in choice.ans @@ -1,5 +1,5 @@ :$ f - | a |> + *| a | x return(1) | y diff --git a/test/tests/text line interpolation with choice event.ans b/test/tests/text line interpolation with choice event.ans index b8ab7c9..66a8b92 100644 --- a/test/tests/text line interpolation with choice event.ans +++ b/test/tests/text line interpolation with choice event.ans @@ -2,12 +2,12 @@ :$ jump button 1 # | A - | Surprise choice! |> + *| Surprise choice! | ok :$ move axis 1 # | left - | Surprise choice! |> + *| Surprise choice! | ok2 return(" joystick")