Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ dist/
# Grammar volatiles
*.wasm
*.obj
*.o
*.o

.*/
!.github/
*.md
!README.md
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-inference"
description = "Inference grammar for tree-sitter"
version = "0.0.37"
version = "0.0.38"
authors = [
"Georgii Plotnikov <accembler@gmail.com>"
]
Expand Down
2 changes: 1 addition & 1 deletion Makefile

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 25 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ module.exports = grammar({
$.struct_definition,
),

visibility: _ => 'pub',

_type: $ => choice(
$._embedded_type,
$._bracketed_generic_name,
Expand Down Expand Up @@ -261,7 +263,11 @@ module.exports = grammar({
)),

prefix_unary_expression: $ => prec(PRECEDENCE.UNARY, seq(
field('operator', $.unary_not),
field('operator', choice(
$.unary_not,
$.unary_minus,
$.unary_bitnot,
)),
$._expression,
)),

Expand All @@ -282,6 +288,7 @@ module.exports = grammar({
['+', PRECEDENCE.ADD],
['-', PRECEDENCE.ADD],
['*', PRECEDENCE.MUL],
['/', PRECEDENCE.MUL],
['%', PRECEDENCE.MUL],
['<', PRECEDENCE.COMPARE],
['<=', PRECEDENCE.COMPARE],
Expand Down Expand Up @@ -309,6 +316,7 @@ module.exports = grammar({
),

type_definition_statement: $ => seq(
optional(field('visibility', $.visibility)),
'type',
field('name', $.identifier),
'=',
Expand All @@ -317,6 +325,7 @@ module.exports = grammar({
),

constant_definition: $ => seq(
optional(field('visibility', $.visibility)),
'const',
field('name', $.identifier),
':',
Expand All @@ -335,6 +344,7 @@ module.exports = grammar({
),

enum_definition: $ => seq(
optional(field('visibility', $.visibility)),
'enum',
field('name', $.identifier),
'{',
Expand All @@ -343,12 +353,13 @@ module.exports = grammar({
),

struct_definition: $ => seq(
optional(field('visibility', $.visibility)),
'struct',
field('name', $.identifier),
'{',
repeat(choice(
seq(field('field', $.struct_field), ';'),
field('value', $.function_definition),
field('method', $.function_definition),
)),
'}',
),
Expand All @@ -366,6 +377,7 @@ module.exports = grammar({
),

function_definition: $ => seq(
optional(field('visibility', $.visibility)),
'fn',
field('name', $.identifier),
optional(field('type_parameters', $.type_argument_list_definition)),
Expand Down Expand Up @@ -482,6 +494,8 @@ module.exports = grammar({
uzumaki_keyword: _ => '@',
mut_keyword: _ => 'mut',
unary_not: _ => '!',
unary_minus: _ => '-',
unary_bitnot: _ => '~',
bool_literal: _ => choice(
token('true'),
token('false'),
Expand All @@ -495,7 +509,9 @@ module.exports = grammar({

_string_literal_content: _ => token.immediate(prec(1, /[^"\\\n]+/)),

number_literal: _ => seq(optional('-'), /\d+/),
// Higher precedence than UNARY ensures -42 parses as a single number_literal,
// not as unary_minus applied to a positive literal
number_literal: _ => token(prec(PRECEDENCE.UNARY + 1, seq(optional('-'), /\d+/))),

unit_literal: _ => seq('(', token.immediate(')')),

Expand Down Expand Up @@ -551,10 +567,13 @@ module.exports = grammar({
)
)),

// Type argument list - space-separated like definitions
// Note: Nested generics are syntactically valid but rejected at compilation
type_argument_list: $ => prec.left(seq(
choice(
sep1(seq(field('type', $._type), token.immediate('\'')), ','),
),
seq(field('type', $._type), token.immediate('\'')),
repeat(
seq(field('type', $._type), token.immediate('\'')),
)
)),

_reserved_identifier: _ => choice(
Expand Down
Loading
Loading