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:
josh11b
2024-09-11 03:17:07 +00:00
committed by GitHub
co-authored by Josh L Richard Smith
parent 8fa173b58a
commit c33c9a02f6
19 changed files with 784 additions and 38 deletions
+12 -2
View File
@@ -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: