mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
[toolchain] Parse variables and parameters as 'name: Type'. (#574)
Factor out code for pattern parsing, that only recognizes this form for now, and uniformly form a 'PatternBinding' parse node for this, for both variables and patterns.
This commit is contained in:
@@ -32,6 +32,8 @@ enum PrecedenceLevel : int8_t {
|
||||
// Assignment.
|
||||
SimpleAssignment,
|
||||
CompoundAssignment,
|
||||
// Sentinel representing a type context.
|
||||
Type,
|
||||
// Sentinel representing a context in which any operator can appear.
|
||||
Lowest,
|
||||
};
|
||||
@@ -58,6 +60,16 @@ struct OperatorPriorityTable {
|
||||
{SimpleAssignment, CompoundAssignment, LogicalAnd, LogicalOr},
|
||||
{Lowest});
|
||||
|
||||
// FIXME: Decide upon a precedence level to use for types. It's important
|
||||
// that this is no higher than simple assignment, otherwise
|
||||
// var x: T = y;
|
||||
// would be parsed as
|
||||
// var x: (T = y);
|
||||
// For now, we have no type operators and no operator overloading, so we
|
||||
// only parse primary expressions in types.
|
||||
MarkHigherThan({Highest}, {Type});
|
||||
MarkHigherThan({Type}, {Lowest});
|
||||
|
||||
// Compute the transitive closure of the above relationships: if we parse
|
||||
// `a $ b @ c` as `(a $ b) @ c` and parse `b @ c % d` as `(b @ c) % d`,
|
||||
// then we will parse `a $ b @ c % d` as `((a $ b) @ c) % d` and should
|
||||
@@ -181,6 +193,10 @@ auto PrecedenceGroup::ForTopLevelExpression() -> PrecedenceGroup {
|
||||
return PrecedenceGroup(Lowest);
|
||||
}
|
||||
|
||||
auto PrecedenceGroup::ForType() -> PrecedenceGroup {
|
||||
return PrecedenceGroup(Type);
|
||||
}
|
||||
|
||||
auto PrecedenceGroup::ForLeading(TokenKind kind)
|
||||
-> llvm::Optional<PrecedenceGroup> {
|
||||
switch (kind) {
|
||||
|
||||
Reference in New Issue
Block a user