[ABNF] Improve nomenclature.

Replace 'circuit-or-alias-type' with 'identifier-or-self-type'.

This makes the nomenclature for types more clear and extensible:

- A type may be an identifier, which may be the name of a circuit type or the
  name of a type alias.

- In the future, an identifier used as a type could refer to other kinds of
  types that we may add, such as enumerations.

- While both 'alias type' and 'type alias' could be acceptable terms, it seems
  best to standardize on 'type alias': the latter describes an alias of a type
  (which is the right concept), while the former suggests a type of the "alias"
  kind (cf. 'circuit type', 'field type', 'integer type', etc.). Type aliases
  are not another kind of types like the other: they are aliases of (any of)
  those kinds of types. So by not having 'circuit-or-alias-type' we avoid
  suggesting a notion of 'alias type'.

This does not change the language described by the grammar, it merely changes
some nomenclature in the grammar. Thus, no change to the parser is
needed. Aligning the nomenclature in the abstract syntax and parser to the ABNF
would be good, but entirely optional at this point.
This commit is contained in:
Alessandro Coglio 2021-09-02 21:54:42 -07:00
parent a0cf3a0f58
commit 1c18f4c56d

View File

@ -659,13 +659,16 @@ character-type = %s"char"
scalar-type = boolean-type / arithmetic-type / address-type / character-type scalar-type = boolean-type / arithmetic-type / address-type / character-type
; Circuit types are denoted by identifiers and the keyword `Self`. ; Circuit types are denoted by identifiers and the keyword `Self`;
; The latter is only allowed inside a circuit definition, ; the latter is only allowed inside a circuit definition,
; to denote the circuit being defined. ; to denote the circuit type being defined.
; Identifiers may also be type aliases;
; syntactically (i.e. without a semantic analysis),
; they cannot be distinguished from circuit types.
self-type = %s"Self" self-type = %s"Self"
circuit-or-alias-type = identifier / self-type identifier-or-self-type = identifier / self-type
; A tuple type consists of zero, two, or more component types. ; A tuple type consists of zero, two, or more component types.
@ -683,7 +686,7 @@ array-dimensions = natural
; Scalar and the remaining types form all the types. ; Scalar and the remaining types form all the types.
type = scalar-type / tuple-type / array-type / circuit-or-alias-type type = scalar-type / tuple-type / array-type / identifier-or-self-type
; The lexical grammar given earlier defines product group literals. ; The lexical grammar given earlier defines product group literals.
; The other kind of group literal is a pair of integer coordinates, ; The other kind of group literal is a pair of integer coordinates,
@ -769,7 +772,7 @@ array-expression = array-construction
; while the right one denotes an expression (a variable), ; while the right one denotes an expression (a variable),
; so they are syntactically identical but semantically different. ; so they are syntactically identical but semantically different.
circuit-construction = circuit-or-alias-type "{" circuit-construction = identifier-or-self-type "{"
circuit-inline-element circuit-inline-element
*( "," circuit-inline-element ) [ "," ] *( "," circuit-inline-element ) [ "," ]
"}" "}"
@ -805,7 +808,7 @@ postfix-expression = primary-expression
/ postfix-expression "." identifier / postfix-expression "." identifier
/ identifier function-arguments / identifier function-arguments
/ postfix-expression "." identifier function-arguments / postfix-expression "." identifier function-arguments
/ circuit-or-alias-type "::" identifier function-arguments / identifier-or-self-type "::" identifier function-arguments
/ postfix-expression "[" expression "]" / postfix-expression "[" expression "]"
/ postfix-expression "[" [expression] ".." [expression] "]" / postfix-expression "[" [expression] ".." [expression] "]"
@ -935,7 +938,8 @@ conditional-statement = branch
; that goes from a starting value (inclusive) to an ending value (exclusive). ; that goes from a starting value (inclusive) to an ending value (exclusive).
; The body is a block. ; The body is a block.
loop-statement = %s"for" identifier %s"in" expression ".." [ "=" ] expression block loop-statement = %s"for" identifier %s"in" expression ".." [ "=" ] expression
block
; An assignment statement is straightforward. ; An assignment statement is straightforward.
; Based on the operator, the assignment may be simple (i.e. `=`) ; Based on the operator, the assignment may be simple (i.e. `=`)
@ -1047,9 +1051,7 @@ package-path = "*"
/ package-name "." package-path / package-name "." package-path
/ "(" package-path *( "," package-path ) [","] ")" / "(" package-path *( "," package-path ) [","] ")"
; A type declaration consists of the `type` keyword ; A type alias declaration defines an identifier to stand for a type.
; followed by an identifier and a type that the alias
; would refer to.
type-alias-declaration = %s"type" identifier "=" type ";" type-alias-declaration = %s"type" identifier "=" type ";"