mirror of
https://github.com/Reuh/anselme.git
synced 2025-10-28 09:09:31 +00:00
Update documentation
This commit is contained in:
parent
dfe838a769
commit
fdcea38e5e
4 changed files with 105 additions and 2 deletions
21
LANGUAGE.md
21
LANGUAGE.md
|
|
@ -624,6 +624,25 @@ These can be used to represent some caracters in string and other text elements
|
||||||
|
|
||||||
Only `0` and `nil` are false. Everything else is considered true.
|
Only `0` and `nil` are false. Everything else is considered true.
|
||||||
|
|
||||||
|
#### Refering to an identifier
|
||||||
|
|
||||||
|
Any defined identifier can be accessed from an expression by using its name; the identifier will be first searched in the current namespace, then go up until it finds it as described in [identifiers](#identifiers).
|
||||||
|
|
||||||
|
What will happen then depends on what the identifier refer to: see [function calls](#function-calls) for functions and [checkpoint calls](#checkpoint-calls) for checkpoints.
|
||||||
|
|
||||||
|
For variables, the identifier will returns the value of the variable when evaluated.
|
||||||
|
|
||||||
|
When the identifier is preceeded by another expression directly (without any operator between the two), Anselme consider this to be an implicit multiplication. This behave in the same way as if there was a `*` operator between the expression and identifier, but has a priority just higher than explicit multiplication.
|
||||||
|
|
||||||
|
```
|
||||||
|
:x = 3
|
||||||
|
|
||||||
|
{2x} = {2*x} = 6
|
||||||
|
|
||||||
|
(Priority is made slighly higher to avoid parentheses in this kind of operation:)
|
||||||
|
{1/2x} = {1/(2*x)} = 1/6
|
||||||
|
```
|
||||||
|
|
||||||
#### Function calls
|
#### Function calls
|
||||||
|
|
||||||
The simplest way to call a function is simply to use its name. If the function has no arguments, parantheses are optional, or can be replaced with a `!`:
|
The simplest way to call a function is simply to use its name. If the function has no arguments, parantheses are optional, or can be replaced with a `!`:
|
||||||
|
|
@ -959,6 +978,8 @@ This only works on strings:
|
||||||
|
|
||||||
Variables for default types (each is associated to a string of the internal variable type name): `nil`, `number`, `string`, `list`, `pair`, `function reference`, `variable reference`.
|
Variables for default types (each is associated to a string of the internal variable type name): `nil`, `number`, `string`, `list`, `pair`, `function reference`, `variable reference`.
|
||||||
|
|
||||||
|
The π constant is also defined in `pi`.
|
||||||
|
|
||||||
#### Built-in language scripts
|
#### Built-in language scripts
|
||||||
|
|
||||||
Anselme provides some scripts that define translated aliases for built-in variables and functions. Currently `enUS` (English) and `frFR` (French) are provided.
|
Anselme provides some scripts that define translated aliases for built-in variables and functions. Currently `enUS` (English) and `frFR` (French) are provided.
|
||||||
|
|
|
||||||
|
|
@ -488,7 +488,7 @@ local vm_mt = {
|
||||||
-- expr: expression to evaluate (string or parsed expression), or a block to run
|
-- expr: expression to evaluate (string or parsed expression), or a block to run
|
||||||
-- will merge state after successful execution
|
-- will merge state after successful execution
|
||||||
-- namespace(default=""): namespace to evaluate the expression in
|
-- namespace(default=""): namespace to evaluate the expression in
|
||||||
-- tags(default={}): defaults tag when evaluating the expression
|
-- tags(default={}): defaults tags when evaluating the expression (Lua value)
|
||||||
-- return interpreter in case of success
|
-- return interpreter in case of success
|
||||||
-- returns nil, err in case of error
|
-- returns nil, err in case of error
|
||||||
run = function(self, expr, namespace, tags)
|
run = function(self, expr, namespace, tags)
|
||||||
|
|
@ -555,7 +555,7 @@ local vm_mt = {
|
||||||
-- merge state after sucessful execution automatically like :run
|
-- merge state after sucessful execution automatically like :run
|
||||||
-- expr: expression to evaluate (string or parsed expression), or a block to evaluate
|
-- expr: expression to evaluate (string or parsed expression), or a block to evaluate
|
||||||
-- namespace(default=""): namespace to evaluate the expression in
|
-- namespace(default=""): namespace to evaluate the expression in
|
||||||
-- tags(default={}): defaults tag when evaluating the expression
|
-- tags(default={}): defaults tags when evaluating the expression (Lua value)
|
||||||
-- return value in case of success (nil if nothing returned)
|
-- return value in case of success (nil if nothing returned)
|
||||||
-- returns nil, err in case of error
|
-- returns nil, err in case of error
|
||||||
eval = function(self, expr, namespace, tags)
|
eval = function(self, expr, namespace, tags)
|
||||||
|
|
|
||||||
11
test/tests/implicit multiplication.ans
Normal file
11
test/tests/implicit multiplication.ans
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
:x = 4
|
||||||
|
|
||||||
|
{2x} = 8
|
||||||
|
|
||||||
|
{(2+1)x} = 12
|
||||||
|
|
||||||
|
{2pi} = 2pi
|
||||||
|
|
||||||
|
{1/2x} = 0.125
|
||||||
|
|
||||||
|
{(1/2)x} = 2
|
||||||
71
test/tests/implicit multiplication.lua
Normal file
71
test/tests/implicit multiplication.lua
Normal file
|
|
@ -0,0 +1,71 @@
|
||||||
|
local _={}
|
||||||
|
_[31]={}
|
||||||
|
_[30]={}
|
||||||
|
_[29]={}
|
||||||
|
_[28]={}
|
||||||
|
_[27]={}
|
||||||
|
_[26]={}
|
||||||
|
_[25]={}
|
||||||
|
_[24]={}
|
||||||
|
_[23]={}
|
||||||
|
_[22]={}
|
||||||
|
_[21]={text=" = 2",tags=_[31]}
|
||||||
|
_[20]={text="2.0",tags=_[30]}
|
||||||
|
_[19]={text=" = 0.125",tags=_[29]}
|
||||||
|
_[18]={text="0.125",tags=_[28]}
|
||||||
|
_[17]={text=" = 2pi",tags=_[27]}
|
||||||
|
_[16]={text="6.2831853071796",tags=_[26]}
|
||||||
|
_[15]={text=" = 12",tags=_[25]}
|
||||||
|
_[14]={text="12",tags=_[24]}
|
||||||
|
_[13]={text=" = 8",tags=_[23]}
|
||||||
|
_[12]={text="8",tags=_[22]}
|
||||||
|
_[11]={_[20],_[21]}
|
||||||
|
_[10]={_[18],_[19]}
|
||||||
|
_[9]={_[16],_[17]}
|
||||||
|
_[8]={_[14],_[15]}
|
||||||
|
_[7]={_[12],_[13]}
|
||||||
|
_[6]={"return"}
|
||||||
|
_[5]={"text",_[11]}
|
||||||
|
_[4]={"text",_[10]}
|
||||||
|
_[3]={"text",_[9]}
|
||||||
|
_[2]={"text",_[8]}
|
||||||
|
_[1]={"text",_[7]}
|
||||||
|
return {_[1],_[2],_[3],_[4],_[5],_[6]}
|
||||||
|
--[[
|
||||||
|
{ "text", { {
|
||||||
|
tags = {},
|
||||||
|
text = "8"
|
||||||
|
}, {
|
||||||
|
tags = {},
|
||||||
|
text = " = 8"
|
||||||
|
} } }
|
||||||
|
{ "text", { {
|
||||||
|
tags = {},
|
||||||
|
text = "12"
|
||||||
|
}, {
|
||||||
|
tags = {},
|
||||||
|
text = " = 12"
|
||||||
|
} } }
|
||||||
|
{ "text", { {
|
||||||
|
tags = {},
|
||||||
|
text = "6.2831853071796"
|
||||||
|
}, {
|
||||||
|
tags = {},
|
||||||
|
text = " = 2pi"
|
||||||
|
} } }
|
||||||
|
{ "text", { {
|
||||||
|
tags = {},
|
||||||
|
text = "0.125"
|
||||||
|
}, {
|
||||||
|
tags = {},
|
||||||
|
text = " = 0.125"
|
||||||
|
} } }
|
||||||
|
{ "text", { {
|
||||||
|
tags = {},
|
||||||
|
text = "2.0"
|
||||||
|
}, {
|
||||||
|
tags = {},
|
||||||
|
text = " = 2"
|
||||||
|
} } }
|
||||||
|
{ "return" }
|
||||||
|
]]--
|
||||||
Loading…
Add table
Add a link
Reference in a new issue