Skip to content

Conversation

NatElkins
Copy link

Summary

This PR adds support for wildcard slice expressions ([*]) in F# arrays and lists, improving AST clarity for this common slicing pattern.

Problem

The grammar already parsed arr.[*] syntax but didn't create a proper AST node for the wildcard, making it difficult for tools to recognize this as a distinct operation from other slice patterns.

Solution

Added an alias for "*" as wildcard_slice in the slice_range rule:

// Before
slice_range: ($) => choice($._slice_range_special, $._expression, "*"),

// After
slice_range: ($) => choice($._slice_range_special, $._expression, alias("*", $.wildcard_slice)),

Examples

The following F# code now produces clear AST nodes:

let all = arr.[*]           // Select all elements
let row = matrix.[0.., *]    // Select entire row
let col = matrix.[*, 0..]    // Select entire column  

Tests

Added 3 tests to test/corpus/expr.txt:

  • Simple wildcard slice
  • 2D array row slice with wildcard
  • 2D array column slice with wildcard

All existing tests continue to pass.

Related

This addresses one of the gaps identified in #150 (Implementation Status tracking).

Implements wildcard slice syntax for arrays and lists:
- arr.[*] selects all elements
- matrix.[0.., *] for multi-dimensional slicing
- Consistent with F# 6.0+ slice syntax

The grammar already supported '*' in slice_range but wasn't creating
a proper AST node. This change aliases '*' as wildcard_slice for
clearer AST representation.

Tests added for:
- Simple wildcard slice: arr.[*]
- 2D array row slice: matrix.[0.., *]
- 2D array column slice: matrix.[*, 0..]
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.

1 participant