Skip to content

add support for SRTP call expressions#171

Draft
alexdarch wants to merge 1 commit intoionide:mainfrom
alexdarch:feature/srtp-call-expression
Draft

add support for SRTP call expressions#171
alexdarch wants to merge 1 commit intoionide:mainfrom
alexdarch:feature/srtp-call-expression

Conversation

@alexdarch
Copy link
Copy Markdown
Contributor

@alexdarch alexdarch commented Apr 4, 2026

Summary

  • Add srtp_call_expression grammar rule for statically resolved type parameter invocations, e.g. (^T : (static member Parse: string -> ^T) "42")
  • Wire it into the _expression choice (replacing the placeholder comment)
  • Add two test cases covering single-argument and multi-argument SRTP calls
  • Regenerate parsers for both fsharp and fsharp_signature

Add srtp_call_expression rule for statically resolved type parameter
invocations, e.g. (^T : (static member Parse: string -> ^T) "42").

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@alexdarch alexdarch changed the title feat: add support for SRTP call expressions Draft: add support for SRTP call expressions Apr 4, 2026
@alexdarch alexdarch marked this pull request as draft April 4, 2026 12:05
@alexdarch alexdarch changed the title Draft: add support for SRTP call expressions add support for SRTP call expressions Apr 4, 2026
@alexdarch alexdarch marked this pull request as ready for review April 7, 2026 09:39
@alexdarch
Copy link
Copy Markdown
Contributor Author

