From 378599afbad2cacd0ce262b5a6d61067b5c566fe Mon Sep 17 00:00:00 2001 From: Alessandro Coglio Date: Mon, 23 Aug 2021 14:39:59 -0700 Subject: [PATCH] [RFC] Add more proposed mods to ABNF grammar. --- docs/rfc/007-type-aliases.md | 53 +++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/docs/rfc/007-type-aliases.md b/docs/rfc/007-type-aliases.md index c4ed3c259a..38aa272287 100644 --- a/docs/rfc/007-type-aliases.md +++ b/docs/rfc/007-type-aliases.md @@ -42,7 +42,7 @@ With the array types of unspecified size proposed in RFC 006, ## Syntax The ABNF grammar changes as follows: -```ts +``` ; modified rule: keyword = ... / %s"true" @@ -59,12 +59,63 @@ declaration = import-declaration / circuit-declaration / constant-declaration / type-alias-declaration ; new + + ``` A type alias declaration introduces the identifier to stand for the type. Only top-level type alias declarations are supported; they are not supported inside functions or circuit types. +In addition, the following changes to the grammar are appropriate. + +First, the rule +``` +circuit-type = identifier / self-type ; replace with the one below +``` +should be replaced with the rule +``` +circuit-or-alias-type = identifier / self-type +``` +The reason is that, at parsing time, an identifier is not necessarily a circuit type; +it may be a type alias that may expand to a (circuit or non-circuit type). +Thus, the nomenclature `circuit-or-alias-type` is appropriate. +Consequently, references to `circuit-type` in the following rules must be replaced with `circuit-or-alias-type`: +``` +; modified rule: +circuit-construction = circuit-or-alias-type "{" ; modified + circuit-inline-element + *( "," circuit-inline-element ) [ "," ] + "}" + +; modified rule: +postfix-expression = primary-expression + / postfix-expression "." natural + / postfix-expression "." identifier + / identifier function-arguments + / postfix-expression "." identifier function-arguments + / circuit-or-alias-type "::" identifier function-arguments ; modified + / postfix-expression "[" expression "]" + / postfix-expression "[" [expression] ".." [expression] "]" +``` + +Second, the rule +``` +aggregate-type = tuple-type / array-type / circuit-type +``` +should be removed, because if we replaced `circuit-type` with `circuit-or-alias-type` there, +the identifier could be a type alias, not necessarily an aggregate type. +(The notion of aggregate type remains at a semantic level, but has no longer a place in the grammar.) +Consequently, the rule +``` +type = scalar-type / aggregate-type +``` +should be rephrased as +``` +type = scalar-type / tuple-type / array-type / circuit-or-alias-type +``` +which "inlines" the previous `aggregate-type` with `circuit-type` replaced with `circuit-or-alias-type`. + ## Semantics There must be no direct or indirect circularity in the type aliases.