|
|
|
@ -17,8 +17,14 @@ module.exports = grammar({
|
|
|
|
$.import,
|
|
|
|
$.import,
|
|
|
|
$.public_constant,
|
|
|
|
$.public_constant,
|
|
|
|
$.constant
|
|
|
|
$.constant
|
|
|
|
|
|
|
|
/* $.external_type, */
|
|
|
|
|
|
|
|
/* $.external_function, */
|
|
|
|
|
|
|
|
/* $._public_extenal_type_or_function, */
|
|
|
|
|
|
|
|
/* $.function, */
|
|
|
|
|
|
|
|
/* $.public_function, */
|
|
|
|
/* $.type, */
|
|
|
|
/* $.type, */
|
|
|
|
/* $.function */
|
|
|
|
/* $.public_opaque_type, */
|
|
|
|
|
|
|
|
/* $.public_type */
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
/* Target groups */
|
|
|
|
/* Target groups */
|
|
|
|
@ -69,37 +75,101 @@ module.exports = grammar({
|
|
|
|
seq(
|
|
|
|
seq(
|
|
|
|
"const",
|
|
|
|
"const",
|
|
|
|
field("name", alias($._name, $.identifier)),
|
|
|
|
field("name", alias($._name, $.identifier)),
|
|
|
|
optional($._const_type_annotation),
|
|
|
|
optional($._constant_type_annotation),
|
|
|
|
"=",
|
|
|
|
"=",
|
|
|
|
field("value", $._literal)
|
|
|
|
field("value", $._constant_value)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
|
|
|
|
_constant_value: ($) =>
|
|
|
|
|
|
|
|
choice(
|
|
|
|
|
|
|
|
$.string,
|
|
|
|
|
|
|
|
$.float,
|
|
|
|
|
|
|
|
$.integer,
|
|
|
|
|
|
|
|
alias($._constant_tuple, $.tuple),
|
|
|
|
|
|
|
|
alias($._constant_list, $.list),
|
|
|
|
|
|
|
|
alias($._constant_bit_string, $.bit_string),
|
|
|
|
|
|
|
|
alias($._constant_record, $.record),
|
|
|
|
|
|
|
|
alias($._constant_remote_record, $.remote_record)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
_constant_tuple: ($) =>
|
|
|
|
|
|
|
|
seq("#", "(", series_of($._constant_value, ","), ")"),
|
|
|
|
|
|
|
|
_constant_list: ($) => seq("[", series_of($._constant_value, ","), "]"),
|
|
|
|
|
|
|
|
_constant_bit_string: ($) =>
|
|
|
|
|
|
|
|
seq(
|
|
|
|
|
|
|
|
"<<",
|
|
|
|
|
|
|
|
optional(
|
|
|
|
|
|
|
|
series_of(
|
|
|
|
|
|
|
|
alias($._constant_bit_string_segment, $.bit_string_segment),
|
|
|
|
|
|
|
|
","
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
">>"
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
_constant_bit_string_segment: ($) =>
|
|
|
|
|
|
|
|
seq(
|
|
|
|
|
|
|
|
field("value", $._constant_value),
|
|
|
|
|
|
|
|
optional(
|
|
|
|
|
|
|
|
field(
|
|
|
|
|
|
|
|
"options",
|
|
|
|
|
|
|
|
seq(
|
|
|
|
|
|
|
|
":",
|
|
|
|
|
|
|
|
alias(
|
|
|
|
|
|
|
|
$._constant_bit_string_segment_options,
|
|
|
|
|
|
|
|
$.bit_string_segment_options
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
// This is not an actual node in the Gleam AST. It only exists to allow me
|
|
|
|
|
|
|
|
// to group the segment options together into their own list.
|
|
|
|
|
|
|
|
_constant_bit_string_segment_options: ($) =>
|
|
|
|
|
|
|
|
series_of($._constant_bit_string_segment_option, "-"),
|
|
|
|
|
|
|
|
_constant_bit_string_segment_option: ($) =>
|
|
|
|
|
|
|
|
choice(
|
|
|
|
|
|
|
|
$._constant_bit_string_named_segment_option,
|
|
|
|
|
|
|
|
alias($.integer, $.constant_int)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
_constant_bit_string_named_segment_option: ($) =>
|
|
|
|
|
|
|
|
choice(
|
|
|
|
|
|
|
|
$._bit_string_segment_option_unit,
|
|
|
|
|
|
|
|
$._constant_bit_string_segment_option_size,
|
|
|
|
|
|
|
|
$._bit_string_segment_option_literal
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
_constant_bit_string_segment_option_size: ($) =>
|
|
|
|
|
|
|
|
seq("size", "(", alias($.integer, $.bit_string_segment_option_size), ")"),
|
|
|
|
|
|
|
|
_constant_record: ($) =>
|
|
|
|
|
|
|
|
seq(
|
|
|
|
|
|
|
|
$._upname,
|
|
|
|
|
|
|
|
optional(
|
|
|
|
|
|
|
|
seq(
|
|
|
|
|
|
|
|
"(",
|
|
|
|
|
|
|
|
optional(
|
|
|
|
|
|
|
|
series_of(alias($._constant_record_arg, $.record_arg), ",")
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
")"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
_constant_record_arg: ($) =>
|
|
|
|
|
|
|
|
seq($._name, optional(seq(":", $._constant_value))),
|
|
|
|
|
|
|
|
_constant_remote_record: ($) => seq($._name, ".", $._constant_record),
|
|
|
|
|
|
|
|
|
|
|
|
/* Special constant types */
|
|
|
|
/* Special constant types */
|
|
|
|
_const_type_annotation: ($) => seq(":", field("type", $._const_type)),
|
|
|
|
_constant_type_annotation: ($) => seq(":", field("type", $._constant_type)),
|
|
|
|
_const_type: ($) =>
|
|
|
|
_constant_type: ($) =>
|
|
|
|
choice(
|
|
|
|
choice(
|
|
|
|
$.type_hole,
|
|
|
|
$.type_hole,
|
|
|
|
alias($.const_tuple_type, $.tuple_type),
|
|
|
|
alias($.constant_tuple_type, $.tuple_type),
|
|
|
|
alias($.const_fn_type, $.fn_type),
|
|
|
|
alias($.constant_type_constructor, $.type_constructor),
|
|
|
|
alias($.const_type_constructor, $.type_constructor),
|
|
|
|
alias($.constant_remote_type_constructor, $.remote_type_constructor)
|
|
|
|
alias($.const_remote_type_constructor, $.remote_type_constructor)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
constant_tuple_type: ($) =>
|
|
|
|
const_tuple_type: ($) =>
|
|
|
|
seq("#", "(", optional(series_of($._constant_type, ",")), ")"),
|
|
|
|
seq("#", "(", optional(series_of($._const_type, ",")), ")"),
|
|
|
|
constant_type_constructor: ($) => $._constant_type_constructor,
|
|
|
|
const_fn_type: ($) =>
|
|
|
|
constant_remote_type_constructor: ($) =>
|
|
|
|
seq(
|
|
|
|
seq($._name, ".", $._constant_type_constructor),
|
|
|
|
"fn",
|
|
|
|
_constant_type_constructor: ($) =>
|
|
|
|
"(",
|
|
|
|
seq($._upname, optional(seq("(", series_of($._constant_type, ","), ")"))),
|
|
|
|
series_of(alias($._const_type, $.argument_type), ","),
|
|
|
|
|
|
|
|
")",
|
|
|
|
|
|
|
|
"->",
|
|
|
|
|
|
|
|
alias($._const_type, $.return_type)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
const_type_constructor: ($) => $._const_type_constructor,
|
|
|
|
|
|
|
|
const_remote_type_constructor: ($) =>
|
|
|
|
|
|
|
|
seq($._name, ".", $._const_type_constructor),
|
|
|
|
|
|
|
|
_const_type_constructor: ($) =>
|
|
|
|
|
|
|
|
seq($._upname, optional(seq("(", series_of($._const_type, ","), ")"))),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Literals */
|
|
|
|
/* Literals */
|
|
|
|
_literal: ($) =>
|
|
|
|
_literal: ($) =>
|
|
|
|
@ -109,7 +179,7 @@ module.exports = grammar({
|
|
|
|
$.integer,
|
|
|
|
$.integer,
|
|
|
|
$.tuple,
|
|
|
|
$.tuple,
|
|
|
|
$.list
|
|
|
|
$.list
|
|
|
|
// $.bitstring,
|
|
|
|
// $.bit_string,
|
|
|
|
// $.record,
|
|
|
|
// $.record,
|
|
|
|
// $.remote_record
|
|
|
|
// $.remote_record
|
|
|
|
),
|
|
|
|
),
|
|
|
|
@ -118,6 +188,44 @@ module.exports = grammar({
|
|
|
|
integer: ($) => /-?[0-9_]+/,
|
|
|
|
integer: ($) => /-?[0-9_]+/,
|
|
|
|
tuple: ($) => seq("#", "(", series_of($._literal, ","), ")"),
|
|
|
|
tuple: ($) => seq("#", "(", series_of($._literal, ","), ")"),
|
|
|
|
list: ($) => seq("[", series_of($._literal, ","), "]"),
|
|
|
|
list: ($) => seq("[", series_of($._literal, ","), "]"),
|
|
|
|
|
|
|
|
bit_string: ($) =>
|
|
|
|
|
|
|
|
seq("<<", optional(series_of($.bit_string_segment, ",")), ">>"),
|
|
|
|
|
|
|
|
bit_string_segment: ($) =>
|
|
|
|
|
|
|
|
seq(
|
|
|
|
|
|
|
|
$._literal,
|
|
|
|
|
|
|
|
optional(seq(":", series_of($._bit_string_segment_option, "-")))
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
_bit_string_segment_option: ($) =>
|
|
|
|
|
|
|
|
choice($.bit_string_named_segment_option, alias($.integer, $.size)),
|
|
|
|
|
|
|
|
bit_string_named_segment_option: ($) =>
|
|
|
|
|
|
|
|
choice(
|
|
|
|
|
|
|
|
$._bit_string_segment_option_unit,
|
|
|
|
|
|
|
|
$._bit_string_segment_option_size,
|
|
|
|
|
|
|
|
$._bit_string_segment_option_literal
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
_bit_string_segment_option_unit: ($) =>
|
|
|
|
|
|
|
|
seq("unit", "(", alias($.integer, $.bit_string_segment_option_unit), ")"),
|
|
|
|
|
|
|
|
_bit_string_segment_option_size: ($) => seq("size", "(", $.integer, ")"),
|
|
|
|
|
|
|
|
_bit_string_segment_option_literal: ($) =>
|
|
|
|
|
|
|
|
choice(
|
|
|
|
|
|
|
|
alias("binary", $.bit_string_segment_option_binary),
|
|
|
|
|
|
|
|
alias("bytes", $.bit_string_segment_option_binary),
|
|
|
|
|
|
|
|
alias("int", $.bit_string_segment_option_int),
|
|
|
|
|
|
|
|
alias("float", $.bit_string_segment_option_float),
|
|
|
|
|
|
|
|
alias("bit_string", $.bit_string_segment_option_bit_string),
|
|
|
|
|
|
|
|
alias("bits", $.bit_string_segment_option_bit_string),
|
|
|
|
|
|
|
|
alias("utf8", $.bit_string_segment_option_utf8),
|
|
|
|
|
|
|
|
alias("utf16", $.bit_string_segment_option_utf16),
|
|
|
|
|
|
|
|
alias("utf32", $.bit_string_segment_option_utf32),
|
|
|
|
|
|
|
|
alias("utf8_codepoint", $.bit_string_segment_option_utf8_codepoint),
|
|
|
|
|
|
|
|
alias("utf16_codepoint", $.bit_string_segment_option_utf16_codepoint),
|
|
|
|
|
|
|
|
alias("utf32_codepoint", $.bit_string_segment_option_utf32_codepoint),
|
|
|
|
|
|
|
|
alias("signed", $.bit_string_segment_option_signed),
|
|
|
|
|
|
|
|
alias("unsigned", $.bit_string_segment_option_unsigned),
|
|
|
|
|
|
|
|
alias("big", $.bit_string_segment_option_big),
|
|
|
|
|
|
|
|
alias("little", $.bit_string_segment_option_little),
|
|
|
|
|
|
|
|
alias("native", $.bit_string_segment_option_native)
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
|
|
/* Types */
|
|
|
|
/* Types */
|
|
|
|
type_var: ($) => $._name,
|
|
|
|
type_var: ($) => $._name,
|
|
|
|
|