mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Parser for index expression such as a[0] (#3033)
Co-authored-by: Farzana Ahmed Siddique <fasiddique@google.com>
This commit is contained in:
co-authored by
Farzana Ahmed Siddique
parent
9e03d5efe2
commit
6cca85534f
@@ -0,0 +1,27 @@
|
||||
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
||||
// Exceptions. See /LICENSE for license information.
|
||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
#include "toolchain/lexer/token_kind.h"
|
||||
#include "toolchain/parser/parser_context.h"
|
||||
|
||||
namespace Carbon {
|
||||
|
||||
auto ParserHandleIndexExpression(ParserContext& context) -> void {
|
||||
auto state = context.PopState();
|
||||
state.state = ParserState::IndexExpressionFinish;
|
||||
context.PushState(state);
|
||||
context.AddNode(ParseNodeKind::IndexExpressionStart,
|
||||
context.ConsumeChecked(TokenKind::OpenSquareBracket),
|
||||
state.subtree_start, state.has_error);
|
||||
context.PushState(ParserState::Expression);
|
||||
}
|
||||
|
||||
auto ParserHandleIndexExpressionFinish(ParserContext& context) -> void {
|
||||
auto state = context.PopState();
|
||||
context.AddNode(ParseNodeKind::IndexExpression,
|
||||
context.ConsumeChecked(TokenKind::CloseSquareBracket),
|
||||
state.subtree_start, state.has_error);
|
||||
}
|
||||
|
||||
} // namespace Carbon
|
||||
Reference in New Issue
Block a user