diff --git a/doc/Expr.adoc b/doc/Expr.adoc index b7824b8..f1c085b 100644 --- a/doc/Expr.adoc +++ b/doc/Expr.adoc @@ -203,19 +203,16 @@ The items of strings can be accessed using the dot `.` operator. ---- .String examples -[source,go] ----- -`>>>` [blue]`s="abc"` [gray]`// assign the string to variable s` -[geen]`abc` -`>>>` [blue]`s.1` [gray]`// char at position 1 (starting from 0) -[blue]`b` -`>>>` [blue]`s.(-1)` [gray]`// char at position -1, the rightmost one -[blue]`c` -`>>>` [blue]`#s` [gray]`// number of chars -[blue]3` -`>>>` [blue]`#"abc"` [gray]`// number of chars -[blue]3` ----- +`>>>` [blue]`s="abc"` [gray]_assign the string to variable s_ + +[green]`abc` + +`>>>` [blue]`s.1` [gray]_char at position 1 (starting from 0)_ + +[green]`b` + +`>>>` [blue]`s.(-1)` [gray]_char at position -1, the rightmost one_ + +[green]`c` + +`>>>` [blue]`\#s` [gray]_number of chars_ + +[gren]`3` + +`>>>` [blue]`#"abc"` [gray]_number of chars_ + +[green]`3` + === Boolean Boolean data type has two values only: _true_ and _false_. Relational and Boolean expressions produce Boolean values. @@ -300,32 +297,27 @@ The items of array can be accessed using the dot `.` operator. ---- .Items of list -[source,go] ----- -`>>>` [blue]`[1,2,3].1` -[green]`2` -`>>>` [blue]`list=[1,2,3]; list.1` -[green]`2` -`>>>` [blue]`["one","two","three"].1` -[green]`two` -`>>>` [blue]`list=["one","two","three"]; list.(2-1)` -[green]`two` -`>>>` [blue]`list.(-1)` -[green]`three` -`>>>` [blue]`list.(-1)` -[green]`three` -`>>>` [blue]`list.(10)` -[red]`Eval Error: [1:9] index 10 out of bounds` -`>>>` [blue]`#list` +`>>>` [blue]`[1,2,3].1` + +[green]`2` + +`>>>` [blue]`list=[1,2,3]; list.1` + +[green]`2` + +`>>>` [blue]`["one","two","three"].1` + +[green]`two` + +`>>>` [blue]`list=["one","two","three"]; list.(2-1)` + +[green]`two` + +`>>>` [blue]`list.(-1)` + +[green]`three` + +`>>>` [blue]`list.(10)` + +[red]`Eval Error: [1:9] index 10 out of bounds` + +`>>>` [blue]`#list` + [green]`3` ----- == Dictionaries The _dictionary_ data-type is set of pairs _key/value_. It is also known as _map_ or _associative array_. Dictionary literals are sequences of pairs separated by comma `,`; sequences are enclosed between brace brackets. -.List examples +.Dictionary examples [source,go] ---- {1:"one", 2:"two"} @@ -336,7 +328,7 @@ The _dictionary_ data-type is set of pairs _key/value_. It is also known as _map WARNING: Support for dictionaries is still ongoing. == Variables -A variable is an identifier with an assigned value. Variables are stored in the object that implements the _ExprContext_ interface. +A variable is an identifier with an assigned value. Variables are stored in the object that implements the Go _ExprContext_ interface, e.g. _SimpleVarStore_ or _SimpleFuncStore_. .Examples [source,go] @@ -390,23 +382,30 @@ The _selector operator_ is very similar to the _switch/case/default_ statement a ::= {";" } ---- -In other words, the selector operator evaluates the expression (``) on the left-hand side of the `?` symbol; it then compares the result obtained with the values listed in the ``'s. If the comparision find a match with a value in a match-list, the associated `` is evaluted, and its result will be the final result of the selection operation. +In other words, the selector operator evaluates the expression (``) on the left-hand side of the `?` symbol; it then compares the result obtained with the values listed in the ``'s. If the comparision finds a match with a value in a match-list, the associated `` is evaluted, and its result will be the final result of the selection operation. The match lists are optional. In that case, the position, from left to right, of the `` is used as match-list. Of course, that only works if the select-expression results in an integer. The `:` symbol (colon) is the separator of the selector-cases. Note that if the value of the select-expression does not match any match-list, an error will be issued. Therefore, it is strongly recommended to provide a default (multi-)expression introduced by the `::` symbol (double-colon). Also note that the default expression has no match-list. - .Examples [source,go] ---- -1 ? {"a"} : {"b"} // returns "b" -10 ? {"a"} : {"b"} :: {"c"} // returns "c" -10 ? {"a"} :[true, 2+8] {"b"} :: {"c"} // returns "b" -10 ? {"a"} :[true, 2+8] {"b"} ::[10] {"c"} // error: "... case list in default clause" -10 ? {"a"} :[10] {x="b" but x} :: {"c"} // returns "b" -10 ? {"a"} :[10] {x="b"; x} :: {"c"} // returns "b" -10 ? {"a"} : {"b"} // error: "... no case catches the value (10) of the selection expression +`>>>` [blue]`1 ? {"a"} : {"b"}` +[green]`b` +`>>>` [blue]`10 ? {"a"} : {"b"} :: {"c"}` +[green]`c' +[green]`>>>` [blue]`10 ? {"a"} :[true, 2+8] {"b"} :: {"c"}` +[green]`b` +`>>>` [blue]`10 ? {"a"} :[true, 2+8] {"b"} ::[10] {"c"}` +[red]`Parse Error: [1:34] case list in default clause` +[green]`>>>` [blue]`10 ? {"a"} :[10] {x="b" but x} :: {"c"}` +[green]`b` +`>>>` [blue]`10 ? {"a"} :[10] {x="b"; x} :: {"c"}` +[green]`b` +`>>>` [blue]`10 ? {"a"} : {"b"}` +[red]`Eval Error: [1:3] no case catches the value (10) of the selection expression` + ---- == Priorities of operators diff --git a/doc/Expr.html b/doc/Expr.html index a2541e1..78f198c 100644 --- a/doc/Expr.html +++ b/doc/Expr.html @@ -868,6 +868,28 @@ pre.rouge .ss { +
+

