You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AST: Use a single kind K"op=" for updating assignments (#530)
Make all updating assignment operators like `+=` be represented with a
single `K"op="` head, with the operator itself in infix position.
For example, `x += 1` is now parsed as
[op=]
x :: Identifier
+ :: Identifier
y :: Identifier
This greatly reduces the number of distinct forms here from a rather big
list (`$=` `%=` `&=` `*=` `+=` `-=` `//=` `/=` `<<=` `>>=` `>>>=` `\=`
`^=` `|=` `÷=` `⊻=`) and makes the operator itself appear in the AST as
kind `K"Identifier"`, as it should. It also makes it possible to add
further unicode updating operators while keeping the AST stable.
The need for this was highlighted when working on JuliaLowering. When
using `K"+="` as a head, one needs to look up the appropriate operator
from the list of updating operators or use string munging on the Kind
itself. This is quite awkward especially as it needs special rules for
inferring the macro scope of the `+` identifier. In addition, having a
single head for this form means update operator semantics only need to
be dealt with in one place.
Copy file name to clipboardExpand all lines: docs/src/reference.md
+1Lines changed: 1 addition & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,6 +80,7 @@ class of tokenization errors and lets the parser deal with them.
80
80
* We use flags rather than child nodes to represent the difference between `struct` and `mutable struct`, `module` and `baremodule` (#220)
81
81
* Iterations are represented with the `iteration` and `in` heads rather than `=` within the header of a `for`. Thus `for i=is ; body end` parses to `(for (iteration (in i is)) (block body))`. Cartesian iteration as in `for a=as, b=bs body end` are represented with a nested `(iteration (in a as) (in b bs))` rather than a `block` containing `=` because these lists of iterators are neither semantically nor syntactically a sequence of statements, unlike other uses of `block`. Generators also use the `iteration` head - see information on that below.
82
82
* Short form functions like `f(x) = x + 1` are represented with the `function` head rather than the `=` head. In this case the `SHORT_FORM_FUNCTION_FLAG` flag is set to allow the surface syntactic form to be easily distinguished from long form functions.
83
+
* All kinds of updating assignment operators like `+=` are represented with a single `K"op="` head, with the operator itself in infix position. For example, `x += 1` is `(op= x + 1)`, where the plus token is of kind `K"Identifer"`. This greatly reduces the number of distinct forms here from a rather big list (`$=` `%=` `&=` `*=` `+=` `-=` `//=` `/=` `<<=` `>>=` `>>>=` `\=` `^=` `|=` `÷=` `⊻=`) and makes the operator itself appear in the AST as kind `K"Identifier"`, as it should. It also makes it possible to add further unicode updating operators while keeping the AST stable.
0 commit comments