struct type construction
This commit is contained in:
@@ -33,9 +33,8 @@ module.exports = grammar({
|
||||
[$.array_type, $.expression],
|
||||
[$.array_type, $.array_literal],
|
||||
[$.expression_statement, $.parenthesized_expression],
|
||||
[$.block, $.tuple_literal],
|
||||
[$.block, $.tuple_literal, $.anonymous_record_literal],
|
||||
[$.field_initializer, $.expression],
|
||||
[$.tuple_literal],
|
||||
[$.capture_list, $.expression],
|
||||
[$.match_capture, $.expression],
|
||||
],
|
||||
@@ -188,6 +187,7 @@ module.exports = grammar({
|
||||
|
||||
_type_atom: $ => choice(
|
||||
$.builtin_type,
|
||||
$.intrinsic_type,
|
||||
$.named_type,
|
||||
$.optional_type,
|
||||
$.pointer_type,
|
||||
@@ -198,9 +198,11 @@ module.exports = grammar({
|
||||
|
||||
parenthesized_type: $ => seq('(', repeat($._newline), $.type, repeat($._newline), ')'),
|
||||
|
||||
named_type: $ => prec.right(seq(
|
||||
$.qualified_identifier,
|
||||
optional($.argument_list),
|
||||
named_type: $ => prec.right(seq($.qualified_identifier, optional($.argument_list))),
|
||||
|
||||
intrinsic_type: $ => prec(PREC.POSTFIX, seq(
|
||||
field('function', alias('struct_type!', $.identifier)),
|
||||
field('arguments', $.argument_list),
|
||||
)),
|
||||
|
||||
optional_type: $ => seq('?', $.type),
|
||||
@@ -441,6 +443,7 @@ module.exports = grammar({
|
||||
$.slice_expression,
|
||||
$.postfix_expression,
|
||||
$.struct_literal,
|
||||
$.anonymous_record_literal,
|
||||
$.tuple_literal,
|
||||
$.comptime_block,
|
||||
$.function_literal,
|
||||
@@ -556,17 +559,27 @@ module.exports = grammar({
|
||||
),
|
||||
|
||||
field_initializer: $ => seq(
|
||||
field('name', $.identifier),
|
||||
field('name', $._field_name),
|
||||
optional(seq('=', repeat($._newline), field('value', $.expression))),
|
||||
),
|
||||
|
||||
anonymous_record_literal: $ => prec(2, seq(
|
||||
'{',
|
||||
repeat($._newline),
|
||||
$.keyed_field_initializer,
|
||||
repeat(seq(repeat($._newline), ',', repeat($._newline), $.keyed_field_initializer)),
|
||||
optional(seq(repeat($._newline), ',')),
|
||||
repeat($._newline),
|
||||
'}',
|
||||
)),
|
||||
|
||||
tuple_literal: $ => prec(1, choice(
|
||||
seq('{', repeat($._newline), '}'),
|
||||
seq(
|
||||
'{', repeat($._newline), $.expression,
|
||||
',', repeat($._newline),
|
||||
repeat(seq($.expression, ',', repeat($._newline))),
|
||||
optional($.expression), repeat($._newline), '}',
|
||||
repeat(seq(repeat($._newline), ',', repeat($._newline), $.expression)),
|
||||
optional(seq(repeat($._newline), ',')),
|
||||
repeat($._newline), '}',
|
||||
),
|
||||
)),
|
||||
|
||||
@@ -597,7 +610,7 @@ module.exports = grammar({
|
||||
),
|
||||
|
||||
keyed_field_initializer: $ => seq(
|
||||
field('name', $.identifier),
|
||||
field('name', $._field_name),
|
||||
'=',
|
||||
repeat($._newline),
|
||||
field('value', $.expression),
|
||||
@@ -635,6 +648,23 @@ module.exports = grammar({
|
||||
undefined: _ => 'undefined',
|
||||
sink: _ => '_',
|
||||
|
||||
_field_name: $ => prec(2, choice(
|
||||
$.identifier,
|
||||
alias(choice(
|
||||
'test', 'func', 'c_func', 'struct', 'c_struct', 'opaque', 'union', 'enum',
|
||||
'distinct', 'alias', 'import', 'hide', 'return', 'try', 'catch', 'mut',
|
||||
'none', 'undefined', 'orelse', 'and', 'or', 'xor', 'if', 'while', 'for',
|
||||
'expand', 'break', 'continue', 'defer', 'errdefer', 'yield', 'match', 'else',
|
||||
'true', 'false',
|
||||
'void', 'type', 'anyopaque', 'bool', 'int', 'uint', 'float', 'range',
|
||||
'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64',
|
||||
'isize', 'usize', 'f32', 'f64',
|
||||
'c_char', 'c_schar', 'c_uchar', 'c_short', 'c_ushort',
|
||||
'c_int', 'c_uint', 'c_long', 'c_ulong', 'c_longlong',
|
||||
'c_ulonglong', 'c_float', 'c_double', 'c_longdouble',
|
||||
), $.identifier),
|
||||
)),
|
||||
|
||||
identifier: _ => /[A-Za-z_][A-Za-z0-9_]*/,
|
||||
integer: _ => /[0-9]+/,
|
||||
float: _ => token(prec(1, /[0-9]+\.[0-9]+/)),
|
||||
|
||||
Reference in New Issue
Block a user