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, ...) fn(self.func, ...)
end, end,
_format = function(self, ...) _format = function(self, state, prio, ...)
return ("%s |> %s"):format(self.text:format(...), self.func:format_right(...)) return ("write choice(%s, %s)"):format(self.text:format(state, operator_priority["_,_"], ...), self.func:format_right(state, operator_priority["_,_"], ...))
end,
_format_priority = function(self)
return operator_priority["_|>_"]
end, end,
build_event_data = function(self, state, event_buffer) build_event_data = function(self, state, event_buffer)

View file

@ -43,7 +43,7 @@ local common = {
infixes = { infixes = {
{ ";", 1 }, { ";", 1 },
{ "#", 2 }, { "->", 2 }, { "#", 2 }, { "->", 2 },
{ "|>", 5 }, { "&", 5 }, { "|", 5 }, { "&", 5 }, { "|", 5 },
{ "==", 6 }, { "!=", 6 }, { ">=", 6 }, { "<=", 6 }, { "<", 6 }, { ">", 6 }, { "==", 6 }, { "!=", 6 }, { ">=", 6 }, { "<=", 6 }, { "<", 6 }, { ">", 6 },
{ "+", 7 }, { "-", 7 }, { "+", 7 }, { "-", 7 },
{ "//", 8 }, { "/", 8 }, { "*", 8 }, { "%", 8 }, { "//", 8 }, { "/", 8 }, { "*", 8 }, { "%", 8 },

View file

@ -14,12 +14,6 @@ return string {
local start_source = source:clone() local start_source = source:clone()
local interpolation, rem = string.parse(self, source, str, limit_pattern) 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 -- remove terminal space
local last = interpolation.list[#interpolation.list] local last = interpolation.list[#interpolation.list]
if ast.String:is(last) then last.string = last.string:gsub("%s$", "") end 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.tuple"),
r("infix.tag"), r("infix.tag"),
r("infix.translate"), r("infix.translate"),
r("infix.choice"),
r("infix.and"), r("infix.and"),
r("infix.or"), r("infix.or"),
r("infix.equal"), r("infix.equal"),

View file

@ -3,6 +3,11 @@ local parser = require("anselme.parser")
local function define_lua(state, list) local function define_lua(state, list)
for _, fn in ipairs(list) do for _, fn in ipairs(list) do
state.scope:define_lua("@"..fn[1], fn[2], fn[3], true) 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
end end
local function load(state, l) local function load(state, l)

View file

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

View file

@ -31,7 +31,7 @@ return {
-- choice -- choice
{ {
"_|>_", "(txt::is text, fn)", "write choice", "(text::is text, fn=attached block(keep return=true))",
function(state, text, func) function(state, text, func)
if func:contains_current_resume_target(state) then if func:contains_current_resume_target(state) then
func:call(state, ArgumentTuple:new()) func:call(state, ArgumentTuple:new())
@ -40,7 +40,8 @@ return {
event_manager:write(state, Choice:new(text, func)) event_manager:write(state, Choice:new(text, func))
end end
return Nil:new() return Nil:new()
end end,
alias = { "*_" }
}, },
-- translation -- translation

View file

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

View file

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

View file

@ -2,10 +2,11 @@
:$ jump button :$ jump button
1 # |A 1 # |A
| Suprise choice! |> () *| Suprise choice!
()
return("JOIN") return("JOIN")
| Press {jump button!} to jump. |> *| Press {jump button!} to jump.
|ok |ok
| No |> *| No
|ko |ko

View file

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

View file

@ -5,13 +5,13 @@
1 # | left 1 # | left
return(" joystick") return(" joystick")
| Press {jump button!} to jump. |> *| Press {jump button!} to jump.
|ok |ok
| No |> *| No
|ko |ko
:@choice = 1 :@choice = 1
| Other |> *| Other
|ok |ok
| Use {move axis!} to move. |> *| Use {move axis!} to move.
|ko |ko

View file

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

View file

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

View file

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

View file

@ -1,36 +1,36 @@
if(1) if(1)
| a |> *| a
| -> a | -> a
| b |> *| b
| -> b | -> b
:@choice = 1 :@choice = 1
if(1, $| a |> _) if(1, $*| a)
| -> a | -> a
| b |> *| b
| -> b | -> b
choice = 2 choice = 2
if((), $| a |> _) if((), $*| a)
| -> a | -> a
| b |> *| b
| -> b | -> b
choice = 1 choice = 1
| a |> *| a
| -> a | -> a
25 # | b |> 25 # *| b
| -> b | -> b
choice = 2 choice = 2
12 # if((), $| a |> _) 12 # if((), $*| a)
| -> a | -> a
3 # | b |> 3 # *| b
| -> b | -> b
choice = 1 choice = 1
12 # if(1, $| a |> _) 12 # if(1, $*| a)
| -> a | -> a
3 # | b |> 3 # *| b
| -> b | -> b
choice = 1 choice = 1

View file

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

View file

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

View file

@ -10,7 +10,7 @@
:x = 8 :x = 8
($_)!from(anchor) ($_)!from(anchor)
|a |a
| A |> *| A
| b | b
c = #pouet c = #pouet
g! g!
@ -18,7 +18,7 @@
_ _
| f | f
| g | g
| B |> *| B
| boum | boum
|h {x} |h {x}

View file

@ -1,17 +1,17 @@
:@choice=1 :@choice=1
:g = "g"!script($_) :g = "g"!script($_)
| a |> *| a
|-> a |-> a
#p!checkpoint #p!checkpoint
| aa |> *| aa
|-> aa |-> aa
| ab |> *| ab
|-> ab |-> ab
| b |> *| b
|-> b |-> b
choice = 2 choice = 2
|autoflush |autoflush
| c |> *| c
|-> c |-> c
choice = 1 choice = 1

View file

@ -1,17 +1,17 @@
:@choice = 1 :@choice = 1
:h = "h"!script($_) :h = "h"!script($_)
if(1) if(1)
| a |> *| a
|-> a |-> a
#p!checkpoint #p!checkpoint
| aa |> *| aa
|-> aa |-> aa
| ab |> *| ab
|-> ab |-> ab
choice = 1 choice = 1
| b |> *| b
|-> b |-> b
| c |> *| c
|-> c |-> c
choice = 1 choice = 1

View file

@ -1,16 +1,16 @@
:@choice = 1 :@choice = 1
:i = "i"!script($_) :i = "i"!script($_)
| a |> *| a
|-> a |-> a
#p!checkpoint #p!checkpoint
| aa |> *| aa
|-> aa |-> aa
| ab |> *| ab
|-> ab |-> ab
| b |> *| b
|-> b |-> b
if(1) if(1)
| c |> *| c
|-> c |-> c
| i: | i:

View file

@ -1,18 +1,18 @@
:@choice = 2 :@choice = 2
:f = "f"!script($_) :f = "f"!script($_)
| a |> *| a
|-> a |-> a
#p!checkpoint #p!checkpoint
| aa |> *| aa
|-> aa |-> aa
| ab |> *| ab
|-> ab |-> ab
| b |> *| b
|-> b |-> b
choice = 2 choice = 2
| c |> *| c
|-> c |-> c
choice=1 choice=1

View file

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

View file

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