-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split apart the grammar for statements and items #10
base: main
Are you sure you want to change the base?
Conversation
TSPL has referred to declarations and expressions as "statements", while the Swift Compiler refers to this general class of syntax as "items". Split the statement and item productions apart.
This might benefit from a more detailed discussion of some sort; especially given how we structure the different parts of the reference portions of the book. Are folks over in the compiler world generally happy with the word "item" as a useful top-level term in grammar here? In contrast to the familiar PL terms of art statement and expression, item feels like it doesn't carry much explanatory weight for readers. But maybe that's just me. Let's talk about this more, either here in the issue or elsewhere. |
There's several questions here so
It is a term of art. Perhaps It's worth noting that we're not alone here in our usage of this term Rust refers to crate and module-level syntactic constructs as items.
It's worth understanding why languages that e.g. choose to make declarations and statements a subordinate production of their statement grammars do so, and why Swift is different. Take Kotlin, which is a near neighbor to us in terms of syntax. They also have a script-mode equivalent, and they choose to structure their grammar in this manner. To my knowledge, Kotlin does not have a notion of compile-time configuration akin to Swift's For Swift, the matter is not so simple. The context a
In declaration context, this production may only contain declarations
In expression context, this production may only involve postfix expressions
In the context of switch statements, this production may only involve case statements and their bodies, not any kind of statement, and not any kind of item
We must be able to distinguish these three kinds of productions from one another, and also reason about when all three are allowed. For that, we cannot conflate declarations, expressions, and statements so freely.
This is a good point. It kind of feels like a cop-out from a descriptive point of view. Programming language grammars are not really designed for the kind of comprehensibility that you describe here as a goal. We have a chance to amend that, certainly, if we can come up with another kind of syntactic category here. |
Marking this as a draft while we continue these discussions. |
TSPL has referred to declarations and expressions as "statements", while
the Swift Compiler refers to this general class of syntax
as "items". Split the statement and item productions apart.