Enhance Assignment Parsing
There are some breaking changes with this new commit, so existing users of Ion should carefully review these changes. Namely, at the moment the ability to perform argument swapping with the let command isn't functioning, due to some changes to how the assignment parsing happens. I will probably bring this feature back soon, but for now it will not work because the new assignment parsing is evaluating expressions without performing any sort of heap allocations. Each key / value pair are now parsed one at a time, which is what made it possible to implement this without any heap allocations. It is also the cause of the breaking change with swapping values. It also causes another breaking change: you can't evaluate an array and have each element in the array distributed to arguments on the left hand side. Instead, your arguments should be properly separated by spaces. When an array is detected, then whichever variable corresponds on the left hand side will receive the entire array and be initialized as an array, unless otherwise specified. But what we have now gained are a significant degree of flexibility in mixing arrays among variables, among specifying types to enable some type checking. Type checking is currently very limited though, but will soon encompass all of the following: - [] - str - str[] - int - int[] - bool - bool[] - float - float[] At some point, this may even be expanded to also support: - int128 - float128 - uint - uint128 There's also a question of whether we should roll back prior assignments when an assignment fails. Currently, I just have the behavior set to retain prior successful assignments, but cancelling all future assignments, should there be an error with setting values, such as an invalid type. let a:str b c = [one two three] for five The above should cause a type error because first variable demands to be a string and not an array. The b and c variables are thus not set at all.
Showing
- examples/let.ion 12 additions, 7 deletionsexamples/let.ion
- examples/let.out 6 additions, 3 deletionsexamples/let.out
- src/parser/assignments.rs 0 additions, 125 deletionssrc/parser/assignments.rs
- src/parser/mod.rs 1 addition, 1 deletionsrc/parser/mod.rs
- src/parser/statement/parse.rs 2 additions, 3 deletionssrc/parser/statement/parse.rs
- src/parser/types/assignments.rs 328 additions, 0 deletionssrc/parser/types/assignments.rs
- src/parser/types/mod.rs 2 additions, 0 deletionssrc/parser/types/mod.rs
- src/parser/types/parse.rs 170 additions, 0 deletionssrc/parser/types/parse.rs
- src/shell/assignments.rs 446 additions, 125 deletionssrc/shell/assignments.rs
- src/shell/flow.rs 6 additions, 6 deletionssrc/shell/flow.rs
- src/shell/flow_control.rs 4 additions, 4 deletionssrc/shell/flow_control.rs
Loading
Please register or sign in to comment