feat(grammar): enhance aliases and for-loop initializers

Signed-off-by: erick-alcachofa <erick@artichoke.dev>

This commit updates the language grammar to expand the capabilities of
`using` aliases and C-style `for` loops. It also refines where aliases
can be declared. This changes are made after re-analizing the grammar
while creating the AST node types.

* **Aliases:** A `using` alias can now map to any valid `<type>`, such
  as a pointer (`*i32`) or optional (`?string`), instead of just a
  simple `<namespaced_identifier>`.
* **For Loops:** The initializer in a C-style `for` loop can now be a
  general `<expression>` (e.g., `i = 0`) in addition to a full
  `<variable_declaration>`.
* **Scope:** Alias declarations are now restricted to the top level
  (declarations) and are no longer permitted as statements inside
  function bodies.

BREAKING CHANGE: Alias declarations (`using`) are no longer valid inside
function bodies and must be declared at a module or global scope.
This commit is contained in:
erick-alcachofa 2025-10-12 18:58:27 -06:00
parent 5e94021ae5
commit 0e9995ce7e
Signed by: me
GPG Key ID: 6FA5F8643444BAFA

View File

@ -48,7 +48,7 @@ non_exportable_declaration =
<namespaced_identifier> ( "::" "*" )?
<alias_statement> =
"using" <identifier> "=" <namespaced_identifier> ";"
"using" <identifier> "=" <type> ";"
/* --- Declarations --- */
@ -106,7 +106,6 @@ non_exportable_declaration =
| <return_statement> ";"
| <break_statement> ";"
| <continue_statement> ";"
| <alias_statement>
| <match_statement>
| <switch_statement>
| <loop_statement>
@ -147,7 +146,7 @@ non_exportable_declaration =
)
<c_for_statement> =
"for" "(" <variable_declaration>? ";" <expression> ";" <expression>? ")"
"for" "(" ( <variable_declaration> | <expression> )? ";" <expression> ";" <expression>? ")"
<code_block>
<range_for_statement> =