Skip to content

Conversation

@FyreByrd
Copy link
Collaborator

@FyreByrd FyreByrd commented Oct 30, 2025

Closes #26.
Part 1/4 of #35.

let arr = [1, 2, 3]; // array literal
let x = arr[0]; // array index
let slice = arr[:]; // slice of the whole array
let fullSlice = arr[1:2:-1]; // full array slice
let y = arr[]; // index with no expression. Not sure on this. artifact of parser rules
let arr2: i32[] = [1, 2, 3]; // explicit type

Potential issue:
I ran into a common lookahead prefix error when trying to require an expression in between the brackets for array indexing, but make it optional for array slices (i.e. arr[:]).
The best solution I could find was to just allow for empty brackets for array indexing. I'm not a big fan of it. I wish I could make it a syntax error, but so far I think the best I can do is a semantic error.

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.

Parser should handle arrays, array indexes, and slices

2 participants