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, ...)
|
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)
|
||||||
|
|
|
||||||
|
|
@ -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 },
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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.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"),
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
]]
|
]]
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
return("SPLIT")
|
return("SPLIT")
|
||||||
|
|
||||||
| Press {jump button!} to jump. |>
|
*| Press {jump button!} to jump.
|
||||||
| ok
|
| ok
|
||||||
| No |>
|
*| No
|
||||||
| ko
|
| ko
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
| ye |>
|
*| ye
|
||||||
| no
|
| no
|
||||||
| ne |>
|
*| ne
|
||||||
| ok
|
| ok
|
||||||
:@choice = 2
|
:@choice = 2
|
||||||
|
|
|
||||||
|
|
@ -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!
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
:@choice = 1
|
:@choice = 1
|
||||||
| a
|
| a
|
||||||
|
|
||||||
| b |> ()
|
*| b
|
||||||
|
()
|
||||||
|
|
||||||
| c
|
| c
|
||||||
| d |> ()
|
*| d
|
||||||
|
()
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
()
|
||||||
|
|
|
||||||
|
|
@ -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}
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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:
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
:$ f
|
:$ f
|
||||||
| a |>
|
*| a
|
||||||
| x
|
| x
|
||||||
return(1)
|
return(1)
|
||||||
| y
|
| y
|
||||||
|
|
|
||||||
|
|
@ -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")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue