[ABNF] Improve rules for array expressions.

Extending array dimensions for types to allow underscore has the unintended
effect of allowing that also for expressions. This is not necessarily an error,
as the static semantics can rule out underscores from array expressions.
However, it is a simple syntactic constraint that is best captured by the
grammar.

This commit differentiate array dimensions for types and array dimensions for
expressions, using them in the appropriate places.
This commit is contained in:
Alessandro Coglio 2021-09-09 11:55:30 -07:00
parent 3b52459f85
commit ba65b4f4d5

View File

@ -669,12 +669,13 @@ tuple-type = "(" [ type 1*( "," type ) ] ")"
; or a tuple of one or more dimensions.
; Each dimension is either a natural or is unspecified.
array-type = "[" type ";" array-dimensions "]"
array-type = "[" type ";" array-type-dimensions "]"
array-dimension = natural / "_"
array-type-dimension = natural / "_"
array-dimensions = array-dimension
/ "(" array-dimension *( "," array-dimension ) ")"
array-type-dimensions = array-type-dimension
/ "(" array-type-dimension
*( "," array-type-dimension ) ")"
; The keyword `Self` denotes the enclosing circuit type.
; It is only allowed inside a circuit type declaration.
@ -767,7 +768,10 @@ array-inline-construction = "["
array-inline-element = expression / "..." expression
array-repeat-construction = "[" expression ";" array-dimensions "]"
array-repeat-construction = "[" expression ";" array-expression-dimensions "]"
array-expression-dimensions = natural
/ "(" natural *( "," natural ) ")"
array-construction = array-inline-construction / array-repeat-construction