I think this is the only one of my 3 PRs (this, #172 and #173) that doesn't conflict with @Thorium's PR #166

@alexdarch alexdarch marked this pull request as draft April 7, 2026 09:44
@Thorium
Copy link
Copy Markdown
Contributor

Thorium commented Apr 7, 2026

I like your commits more, I'll cherry-pick/port them to be in my PR as well

Thorium pushed a commit to Thorium/tree-sitter-fsharp that referenced this pull request Apr 7, 2026
Port of PR ionide#171 - adds srtp_call_expression rule for parsing SRTP
trait member invocations like (^T : (member Method : ...) arg).
Uses restricted _srtp_type_argument matching only ^-prefixed type
params to avoid conflicts with char literals.
Nsidorenco pushed a commit that referenced this pull request Apr 15, 2026
* Add support for the following F# syntax features (all tests passing):

- open type declarations
- FSI directives (#time, #I, #help, #quit)
- XML doc comments (/// as distinct xml_doc node)
- Type test pattern in atomic patterns (:? Type)
- Quotation splicing (%%) prefix operator
- fixed expressions
- Range expressions in computation expressions
- Preprocessor boolean conditions (&&, ||, !, parens, true/false)
- Extern/P/Invoke declarations
- SRTP trait call expressions (^a : (static member ...) )
- Triple-quoted string interpolation ($""" {expr} """)
- Operator precedence for && and || (split into 3 levels)
- module rec (recursive modules)
- and! in computation expressions
- struct tuple type annotations (struct (int * int))
- Add optional type_argument_constraints to _function_or_value_defn_body for
  SRTP 'when' constraints on return type annotations
- Add optional 'struct' to anon_record_type for struct anonymous record types
- Add optional 'then' clause to additional_constr_defn for secondary
  constructor initialization expressions
- Expand fsharp_signature parser: named_module, namespace (global/rec),
  module_defn, type_definition, exception_definition, import_decl,
  module_abbrev, compiler_directive_decl, preproc_if support
- Fix indentation bug in type extension with ($) identifier test
- Add quotation expression support (<@ @>, <@@ @@>) with external tokens
- Add multi-dollar triple-quoted string interpolation ($$"""...""", $$$"""...""")
- Add module ... = begin...end with begin as external token
- Add exception named fields (of field1: type * field2: type)
- Add multiline type provider support via _multiline_generic_type
- Add signature parser named parameters (curried_spec)
- Fix scanner serialize/deserialize bugs (clamped count, bounds check, off-by-one)
- Update highlights, injections, indents queries

Scanner changes:
- Add FORMAT_TRIPLE_QUOTE_CONTENT external token that stops at
  unescaped { for interpolation support

Grammar changes:
- fsharp/grammar.js: new rules (trait_call_expression, extern_binding,
  extern_param, and_bang, struct_type, _preproc_expression, xml_doc),
  extended existing rules (import_decl, prefixed_expression, module_defn,
  named_module, infix_expression, format_triple_quoted_string)
- fsharp_signature/grammar.js: added conflict for operator precedence
- common/scanner.h: FORMAT_TRIPLE_QUOTE_CONTENT with {{ escape handling

* fix: resolve infinite loop on unmatched parens and multiline record patterns (#134, #149)

- Fix infinite loop during error recovery by returning false from scanner
  when ERROR_SENTINEL is set, preventing zero-length DEDENT loop
- Fix multiline record patterns by adding indent/dedent alternative in
  record_pattern grammar rule so scanner-emitted INDENT tokens between
  fields on different lines are handled correctly
- Add test case for multiline record patterns in match expressions

* Some real-world testing based improvements

* fix: narrow function.call highlight to identifier in application expressions

The application_expression highlight query previously used a wildcard
(_) @function.call that captured the entire first child node. For generic
constructor calls like ResizeArray<string>(), this meant the typed_expression
spanning 'ResizeArray<string>' was tagged as function.call, causing the '<'
at column 19 to incorrectly receive the function.call highlight instead of
a bracket highlight.

Changes:
- Replace the single broad application_expression query with four specific
  patterns that target only the identifier within long_identifier_or_op,
  dot_expression, and their typed_expression variants
- Add typed_expression '>' @punctuation.bracket to highlight the closing
  angle bracket consistently with generic_type (the opening '<' uses the
  _tyapp_open external token which is anonymous and unmatchable in queries)
- Update test expectations: remove assertions for '<' (unmatchable) and
  change '>' from operator to punctuation.bracket

* Reduced signature parser size, fixed EOF handling, and improved numeric directives

* match scoping is a known issue for now, this new test is failing.

* Address PR feedback from @Nsidorenco

* Fix three parser issues: *, step ranges, and $ string DEDENT

- Scanner: add * to is_infix_op_start() so multiplication on
  continuation lines is recognized as an infix operator
- Grammar: add 3-part from..step..to alternative to _slice_range_special
  for step range expressions (e.g. [0..2..10])
- Scanner: emit DEDENT/NEWLINE before returning false in the
  MULTI_DOLLAR_TRIPLE_QUOTE_START handler, fixing interpolated strings
  on dedented lines being absorbed into previous let bindings

* Fix type_extension greedily consuming subsequent declarations

Require 'with' keyword for standalone type_extension rule, preventing
bodyless type definitions (e.g. [<Measure>] type Cent) from being
parsed as type extensions that greedily consume following declarations.

Record and union type definitions retain support for members both with
and without the 'with' keyword via type_extension_elements.

* fix: improve member signature type parsing for tuples and curried types

Add _argument_type and _curried_return_type type subsets to correctly
parse member signatures. Before this fix, `string -> string * string`
in a member signature would incorrectly parse `*` as part of a tuple
argument type rather than a tuple return type.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* feat: add srtp_call_expression for statically resolved type parameters

Port of PR #171 - adds srtp_call_expression rule for parsing SRTP
trait member invocations like (^T : (member Method : ...) arg).
Uses restricted _srtp_type_argument matching only ^-prefixed type
params to avoid conflicts with char literals.

* feat: add type_declaration for bare type definitions and TYPE_DECL_NEWLINE scanner token

Port of PR #172 - adds type_declaration rule for bodyless type
definitions (e.g. [<Measure>] type Dollars). Uses a new
TYPE_DECL_NEWLINE external scanner token that fires at newline/EOF
when the next non-blank line is not more indented, disambiguating
bare declarations from types with bodies.

Note: measure_op_type was omitted as the existing measure/
measure_quotient rules already handle A/B division in type contexts.

* Add let...in expression support via external _in token and _expression_block_for_let

* Add hex escape support (\xNN) in character and string literals

* fix: resolve 5 parser bugs in scanner and grammar

Scanner fixes (common/scanner.h):
- Bug 1: 'begin' keyword check no longer corrupts state for identifier 'b'
- Bug 2: '@' operator on continuation line no longer produces zero-width ERROR
- Bug 3: Trailing semicolon in array comprehension no longer breaks parsing

Grammar fixes (fsharp/grammar.js):
- Bug 4: '..' range operator now works in multi-line [| |] and [ ] arrays/lists
  by adding optional(_newline) before _comp_or_range_expression and slice_ranges
- Bug 5: [<assembly:...>] attributes followed by bare expressions like () now
  parse correctly via new _attribute_expression rule in _module_elem

All 422 tests pass with no regressions. Parser.c size unchanged (~60MB).

* fix: regenerate fsharp_signature parser and remove unnecessary conflict

- Regenerated fsharp_signature parser (inherits from fsharp/grammar.js
  which was modified but signature parser was not regenerated)
- Removed unnecessary conflict entry [preproc_if, preproc_if_in_expression]
  eliminating the tree-sitter generate warning

---------

Co-authored-by: alex darch <alex.darch@btinternet.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

2 participants