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

Add while loop line and operator

This commit is contained in:
Étienne Fildadut 2021-12-12 17:07:50 +01:00
parent f5382d2912
commit 48cabbf4c0
14 changed files with 500 additions and 61 deletions

View file

@ -31,7 +31,7 @@ common = {
-- operators not included here and why:
-- * assignment operators (:=, +=, -=, //=, /=, *=, %=, ^=): handled with its own syntax (function assignment)
-- * list operator (,): is used when calling every functions, sounds like more trouble than it's worth
-- * |, & and ~ operators: are lazy and don't behave like regular functions
-- * |, &, ~? and ~ operators: are lazy and don't behave like regular functions
-- * # operator: need to set tag state _before_ evaluating the left arg
-- prefix unop

View file

@ -5,7 +5,7 @@ local binops_prio = {
[1] = { ";" },
[2] = { ":=", "+=", "-=", "//=", "/=", "*=", "%=", "^=" },
[3] = { "," },
[4] = { "|", "&", "~", "#" },
[4] = { "|", "&", "~?", "~", "#" },
[5] = { "!=", "==", ">=", "<=", "<", ">" },
[6] = { "+", "-" },
[7] = { "*", "//", "/", "%" },
@ -336,7 +336,7 @@ local function expression(s, state, namespace, current_priority, operating_on)
left = operating_on,
right = right
})
elseif op == "&" or op == "|" or op == "~" or op == "#" then
elseif op == "&" or op == "|" or op == "~?" or op == "~" or op == "#" then
return expression(r, state, namespace, current_priority, {
type = op,
left = operating_on,

View file

@ -29,11 +29,17 @@ local function parse_line(line, state, namespace)
local r = {
source = line.source
}
-- else-condition & condition
if l:match("^~~?") then
r.type = l:match("^~~") and "else-condition" or "condition"
-- else-condition, condition & while
if l:match("^~[~%?]?") then
if l:match("^~~") then
r.type = "else-condition"
elseif l:match("^~%?") then
r.type = "while"
else
r.type = "condition"
end
r.child = true
local expr = l:match("^~~?(.*)$")
local expr = l:match("^~[~%?]?(.*)$")
if expr:match("[^%s]") then
r.expression = expr
else