mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Parse support for where operator (#4275)
Includes support for the `impls`, `=`, and `==` requirement operators to the right of a `where`, but `and` to allow multiple requirements is still a TODO. --------- Co-authored-by: Josh L <josh11b@users.noreply.github.com> Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Josh L
Richard Smith
parent
8fa173b58a
commit
c33c9a02f6
@@ -29,6 +29,8 @@ enum PrecedenceLevel : int8_t {
|
||||
// Type formation.
|
||||
TypePrefix,
|
||||
TypePostfix,
|
||||
// `where` keyword.
|
||||
Where,
|
||||
// Casts.
|
||||
As,
|
||||
// Logical.
|
||||
@@ -60,9 +62,9 @@ struct OperatorPriorityTable {
|
||||
MarkHigherThan({Multiplicative}, {Additive});
|
||||
MarkHigherThan(
|
||||
{Additive, Modulo, BitwiseAnd, BitwiseOr, BitwiseXor, BitShift},
|
||||
{Relational});
|
||||
{Relational, Where});
|
||||
MarkHigherThan({Relational, LogicalPrefix}, {LogicalAnd, LogicalOr});
|
||||
MarkHigherThan({As, LogicalAnd, LogicalOr}, {If});
|
||||
MarkHigherThan({As, LogicalAnd, LogicalOr, Where}, {If});
|
||||
MarkHigherThan({If}, {Assignment});
|
||||
MarkHigherThan({Assignment, IncrementDecrement}, {Lowest});
|
||||
|
||||
@@ -194,6 +196,10 @@ auto PrecedenceGroup::ForImplAs() -> PrecedenceGroup {
|
||||
return PrecedenceGroup(As);
|
||||
}
|
||||
|
||||
auto PrecedenceGroup::ForRequirements() -> PrecedenceGroup {
|
||||
return PrecedenceGroup(Where);
|
||||
}
|
||||
|
||||
auto PrecedenceGroup::ForLeading(Lex::TokenKind kind)
|
||||
-> std::optional<PrecedenceGroup> {
|
||||
switch (kind) {
|
||||
@@ -289,6 +295,10 @@ auto PrecedenceGroup::ForTrailing(Lex::TokenKind kind, bool infix)
|
||||
case Lex::TokenKind::As:
|
||||
return Trailing{.level = As, .is_binary = true};
|
||||
|
||||
// Requirement operator.
|
||||
case Lex::TokenKind::Where:
|
||||
return Trailing{.level = Where, .is_binary = true};
|
||||
|
||||
// Prefix-only operators.
|
||||
case Lex::TokenKind::Const:
|
||||
case Lex::TokenKind::MinusMinus:
|
||||
|
||||
Reference in New Issue
Block a user