Parse self in expressions. (#2697)

`self` wasn't being handled in expression logic, only parameter logic. This is needed for `self.x`.

Also renames SelfDeducedParameter to SelfIdentifier because it's parsed fairly consistently with Identifier; this better represents the situations where `self` will need to be handled, it's where `Identifier` is allowed (although `Identifier` could also refer to a type... but I still think `SelfDeducedParameter` is a more difficult to understand name).
This commit is contained in:
Jon Ross-Perkins
2023-03-20 14:13:29 -07:00
committed by GitHub
parent f50ca72797
commit d0105e119f
9 changed files with 92 additions and 12 deletions
+6 -1
View File
@@ -948,6 +948,11 @@ auto Parser::HandleExpressionInPostfixState() -> void {
PushState(ParserState::ParenExpression);
break;
}
case TokenKind::SelfParameter: {
AddLeafNode(ParseNodeKind::SelfIdentifier, Consume());
PushState(state);
break;
}
case TokenKind::SelfType: {
AddLeafNode(ParseNodeKind::SelfType, Consume());
PushState(state);
@@ -1494,7 +1499,7 @@ auto Parser::HandlePattern(PatternKind pattern_kind) -> void {
AddLeafNode(ParseNodeKind::DeclaredName, *identifier);
} else if (pattern_kind == PatternKind::DeducedParameter) {
if (auto self = ConsumeIf(TokenKind::SelfParameter)) {
AddLeafNode(ParseNodeKind::SelfDeducedParameter, *self);
AddLeafNode(ParseNodeKind::SelfIdentifier, *self);
} else {
on_error();
return;