Skip to content

Commit

Permalink
refactor: simplify grammar for in/!in and is/!is
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Mar 31, 2024
1 parent 671fce5 commit c8346f4
Show file tree
Hide file tree
Showing 8 changed files with 198,540 additions and 209,979 deletions.
9 changes: 2 additions & 7 deletions src/analyzer/psi/TypeInferer.v
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,7 @@ pub fn (t &TypeInferer) infer_type_impl(elem ?PsiElement) types.Type {

mut visited := map[string]types.Type{}

if element.node.type_name in [
.in_expression,
.not_in_expression,
.is_expression,
.not_is_expression,
] {
if element.node.type_name in [.in_expression, .is_expression] {
return types.new_primitive_type('bool')
}

Expand Down Expand Up @@ -932,7 +927,7 @@ pub fn (t &TypeInferer) infer_context_type(elem ?PsiElement) types.Type {
}

bin_expr := parent.parent() or { return types.unknown_type }
if bin_expr.element_type() in [.binary_expression, .in_expression, .not_in_expression] {
if bin_expr.element_type() in [.binary_expression, .in_expression] {
left := bin_expr.first_child_or_stub() or { return types.unknown_type }
if left.is_parent_of(parent) {
return types.unknown_type
Expand Down
6 changes: 0 additions & 6 deletions tree_sitter_v/bindings/node_types.v
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ pub enum NodeType {
mutability_modifiers
mutable_expression
mutable_identifier
not_in_expression
not_is_expression
option_propagation_expression
option_type
or_block
Expand Down Expand Up @@ -202,8 +200,6 @@ const supertype__expression_nodes = merge(supertype__expression_with_blocks_node
.index_expression,
.is_expression,
.literal,
.not_in_expression,
.not_is_expression,
.option_propagation_expression,
.or_block_expression,
.parenthesized_expression,
Expand Down Expand Up @@ -422,8 +418,6 @@ const node_type_name_to_enum = {
'mutability_modifiers': NodeType.mutability_modifiers
'mutable_expression': NodeType.mutable_expression
'mutable_identifier': NodeType.mutable_identifier
'not_in_expression': NodeType.not_in_expression
'not_is_expression': NodeType.not_is_expression
'option_propagation_expression': NodeType.option_propagation_expression
'option_type': NodeType.option_type
'or_block': NodeType.or_block
Expand Down
23 changes: 2 additions & 21 deletions tree_sitter_v/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ module.exports = grammar({
[$.fixed_array_type, $.literal],
[$.reference_expression, $.type_reference_expression],
[$.is_expression],
[$.not_is_expression],
[$._type_union_list],
[$._expression_without_blocks, $.element_list],
],
Expand Down Expand Up @@ -437,9 +436,7 @@ module.exports = grammar({
$.receive_expression,
$.binary_expression,
$.is_expression,
$.not_is_expression,
$.in_expression,
$.not_in_expression,
$.index_expression,
$.slice_expression,
$.as_type_cast_expression,
Expand Down Expand Up @@ -748,31 +745,15 @@ module.exports = grammar({
2,
seq(
field('left', seq(optional($.mutability_modifiers), $._expression)),
'is',
field('right', $.plain_type),
),
),

not_is_expression: ($) =>
prec.dynamic(
2,
seq(
field('left', seq(optional($.mutability_modifiers), $._expression)),
'!is',
choice('is', '!is'),
field('right', $.plain_type),
),
),

in_expression: ($) =>
prec.left(
PREC.comparative,
seq(field('left', $._expression), 'in', field('right', $._expression)),
),

not_in_expression: ($) =>
prec.left(
PREC.comparative,
seq(field('left', $._expression), '!in', field('right', $._expression)),
seq(field('left', $._expression), choice('in', '!in'), field('right', $._expression)),
),

enum_fetch: ($) => prec.dynamic(-1, seq('.', $.reference_expression)),
Expand Down
112 changes: 22 additions & 90 deletions tree_sitter_v/src/grammar.json

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

80 changes: 0 additions & 80 deletions tree_sitter_v/src/node-types.json

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

Loading

0 comments on commit c8346f4

Please sign in to comment.