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:
parent
51eff0627f
commit
87afa51baa
26 changed files with 86 additions and 98 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 },
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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"),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -79,4 +79,6 @@ return [[
|
|||
|
||||
:@fusionner branche = stdlib.merge branch
|
||||
:@persister = stdlib.persist
|
||||
|
||||
:@écrire choix = stdlib.write choice
|
||||
]]
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
:@choice = 2
|
||||
| ye |>
|
||||
*| ye
|
||||
| no
|
||||
| ne |>
|
||||
*| ne
|
||||
| ok
|
||||
|
||||
choice = 1
|
||||
| ho |>
|
||||
*| ho
|
||||
| plop
|
||||
| oh |>
|
||||
*| oh
|
||||
| plup
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
:$ f
|
||||
| neol |>
|
||||
*| neol
|
||||
| nah
|
||||
|
||||
| ho |>
|
||||
*| ho
|
||||
|plop
|
||||
f!
|
||||
| oh |>
|
||||
*| oh
|
||||
|ok
|
||||
f!
|
||||
:@choice=3
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
return("SPLIT")
|
||||
|
||||
| Press {jump button!} to jump. |>
|
||||
*| Press {jump button!} to jump.
|
||||
| ok
|
||||
| No |>
|
||||
*| No
|
||||
| ko
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -2,15 +2,17 @@
|
|||
|
||||
:$ f
|
||||
42 #
|
||||
| a |>
|
||||
*| a
|
||||
| b
|
||||
|
||||
f!
|
||||
| c |> ()
|
||||
*| c
|
||||
()
|
||||
|
||||
"k":"v" #
|
||||
f!
|
||||
| d |> ()
|
||||
*| d
|
||||
()
|
||||
| e
|
||||
|
||||
| f
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
| ye |>
|
||||
*| ye
|
||||
| no
|
||||
| ne |>
|
||||
*| ne
|
||||
| ok
|
||||
:@choice = 2
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
:@choice = 1
|
||||
|
||||
:f = $_
|
||||
| a |>
|
||||
*| a
|
||||
|-> a
|
||||
| aa |>
|
||||
*| aa
|
||||
|-> aa
|
||||
| ab |>
|
||||
*| ab
|
||||
|-> ab
|
||||
| x
|
||||
| b |>
|
||||
*| b
|
||||
|-> b
|
||||
|
||||
f!
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
:@choice = 1
|
||||
| a
|
||||
|
||||
| b |> ()
|
||||
*| b
|
||||
()
|
||||
|
||||
| c
|
||||
| d |> ()
|
||||
*| d
|
||||
()
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@ if(1)
|
|||
if(1)
|
||||
|e
|
||||
|
||||
| f |> ()
|
||||
*| f
|
||||
()
|
||||
:@choice = 1
|
||||
|
||||
if(1)
|
||||
|g
|
||||
| h |> ()
|
||||
*| h
|
||||
()
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
:$ f
|
||||
| a |>
|
||||
*| a
|
||||
| x
|
||||
return(1)
|
||||
| y
|
||||
|
|
|
|||
|
|
@ -2,12 +2,12 @@
|
|||
|
||||
:$ jump button
|
||||
1 # | A
|
||||
| Surprise choice! |>
|
||||
*| Surprise choice!
|
||||
| ok
|
||||
|
||||
:$ move axis
|
||||
1 # | left
|
||||
| Surprise choice! |>
|
||||
*| Surprise choice!
|
||||
| ok2
|
||||
return(" joystick")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue