mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Reorganize interface parsing to be more consistent with other declarations. (#2646)
The comments in parse_node_kind.def capture the change being made here. Before: ``` // _external_: DeclaredName // InterfaceBodyStart // _external_: statements // InterfaceBodyEnd // InterfaceDefinition ``` After: ``` // InterfaceIntroducer // DeclaredName // InterfaceDefinitionStart // _external_: declarations // InterfaceDefinition ``` Really I just want to treat introduced things consistently. `var` defines my philosophy here: it doesn't always have a `DeclaredName`, so the `VarIntroducer` _must_ be the bounding node. By being consistent with that, I believe that overall the structure becomes easier to understand (that is, there are fewer inconsistencies to understand). This also adds InterfaceDeclaration, since I think it can be predicted we'll have that, and it's helpful for making recover consistent with HandleDeclarationError. Similarly, I'm also trying to standardize the loop processing a little with HandleDeclarationLoop. In the current approach, InterfaceDefinitionFinish isn't a necessary state, so I'm removing it.
This commit is contained in:
@@ -79,8 +79,9 @@ CARBON_PARSE_NODE_KIND_BRACKET(CodeBlock, CodeBlockStart)
|
||||
// _external_: statements
|
||||
// FunctionDefinition
|
||||
//
|
||||
// The above is a definition; for a declaration, FunctionDeclaration will end it
|
||||
// where FunctionDefinitionStart is for a definition.
|
||||
// The above is the structure for a definition; for a declaration,
|
||||
// FunctionDefinitionStart and later nodes are removed and replaced by
|
||||
// FunctionDeclaration.
|
||||
CARBON_PARSE_NODE_KIND_CHILD_COUNT(FunctionIntroducer, 0)
|
||||
CARBON_PARSE_NODE_KIND_CHILD_COUNT(ReturnType, 1)
|
||||
CARBON_PARSE_NODE_KIND_BRACKET(FunctionDefinitionStart, FunctionIntroducer)
|
||||
@@ -282,14 +283,19 @@ CARBON_PARSE_NODE_KIND_BRACKET(StructTypeLiteral,
|
||||
StructLiteralOrStructTypeLiteralStart)
|
||||
|
||||
// `interface`:
|
||||
// _external_: DeclaredName
|
||||
// InterfaceBodyStart
|
||||
// _external_: statements
|
||||
// InterfaceBodyEnd
|
||||
// InterfaceIntroducer
|
||||
// DeclaredName
|
||||
// InterfaceDefinitionStart
|
||||
// _external_: declarations
|
||||
// InterfaceDefinition
|
||||
CARBON_PARSE_NODE_KIND_CHILD_COUNT(InterfaceBodyStart, 0)
|
||||
CARBON_PARSE_NODE_KIND_BRACKET(InterfaceBody, InterfaceBodyStart)
|
||||
CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDefinition, DeclaredName)
|
||||
//
|
||||
// The above is the structure for a definition; for a declaration,
|
||||
// InterfaceDefinitionStart and later nodes are removed and replaced by
|
||||
// InterfaceDeclaration.
|
||||
CARBON_PARSE_NODE_KIND_CHILD_COUNT(InterfaceIntroducer, 0)
|
||||
CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDefinitionStart, InterfaceIntroducer)
|
||||
CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDefinition, InterfaceDefinitionStart)
|
||||
CARBON_PARSE_NODE_KIND_BRACKET(InterfaceDeclaration, InterfaceIntroducer)
|
||||
|
||||
// A pattern binding for `self` deduced parameter:
|
||||
// `self`
|
||||
|
||||
Reference in New Issue
Block a user