8000 [tree_sitter_v] fix struct field (#74) · v-analyzer/v-analyzer@a939c6f · GitHub
[go: up one dir, main page]

Skip to content

Commit

Permalink
[tree_sitter_v] fix struct field (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lycs-D authored Dec 13, 2023
1 parent 320101b commit a939c6f
Show file tree
Hide file tree
Showing 10 changed files with 203,431 additions and 203,485 deletions.
47 changes: 16 additions & 31 deletions tree_sitter_v/grammar.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ const PREC = {
or: 1,
resolve: 1,
composite_literal: -1,
empty_array: -2,
strictly_expression_list: -3,
};

Expand Down Expand Up @@ -144,7 +143,7 @@ module.exports = grammar({
inline: ($) => [
$._string_literal,
$._top_level_declaration,
$._non_empty_array,
$._array,
],

supertypes: ($) => [
Expand Down Expand Up @@ -383,14 +382,16 @@ module.exports = grammar({
$._struct_body,
),

_struct_body: ($) => seq("{", optional($._struct_fields), "}"),

_struct_fields: ($) =>
repeat1(
choice(
seq($.struct_field_scope, optional(terminator)),
seq($.struct_field_declaration, optional(terminator)),
_struct_body: ($) =>
seq(
"{",
repeat(
choice(
seq($.struct_field_scope, optional(terminator)),
seq($.struct_field_declaration, optional(terminator)),
),
),
"}",
),

// pub:
Expand All @@ -409,8 +410,8 @@ module.exports = grammar({
seq(
field("name", $.identifier),
field("type", $.plain_type),
optional(field("attributes", $.attribute)),
optional(seq("=", field("default_value", $._expression))),
optional(field("attributes", $.attribute)),
),
),

Expand Down Expand Up @@ -484,11 +485,9 @@ module.exports = grammar({
$.spawn_expression,
$.call_expression,
$.function_literal,
$.empty_literal_value,
$.reference_expression,
$._max_group,
$.array_creation,
$.empty_array_creation,
$.fixed_array_creation,
$.unary_expression,
$.receive_expression,
Expand All @@ -499,7 +498,6 @@ module.exports = grammar({
$.not_in_expression,
$.index_expression,
$.slice_expression,
// $.type_cast_expression,
$.as_type_cast_expression,
$.selector_expression,
$.enum_fetch,
Expand Down Expand Up @@ -715,14 +713,6 @@ module.exports = grammar({

as_type_cast_expression: ($) => seq($._expression, "as", $.plain_type),

type_cast_expression: ($) =>
seq(
field("type", $.plain_type),
"(",
field("operand", $._expression),
")",
),

compile_time_selector_expression: ($) =>
comp_time(
seq("(", choice($.reference_expression, $.selector_expression), ")"),
Expand Down Expand Up @@ -779,24 +769,21 @@ module.exports = grammar({
PREC.composite_literal,
seq(
"{",
repeat1(seq($.map_keyed_element, optional(list_separator))),
repeat(seq($.map_keyed_element, optional(list_separator))),
"}",
),
),

map_keyed_element: ($) =>
seq(field("key", $._expression), ":", field("value", $._expression)),

array_creation: ($) => prec.right(PREC.multiplicative, $._non_empty_array),

empty_array_creation: () =>
prec(PREC.empty_array, prec.dynamic(-1, seq("[", "]"))),
array_creation: ($) => prec.right(PREC.multiplicative, $._array),

fixed_array_creation: ($) =>
prec.right(PREC.multiplicative, seq($._non_empty_array, "!")),
prec.right(PREC.multiplicative, seq($._array, "!")),

_non_empty_array: ($) =>
seq("[", repeat1(seq($._expression, optional(","))), "]"),
_array: ($) =>
seq("[", repeat(seq($._expression, optional(","))), "]"),

selector_expression: ($) =>
prec.dynamic(
Expand Down Expand Up @@ -1126,8 +1113,6 @@ module.exports = grammar({
expression_without_blocks_list: ($) =>
prec(PREC.resolve, comma_sep1($._expression_without_blocks)),

empty_literal_value: () => prec(PREC.composite_literal, seq("{", "}")),

// ==================== TYPES ====================

plain_type: ($) =>
Expand Down
6 changes: 0 additions & 6 deletions tree_sitter_v/node_types.v
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ pub enum NodeType {
element_list
else_branch
embedded_definition
empty_array_creation
empty_literal_value
enum_backed_type
enum_declaration
enum_fetch
Expand Down Expand Up @@ -194,8 +192,6 @@ const supertype__expression_nodes = merge(supertype__expression_with_blocks_node
.binary_expression,
.call_expression,
.dec_expression,
.empty_array_creation,
.empty_literal_value,
.enum_fetch,
.fixed_array_creation,
.function_literal,
Expand Down Expand Up @@ -366,8 +362,6 @@ const node_type_name_to_enum = {
'element_list': NodeType.element_list
'else_branch': NodeType.else_branch
'embedded_definition': NodeType.embedded_definition
'empty_array_creation': NodeType.empty_array_creation
'empty_literal_value': NodeType.empty_literal_value
'enum_backed_type': NodeType.enum_backed_type
'enum_declaration': NodeType.enum_declaration
'enum_fetch': NodeType.enum_fetch
Expand Down
Loading

0 comments on commit a939c6f

Please sign in to comment.
0