Update docs
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
42649e3160
commit
0d3f2a359d
|
@ -14,8 +14,8 @@ The values of input data are according to the pack config.
|
|||
String literals may be written with quotation marks as follows: `"some text"` or `'some text'`
|
||||
Numbers may be written as follows: `103` or `10.15`
|
||||
Booleans may be written either as `true` or `false`
|
||||
Objects, lists and functions cannot be created manually but may be provided to the script as parameters or from
|
||||
functions.
|
||||
You can find more information about the syntax for functions below.
|
||||
Objects and lists cannot be created manually but may be provided to the script as parameters or from functions.
|
||||
Additionally, function parameters will automatically be packed in a list
|
||||
|
||||
Please ensure you use proper whitespace, as this might behave unexpectedly otherwise.
|
||||
|
@ -58,18 +58,28 @@ Objects support the following operators (x is an object with an entry called `en
|
|||
- Value access via `.`: `x.entry`
|
||||
- Value access via square brackets: `x["entry"]` (also supports other types)
|
||||
|
||||
Parentheses (`()`) may be used to indicate order of operation
|
||||
Parentheses (`()`) may be used to indicate order of operation.
|
||||
|
||||
Namespacing is done using double colons like in c++ (`namespace::value`), though it should not be used
|
||||
## Closures (functions)
|
||||
One may define a closure as follows: `{list, of, arguments -> body}`.
|
||||
The body of a closure may contain multiple expressions, which can be (but don't have to be) seperated by semicolons.
|
||||
In that case, the return value of the last expression will be the return value of the closure.
|
||||
The arrow (`->`) must always be present, even if the closure takes no arguments.
|
||||
The amount of arguments is checked at runtime, so the amount used to call the function MUST be correct.
|
||||
In closures (or multi-expression scripts for that matter), you may assign variables as follows: `name = value`.
|
||||
Please note that you cannot assign values to fields of objects.
|
||||
You may also assign a closure to a variable to use it like a named function.
|
||||
This could look as follows: `someFunction = {arg -> arg * arg}`
|
||||
Please also be aware that μScript does NOT allow you to modify variables of outer scopes from inner scopes.
|
||||
|
||||
## Embedding μScript
|
||||
|
||||
μScript is available as a [maven package](https://gitlab.com/JFronny/java-commons/-/packages) which you can add to your
|
||||
μScript is available as a [maven package](https://maven.frohnmeyer-wds.de/#/artifacts/io/gitlab/jfronny/muscript) which you can add to your
|
||||
project.
|
||||
To use it, first parse a script via `Parser.parse(String script)` and convert the returned generic expression to a typed
|
||||
one
|
||||
by calling `as(Bool|String|Number|Dynamic)Expr`.
|
||||
To use it, first parse an expression via `Parser.parse(String script)` and convert the returned generic expression to a typed
|
||||
one by calling `as(Bool|String|Number|Dynamic)Expr`.
|
||||
This process may throw a ParseException.
|
||||
You may also use `Parser.parseScript(String script)` for multi-expression scripts.
|
||||
You can call `get(Dynamic<?> dataRoot)` on the result to execute the script on the provided data, which should be an
|
||||
`Scope` on which you called `StandardLib.addTo()` to add standard methods.
|
||||
This is also where you can add custom data to be accessed by your script.
|
||||
|
|
|
@ -10,7 +10,6 @@ import io.gitlab.jfronny.muscript.ast.string.Concatenate;
|
|||
import io.gitlab.jfronny.muscript.data.Script;
|
||||
import io.gitlab.jfronny.muscript.error.*;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.*;
|
||||
|
||||
public class Parser {
|
||||
|
|
Loading…
Reference in New Issue