The items of strings can be accessed using the dot . operator.

+
+
+
Item access syntax
+
+
<item> ::= <string-expr>"."<index-expr>
+
+
+
+
String examples
+

>>> s="abc" assign the string to variable s
+abc
+>>> s.1 char at position 1 (starting from 0)
+b
+>>> s.(-1) char at position -1, the rightmost one
+c
+>>> #s number of chars
+3
+>>> #"abc" number of chars
+3

+

2.4. Boolean

@@ -1059,23 +1081,22 @@ pre.rouge .ss {
<item> ::= <list-expr>"."<index-expr>
-
+
Items of list
-
-
`>>>` [blue]`[1,2,3].1`
-[green]`2`
-`>>>` [blue]`list=[1,2,3]; list.1`
-[green]`2`
-`>>>` [blue]`["one","two","three"].1`
-[green]`two`
-`>>>` [blue]`list=["one","two","three"]; list.(2-1)`
-[green]`two`
-`>>>` [blue]`list.(-1)`
-[green]`three`
-`>>>` [blue]`list.(-1)`
-[green]`three`
-`>>>` [blue]`list.(10)`
-
+

>>> [1,2,3].1
+2
+>>> list=[1,2,3]; list.1
+2
+>>> ["one","two","three"].1
+two
+>>> list=["one","two","three"]; list.(2-1)
+two
+>>> list.(-1)
+three
+>>> list.(10)
+Eval Error: [1:9] index 10 out of bounds
+>>> #list
+3

@@ -1087,7 +1108,7 @@ pre.rouge .ss {

The dictionary data-type is set of pairs key/value. It is also known as map or associative array. Dictionary literals are sequences of pairs separated by comma ,; sequences are enclosed between brace brackets.

-
List examples
+
Dictionary examples
{1:"one", 2:"two"}
 {"one":1, "two": 2}
@@ -1112,7 +1133,7 @@ Support for dictionaries is still ongoing.
 

4. Variables

-

A variable is an identifier with an assigned value. Variables are stored in the object that implements the ExprContext interface.

+

A variable is an identifier with an assigned value. Variables are stored in the object that implements the Go ExprContext interface, e.g. SimpleVarStore or SimpleFuncStore.

Examples
@@ -1202,7 +1223,7 @@ The value on the left side of = must be an identifier.
-

In other words, the selector operator evaluates the expression (<select-expression>) on the left-hand side of the ? symbol; it then compares the result obtained with the values listed in the <match-list>’s. If the comparision find a match with a value in a match-list, the associated `<case-multi-expression> is evaluted, and its result will be the final result of the selection operation.

+

In other words, the selector operator evaluates the expression (<select-expression>) on the left-hand side of the ? symbol; it then compares the result obtained with the values listed in the <match-list>’s. If the comparision finds a match with a value in a match-list, the associated `<case-multi-expression> is evaluted, and its result will be the final result of the selection operation.

The match lists are optional. In that case, the position, from left to right, of the <selector-case> is used as match-list. Of course, that only works if the select-expression results in an integer.

@@ -1213,13 +1234,21 @@ The value on the left side of = must be an identifier.
Examples
-
1 ? {"a"} : {"b"}                           // returns "b"
-10 ? {"a"} : {"b"} :: {"c"}                 // returns "c"
-10 ? {"a"} :[true, 2+8] {"b"} :: {"c"}      // returns "b"
-10 ? {"a"} :[true, 2+8] {"b"} ::[10] {"c"}  // error:  "... case list in default clause"
-10 ? {"a"} :[10] {x="b" but x} :: {"c"}     // returns "b"
-10 ? {"a"} :[10] {x="b"; x} :: {"c"}        // returns "b"
-10 ? {"a"} : {"b"}                          // error:  "... no case catches the value (10) of the selection expression
+
`>>>` [blue]`1 ? {"a"} : {"b"}`
+[green]`b`
+`>>>` [blue]`10 ? {"a"} : {"b"} :: {"c"}`
+[green]`c'
+[green]`>>>` [blue]`10 ? {"a"} :[true, 2+8] {"b"} :: {"c"}`
+[green]`b`
+`>>>` [blue]`10 ? {"a"} :[true, 2+8] {"b"} ::[10] {"c"}`
+[red]`Parse Error: [1:34] case list in default clause`
+[green]`>>>` [blue]`10 ? {"a"} :[10] {x="b" but x} :: {"c"}`
+[green]`b`
+`>>>` [blue]`10 ? {"a"} :[10] {x="b"; x} :: {"c"}`
+[green]`b`
+`>>>` [blue]`10 ? {"a"} : {"b"}`
+[red]`Eval Error: [1:3] no case catches the value (10) of the selection expression`
+
@@ -1490,7 +1519,7 @@ The value on the left side of = must be an identifier.