Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyword continue, break, pass in lexer, parser #173

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MaksimShagov
Copy link
Collaborator

No description provided.

@MaksimShagov MaksimShagov self-assigned this May 19, 2024
ctx.tokenIter->is(Keyword::Pass));
ctx.goNextToken();
if (!ctx.token().is(Special::EndOfExpression)) {
ctx.pushError("Unexepted tokens after control flow keyword");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. я думаю сообщение должно быть более конкретным: Unexpected token in a break|continue|pass statement.
  2. в случае этой ошибки нужно явно перейти на следующее выражение, ctx.goNextExperssion()

@@ -433,6 +433,17 @@ std::stack<SubExpression> generatePostfixForm(TokenIterator tokenIterBegin, Toke
return postfixForm;
}

void parseControlFlowStatement(ParserContext &ctx) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pass не влияет на control flow, лучше parseSimpleStatement или что-нибудь такое

@@ -1193,6 +1193,53 @@ TEST(Parser, can_parse_for_enumerate) {
ASSERT_EQ(expected, tree.dump());
}

TEST(Parser, can_parse_pass_continue_break_loops) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

наверное для pass лучше сделать отдельный тест? он же не только в цикле может быть, а где угодно

};
TokenList tokens = Lexer::process(source);
SyntaxTree tree = Parser::process(tokens);
std::string expected = "ProgramRoot\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

как смотришь на использование DeclarativeTree?

t.node(NodeType::FunctionDefinition).withChildren();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Extend language: pass Extend language: continue, break
2 participants