Skip to content

added statement expansion to parser #7724

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

Conversation

dean-starkware
Copy link
Collaborator

No description provided.

@dean-starkware dean-starkware marked this pull request as ready for review May 3, 2025 13:41
@reviewable-StarkWare
Copy link

This change is Reviewable

@dean-starkware dean-starkware force-pushed the dean/macro_placeholder_repetition_block branch from 12ea42b to 888bd51 Compare May 6, 2025 11:41
Copy link
Collaborator

@orizi orizi left a comment

Choose a reason for hiding this comment

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

Reviewed 2 of 11 files at r2, all commit messages.
Reviewable status: 2 of 11 files reviewed, 2 unresolved discussions (waiting on @gilbens-starkware)


crates/cairo-lang-parser/src/parser.rs line 1536 at r2 (raw file):

        );
        Ok(placeholder_repetition_block.into())
    }

move to under the usage.

(probably right below parse_statements_and_block.

Code quote:

    /// Parses a placeholder repetition block inside a macro.
    fn parse_placeholder_repetition_block(&mut self) -> TryParseResult<StatementBlockGreen> {
        let dollar = self.take::<TerminalDollar>();
        if self.peek().kind != SyntaxKind::TerminalLParen {
            return Err(TryParseFailure::SkipToken);
        }
        let lparen = self.take::<TerminalLParen>();
        let elements = StatementList::new_green(
            self.db,
            self.parse_list(
                Self::try_parse_statement,
                is_of_kind!(rparen, block, rbrace, module_item_kw),
                "statement",
            ),
        );
        let rparen = self.parse_token::<TerminalRParen>();
        let operator = match self.peek().kind {
            SyntaxKind::TerminalQuestionMark => self.take::<TerminalQuestionMark>().into(),
            SyntaxKind::TerminalPlus => self.take::<TerminalPlus>().into(),
            SyntaxKind::TerminalMul => self.take::<TerminalMul>().into(),
            _ => self
                .create_and_report_missing::<TerminalPlus>(
                    ParserDiagnosticKind::MissingRepetitionOperator,
                )
                .into(),
        };
        let placeholder_repetition_block = PlaceholderRepetitionBlock::new_green(
            self.db, dollar, lparen, elements, rparen, operator,
        );
        Ok(placeholder_repetition_block.into())
    }

crates/cairo-lang-parser/src/parser_test_data/diagnostics/expr_diagnostics line 42 at r2 (raw file):

 --> dummy_file.cairo:4:7
    } + match x {
      ^

?

Code quote:

error: Skipped tokens. Expected: statement.
 --> dummy_file.cairo:4:7
    } + match x {
      ^

@dean-starkware dean-starkware force-pushed the dean/macro_placeholder_repetition_block branch from 888bd51 to 0edd08a Compare May 10, 2025 12:43
Copy link
Collaborator Author

@dean-starkware dean-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 11 files reviewed, 2 unresolved discussions (waiting on @gilbens-starkware and @orizi)


crates/cairo-lang-parser/src/parser.rs line 1536 at r2 (raw file):

Previously, orizi wrote…

move to under the usage.

(probably right below parse_statements_and_block.

Done.

@dean-starkware dean-starkware force-pushed the dean/macro_placeholder_repetition_block branch from 0edd08a to 9dd305b Compare May 11, 2025 06:40
@dean-starkware dean-starkware marked this pull request as draft May 11, 2025 06:40
Copy link
Contributor

@gilbens-starkware gilbens-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 11 files reviewed, 4 unresolved discussions (waiting on @dean-starkware and @orizi)


crates/cairo-lang-semantic/src/expr/compute.rs line 1786 at r4 (raw file):

            ast::StatementBlock::Statements(statements) => statements.elements(db),
            _ => vec![],
        };

Placeholders shouldn't reach this point (it'll be replaces in the expansion, which should happen before), so extract the exprblock at the top of the function and panic if it's a placeholder.

Code quote:

        let mut statements = match syntax.statements(db) {
            ast::StatementBlock::Statements(statements) => statements.elements(db),
            _ => vec![],
        };

crates/cairo-lang-parser/src/parser_test_data/partial_trees/macro_declaration line 288 at r4 (raw file):

}

//! > top_level_kind

Suggestion:

//! > top_level_kind
PlaceholderRepetitionBlock

@dean-starkware dean-starkware force-pushed the dean/macro_placeholder_repetition_block branch from 9dd305b to 0e9d727 Compare May 11, 2025 13:25
Copy link
Collaborator Author

@dean-starkware dean-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 11 files reviewed, 4 unresolved discussions (waiting on @gilbens-starkware and @orizi)


crates/cairo-lang-parser/src/parser_test_data/diagnostics/expr_diagnostics line 42 at r2 (raw file):

Previously, orizi wrote…

?

Done.

Copy link
Contributor

@gilbens-starkware gilbens-starkware left a comment

Choose a reason for hiding this comment

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

Reviewed all commit messages.
Reviewable status: 1 of 11 files reviewed, 5 unresolved discussions (waiting on @dean-starkware and @orizi)


crates/cairo-lang-parser/src/diagnostic.rs line 155 at r5 (raw file):

            }
            ParserDiagnosticKind::MissingRepetitionOperator => {
                "Missing tokens. Expected an operator.".to_string()

Suggestion:

Missing tokens. Expected a repetition operator.

@dean-starkware dean-starkware force-pushed the dean/macro_placeholder_repetition_block branch from 0e9d727 to 90a6791 Compare May 12, 2025 08:13
Copy link
Collaborator Author

@dean-starkware dean-starkware left a comment

Choose a reason for hiding this comment

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

Reviewable status: 1 of 11 files reviewed, 4 unresolved discussions (waiting on @gilbens-starkware and @orizi)


crates/cairo-lang-semantic/src/expr/compute.rs line 1786 at r4 (raw file):

Previously, gilbens-starkware (Gil Ben-Shachar) wrote…

Placeholders shouldn't reach this point (it'll be replaces in the expansion, which should happen before), so extract the exprblock at the top of the function and panic if it's a placeholder.

Done.


crates/cairo-lang-parser/src/diagnostic.rs line 155 at r5 (raw file):

            }
            ParserDiagnosticKind::MissingRepetitionOperator => {
                "Missing tokens. Expected an operator.".to_string()

Done.

@dean-starkware dean-starkware marked this pull request as ready for review May 12, 2025 08:15
@dean-starkware dean-starkware force-pushed the dean/macro_placeholder_repetition_block branch from 90a6791 to 1fec6a0 Compare May 12, 2025 08:15
@dean-starkware dean-starkware force-pushed the dean/macro_placeholder_repetition_block branch from 41c13ce to 0753382 Compare May 12, 2025 08:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants