feat: add array declaration parsing support#112
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds parsing support for C-style array declarators ([...]) in both global and local variable declarations by consuming bracket suffixes after identifiers and wrapping the declared type in Type::Array.
Changes:
- Introduces
parse_array_suffixto parse one-or-more array suffixes ([expr?]) after a variable name (including multidimensional and[]). - Updates global (
parse_global_var_decl) and local (parse_var_decl) declaration parsing to applyparse_array_suffixbefore optional initializers. - Adds parser tests covering global/local arrays, multidimensional arrays, and arrays without a specified size.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/parser/rules/declarations/types.rs |
Adds parse_array_suffix helper that consumes [...] and nests Type::Array. |
src/parser/rules/declarations/top_level.rs |
Applies array-suffix parsing to global variable declarations. |
src/parser/rules/declarations/var_decl.rs |
Applies array-suffix parsing to local variable declarations. |
src/parser/rules/declarations/mod.rs |
Re-exports parse_array_suffix for use by other parser modules. |
src/tests/parser_test.rs |
Adds unit tests for global/local array declarations, multidimensional arrays, and []. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Asserções do parses_array_without_size e parses_struct_use_as_type_after_definition estavam trocadas por corrupção de merge. Restaura comportamento correto de cada teste.
Owner
Author
|
Correções do copilot levadas em consideração! pronto para o merge |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request adds support for parsing array types in both global and local variable declarations, including multidimensional arrays and arrays without specified sizes. It introduces a new helper function to handle array suffixes in type declarations, updates the parsing logic to use this function, and adds comprehensive tests to ensure correct parsing of various array scenarios.
Parser enhancements for array types:
parse_array_suffixfunction intypes.rsto consume array suffixes ([N]) after variable names, supporting multiple dimensions and arrays without specified sizes. The parsed type is wrapped inType::Array, though the size is not stored in the AST.top_level.rs) and local (var_decl.rs) variable declaration parsers to useparse_array_suffix, enabling consistent array type handling across declaration contexts.API and module changes:
Re-exported
parse_array_suffixfrom thetypesmodule for use in other parser components.Updated imports in affected files to include
parse_array_suffix.Testing improvements:
Added new tests to
parser_test.rscovering global and local array declarations, multidimensional arrays, and arrays without a specified size to verify correct parsing behavior.Closes #108