Skip to content

Conversation

@0xGeorgii
Copy link
Contributor

@0xGeorgii 0xGeorgii commented Aug 10, 2025

Description

Apart from internal grammar improvements, this PR changes the way of defining generics. The reason is to get rid of ambiguity using < and > symbols in

  1. Comparison operators
  2. Bit shift operators

Generic parameters definition

Was: fn foo<A>() -> i32
Now: fn foo A' () -> i32

Similarly with types

Was: struct Vector<T>
Now: struct Vector T'

Access to generalized type functions

Was: Vector<i32>::new()
Now: (Vector i32')::new()

What's new

Now, the angle brackets are not a part of the generic syntax definition. Instead, we use a list of names with a prime suffix.

Comments are not separated from Docstrings

  • // is a comment
  • /// is a docstring

- Changed generic function syntax from `fn func<T>(x: T) -> T` to `fn func T' (x: T) -> T`.
- Updated member access expressions to type member access expressions in various files.
- Modified array initialization syntax to align with new type member access conventions.
- Adjusted variable definitions to use the new syntax for non-primitive types.
- Added a new parser and library files for inference functionality.
… multiple files

- Updated comment syntax from `///` to `//` in various function definitions and specifications.
- Removed unnecessary operators in the grammar specifications for function definitions, variable declarations, and expressions.
- Cleaned up the structure of the code to improve readability and maintainability.
- Ensured consistency in the representation of variable assignments and function definitions in the specification files.
@0xGeorgii 0xGeorgii self-assigned this Aug 10, 2025
@0xGeorgii 0xGeorgii requested a review from Copilot August 10, 2025 10:52
Copy link

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

This pull request changes the generics syntax from angle brackets (<>) to a postfix apostrophe (') notation and updates various language constructs to improve consistency and readability.

  • Changes generic syntax from Array<T> to Array T' format
  • Removes unnecessary operator tokens (function_keyword, assign_operator, etc.) in favor of direct string literals
  • Updates comment syntax from /// (docstring) to // (regular comments) in test files
  • Modernizes tree-sitter grammar structure and node definitions

Reviewed Changes

Copilot reviewed 30 out of 35 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
grammar.js Core grammar changes implementing new generics syntax and removing operator tokens
src/grammar.json Generated grammar JSON reflecting the new syntax rules
src/node-types.json Updated node type definitions for the new grammar structure
test/corpus/*.txt Test corpus files updated to reflect new generics and comment syntax
queries/highlights.scm Updated syntax highlighting for new function keyword handling
package.json Updated dependencies to newer versions
example.inf Example file demonstrating the new syntax
Comments suppressed due to low confidence (1)

test/corpus/expressions/binary.txt:115

  • The parentheses around generic types in member access expressions (Array u32')::new() creates visual inconsistency. The syntax should be standardized - either always require parentheses for generics in member access or find an alternative approach.
              (number_literal)

…o 'tree_sitter_inference' in header files and related configurations
…o 'tree_sitter_inference' in header files and related configurations
@Inferara Inferara deleted a comment from Copilot AI Aug 10, 2025
@Inferara Inferara deleted a comment from Copilot AI Aug 10, 2025
@Inferara Inferara deleted a comment from Copilot AI Aug 10, 2025
@Inferara Inferara deleted a comment from Copilot AI Aug 10, 2025
@Inferara Inferara deleted a comment from Copilot AI Aug 10, 2025
@Keyholder
Copy link

I agree with general idea - overuse of < and > is pain in the ass for readability, in my opinion. But I'm curious, how does this syntax look, when there is more then one type parameter?

@0xGeorgii
Copy link
Contributor Author

0xGeorgii commented Aug 10, 2025

Thanks for the question fn foo T' V' () -> ... e.g. A list of names with a prime as a suffix.

@0xGeorgii 0xGeorgii merged commit 4b92899 into main Aug 15, 2025
4 checks passed
@0xGeorgii 0xGeorgii deleted the change-generics-syntax branch August 15, 2025 12:06
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.

3 participants