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

[language] Remove _|>_ operator, replace with *_

This commit is contained in:
Étienne Fildadut 2024-01-09 17:57:13 +01:00
parent 51eff0627f
commit 87afa51baa
26 changed files with 86 additions and 98 deletions

View file

@ -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)

View file

@ -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 },

View file

@ -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

View file

@ -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
}

View file

@ -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"),

View file

@ -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)

View file

@ -79,4 +79,6 @@ return [[
:@fusionner branche = stdlib.merge branch
:@persister = stdlib.persist
:@écrire choix = stdlib.write choice
]]

View file

@ -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

View file

@ -1,11 +1,11 @@
:@choice = 2
| ye |>
*| ye
| no
| ne |>
*| ne
| ok
choice = 1
| ho |>
*| ho
| plop
| oh |>
*| oh
| plup

View file

@ -1,11 +1,11 @@
:$ f
| neol |>
*| neol
| nah
| ho |>
*| ho
|plop
f!
| oh |>
*| oh
|ok
f!
:@choice=3

View file

@ -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

View file

@ -5,7 +5,7 @@
return("SPLIT")
| Press {jump button!} to jump. |>
*| Press {jump button!} to jump.
| ok
| No |>
*| No
| ko

View file

@ -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

View file

@ -2,15 +2,17 @@
:$ f
42 #
| a |>
*| a
| b
f!
| c |> ()
*| c
()
"k":"v" #
f!
| d |> ()
*| d
()
| e
| f

View file

@ -1,5 +1,5 @@
| ye |>
*| ye
| no
| ne |>
*| ne
| ok
:@choice = 2

View file

@ -1,14 +1,14 @@
:@choice = 1
:f = $_
| a |>
*| a
|-> a
| aa |>
*| aa
|-> aa
| ab |>
*| ab
|-> ab
| x
| b |>
*| b
|-> b
f!

View file

@ -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

View file

@ -1,7 +1,9 @@
:@choice = 1
| a
| b |> ()
*| b
()
| c
| d |> ()
*| d
()

View file

@ -10,9 +10,11 @@ if(1)
if(1)
|e
| f |> ()
*| f
()
:@choice = 1
if(1)
|g
| h |> ()
*| h
()

View file

@ -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}

View file

@ -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

View file

@ -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

View file

@ -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:

View file

@ -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

View file

@ -1,5 +1,5 @@
:$ f
| a |>
*| a
| x
return(1)
| y

View file

@ -2,12 +2,12 @@
:$ jump button
1 # | A
| Surprise choice! |>
*| Surprise choice!
| ok
:$ move axis
1 # | left
| Surprise choice! |>
*| Surprise choice!
| ok2
return(" joystick")