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

Condition line -> expression line

This commit is contained in:
Étienne Fildadut 2021-04-08 13:21:47 +02:00
parent e1b0b17fc6
commit eb6da84878
2 changed files with 6 additions and 6 deletions

View file

@ -137,9 +137,9 @@ There's different types of lines, depending on their first character(s) (after i
here here
``` ```
* `~`: condition line. Can be followed by an [expression](#expressions); otherwise the expression `1` is assumed. If the expression evaluates to [true](#truethness), run its children. * `~`: expression line. Can be followed by an [expression](#expressions); otherwise the expression `1` is assumed. If the expression evaluates to [true](#truethness), run its children.
* `~~`: else condition. Same as a condition line, but is only run if the last condition or else-condition line failed (regardless of line distance). * `~~`: else expression. Same as an expression line, but is only run if the last expression or else-expression line was false (regardless of line distance).
``` ```
~ 1 ~ 1
@ -279,7 +279,7 @@ And this is more text, in a different event.
Every line can also be followed with decorators, which are appended at the end of the line and affect its behaviour. Every line can also be followed with decorators, which are appended at the end of the line and affect its behaviour.
* `~`: condition decorator. Same as a condition line, behaving as if this line was it sole child. * `~`: expression decorator. Same as an expression line, behaving as if this line was it sole child. Typically used to conditionally execute line.
* `§`: paragraph decorator. Same as a paragraph line, behaving as if this line was it sole child. * `§`: paragraph decorator. Same as a paragraph line, behaving as if this line was it sole child.
@ -345,7 +345,7 @@ Every event have a type (`text`, `choice`, `return` or `error` by default, custo
### Identifiers ### Identifiers
Valid identifiers must be at least 1 caracters long and can contain anything except the caracters `%/*+-()!&|=$?><:{}[],\`. They can contain spaces. Valid identifiers must be at least 1 caracters long and can contain anything except the caracters `%/*+-()!&|=$§?><:{}[],\`. They can contain spaces.
When defining an identifier (using a function, paragraph or variable delcaration line), it will be defined into the current namespace (defined by the parent function/paragraph). When evaluating an expression, Anselme will look for variables into the current line's namespace, then go up a level if it isn't found, and so on. When defining an identifier (using a function, paragraph or variable delcaration line), it will be defined into the current namespace (defined by the parent function/paragraph). When evaluating an expression, Anselme will look for variables into the current line's namespace, then go up a level if it isn't found, and so on.

View file

@ -5,7 +5,7 @@ local escapeCache = {}
local common local common
common = { common = {
--- valid identifier pattern --- valid identifier pattern
identifier_pattern = "[^%%%/%*%+%-%(%)%!%&%|%=%$%?%>%<%:%{%}%[%]%,%\"]+", identifier_pattern = "[^%%%/%*%+%-%(%)%!%&%|%=%$%§%?%>%<%:%{%}%[%]%,%\"]+",
--- escape a string to be used as an exact match pattern --- escape a string to be used as an exact match pattern
escape = function(str) escape = function(str)
if not escapeCache[str] then if not escapeCache[str] then
@ -39,7 +39,7 @@ common = {
end end
return nil, ("can't find %q in namespace %s"):format(name, namespace) return nil, ("can't find %q in namespace %s"):format(name, namespace)
end, end,
--- transform an identifier into a clean version --- transform an identifier into a clean version (trim & alias)
format_identifier = function(identifier, state) format_identifier = function(identifier, state)
local r = identifier:gsub("[^%.]+", function(str) local r = identifier:gsub("[^%.]+", function(str)
str = common.trim(str) str = common.trim(str)