polserver/testsuite/escript/binding/doc-examples.src
Kevin Eady ec344a395d
Add support for sequence and index bindings (#760)
* update grammar

* add ast nodes; ast building

* Rename to unpacking

* semantic analysis

* executor work part 1, unpacking indices

* renamings; implement index binding

* small cleanup

* use multi_index; more tests

* use multi_index only for rest, otherwise list

* initial formatting

* add missing token decoding

* address self-review comments

* formatting tweaks

* add test for var binding in classes

* add StringIterator

* fix spread tests

* add cfgfile iterator; add cfgelem opersubscript; tests

* add iterator for SQLResultSet and SQLRow; tests

* Copy value in take global/local

* Allow any iterable can index rest unpacking
Always use dictionary as rest object in index unpacking

* add docs, core-changes, doc tests

* formatting changes...

* address self-review comments

* update formatter, format all binding test srcs

* address review comments
- unset var scope

* add cfgfile/cfgelem docs

* reformat objref svg
2025-02-17 21:59:42 +01:00

49 lines
1.1 KiB
Text

if ( 1 )
var [ a, b, c ] := array{ 1, 2, 3 };
print( a ); // 1
print( b ); // 2
print( c ); // 3
endif
if ( 1 )
var { a, b, c } := dictionary{ "a" -> 1, "b" -> 2, "c" -> 3 };
print( a ); // 1
print( b ); // 2
print( c ); // 3
endif
if ( 1 )
var { a, b: b_value } := dictionary{ "a" -> 1, "b" -> 2, "c" -> 3 };
print( a ); // 1
print( b_value ); // 2
endif
if ( 1 )
var { [5]: five_value } := dictionary{ 5 -> "five" };
print( five_value ); // "five"
endif
if ( 1 )
var [ firstElement, { b, c } ] := array{ 1, struct{ b := 2, c := 3 } };
print( firstElement ); // 1
print( b ); // 2
print( c ); // 3
endif
if ( 1 )
var [ first, middle..., last ] := array{ 1, 2, 3, 4, 5 };
print( first ); // 1
print( middle ); // {2, 3, 4}
print( last ); // 5
endif
if ( 1 )
var { name,
age,
other_details... } := struct{ name := "John", age := 30, birthdate := "1990-01-01",
address := "123 Main St" };
print( other_details ); // dict{ "address" -> "123 Main St", "birthdate" -> "1990-01-01" }
endif