Skip to content

feat: add array declaration parsing support#112

Merged
Bappoz merged 4 commits into
developerfrom
feat/issu107-fix-array-declaration
May 29, 2026
Merged

feat: add array declaration parsing support#112
Bappoz merged 4 commits into
developerfrom
feat/issu107-fix-array-declaration

Conversation

@Bappoz
Copy link
Copy Markdown
Owner

@Bappoz Bappoz commented May 29, 2026

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:

  • Added the parse_array_suffix function in types.rs to consume array suffixes ([N]) after variable names, supporting multiple dimensions and arrays without specified sizes. The parsed type is wrapped in Type::Array, though the size is not stored in the AST.
  • Updated both global (top_level.rs) and local (var_decl.rs) variable declaration parsers to use parse_array_suffix, enabling consistent array type handling across declaration contexts.

API and module changes:

  • Re-exported parse_array_suffix from the types module for use in other parser components.

  • Updated imports in affected files to include parse_array_suffix.
    Testing improvements:

  • Added new tests to parser_test.rs covering global and local array declarations, multidimensional arrays, and arrays without a specified size to verify correct parsing behavior.

Closes #108

@Bappoz Bappoz self-assigned this May 29, 2026
@Bappoz Bappoz added bug Something isn't working parser labels May 29, 2026
@Bappoz Bappoz requested a review from Copilot May 29, 2026 23:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_suffix to 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 apply parse_array_suffix before 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.

Comment thread src/parser/rules/declarations/var_decl.rs Outdated
Comment thread src/parser/rules/declarations/top_level.rs
Bappoz and others added 3 commits May 29, 2026 20:39
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.
@Bappoz
Copy link
Copy Markdown
Owner Author

Bappoz commented May 29, 2026

Correções do copilot levadas em consideração! pronto para o merge

@Bappoz Bappoz merged commit f171b77 into developer May 29, 2026
1 check passed
@Bappoz Bappoz deleted the feat/issu107-fix-array-declaration branch May 29, 2026 23:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working parser

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants