generalize bit string option node (#22)

* generalize bit string option node
* highlight bit-string options as function.builtin
pull/204/head
Michael Davis 2022-03-11 13:16:12 +07:00 committed by GitHub
parent 1a9e736304
commit 11d78be28e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 40 deletions

@ -588,27 +588,26 @@ module.exports = grammar({
_decimal: ($) => /[0-9][0-9_]*/, _decimal: ($) => /[0-9][0-9_]*/,
_octal: ($) => /0[oO][0-7_]+/, _octal: ($) => /0[oO][0-7_]+/,
_binary: ($) => /0[bB][0-1_]+/, _binary: ($) => /0[bB][0-1_]+/,
_bit_string_segment_option_unit: ($) => _bit_string_segment_option: ($) =>
seq("unit", "(", alias($.integer, $.bit_string_segment_option_unit), ")"),
_bit_string_segment_option_literal: ($) =>
choice( choice(
alias("binary", $.bit_string_segment_option_binary), "binary",
alias("bytes", $.bit_string_segment_option_binary), "bytes",
alias("int", $.bit_string_segment_option_int), "int",
alias("float", $.bit_string_segment_option_float), "float",
alias("bit_string", $.bit_string_segment_option_bit_string), "bit_string",
alias("bits", $.bit_string_segment_option_bit_string), "bits",
alias("utf8", $.bit_string_segment_option_utf8), "utf8",
alias("utf16", $.bit_string_segment_option_utf16), "utf16",
alias("utf32", $.bit_string_segment_option_utf32), "utf32",
alias("utf8_codepoint", $.bit_string_segment_option_utf8_codepoint), "utf8_codepoint",
alias("utf16_codepoint", $.bit_string_segment_option_utf16_codepoint), "utf16_codepoint",
alias("utf32_codepoint", $.bit_string_segment_option_utf32_codepoint), "utf32_codepoint",
alias("signed", $.bit_string_segment_option_signed), "signed",
alias("unsigned", $.bit_string_segment_option_unsigned), "unsigned",
alias("big", $.bit_string_segment_option_big), "big",
alias("little", $.bit_string_segment_option_little), "little",
alias("native", $.bit_string_segment_option_native) "native",
seq("unit", "(", $.integer, ")")
), ),
/* Types */ /* Types */
@ -710,18 +709,15 @@ function bit_string_segment_options(name, arg_parser) {
[`_${name}_bit_string_segment_option`]: ($) => [`_${name}_bit_string_segment_option`]: ($) =>
choice($[`_${name}_bit_string_named_segment_option`], $.integer), choice($[`_${name}_bit_string_named_segment_option`], $.integer),
[`_${name}_bit_string_named_segment_option`]: ($) => [`_${name}_bit_string_named_segment_option`]: ($) =>
choice( alias(
$._bit_string_segment_option_unit, choice(
$[`_${name}_bit_string_segment_option_size`], $._bit_string_segment_option,
$._bit_string_segment_option_literal $[`_${name}_bit_string_segment_option_size`]
),
$.bit_string_segment_option
), ),
[`_${name}_bit_string_segment_option_size`]: ($) => [`_${name}_bit_string_segment_option_size`]: ($) =>
seq( seq("size", "(", $[arg_parser], ")"),
"size",
"(",
alias($[arg_parser], $.bit_string_segment_option_size),
")"
),
}; };
} }

@ -47,6 +47,7 @@
; Literals ; Literals
(string) @string (string) @string
(bit_string_segment_option) @function.builtin
(integer) @number (integer) @number
(float) @number (float) @number
@ -84,6 +85,8 @@
"]" "]"
"{" "{"
"}" "}"
"<<"
">>"
] @punctuation.bracket ] @punctuation.bracket
[ [
"." "."
@ -94,4 +97,5 @@
"=" "="
"->" "->"
".." ".."
"-"
] @punctuation.delimiter ] @punctuation.delimiter

@ -121,15 +121,18 @@ const a: option.Option(String) = option.Some("Hello, World!")
(bit_string_segment (bit_string_segment
value: (integer) value: (integer)
options: (bit_string_segment_options options: (bit_string_segment_options
(bit_string_segment_option_size))))) (bit_string_segment_option
(integer))))))
(constant (constant
name: (identifier) name: (identifier)
value: (bit_string value: (bit_string
(bit_string_segment (bit_string_segment
value: (integer) value: (integer)
options: (bit_string_segment_options options: (bit_string_segment_options
(bit_string_segment_option_size) (bit_string_segment_option
(bit_string_segment_option_unit))))) (integer))
(bit_string_segment_option
(integer))))))
(constant (constant
name: (identifier) name: (identifier)
value: (bit_string value: (bit_string
@ -137,7 +140,7 @@ const a: option.Option(String) = option.Some("Hello, World!")
value: (string value: (string
(quoted_content)) (quoted_content))
options: (bit_string_segment_options options: (bit_string_segment_options
(bit_string_segment_option_utf8))))) (bit_string_segment_option)))))
(constant (constant
name: (identifier) name: (identifier)
value: (record value: (record
@ -308,7 +311,8 @@ pub const a = uri.Uri(host: "github.com")
(bit_string_segment (bit_string_segment
value: (integer) value: (integer)
options: (bit_string_segment_options options: (bit_string_segment_options
(bit_string_segment_option_size))))) (bit_string_segment_option
(integer))))))
(constant (constant
(visibility_modifier) (visibility_modifier)
name: (identifier) name: (identifier)
@ -316,8 +320,10 @@ pub const a = uri.Uri(host: "github.com")
(bit_string_segment (bit_string_segment
value: (integer) value: (integer)
options: (bit_string_segment_options options: (bit_string_segment_options
(bit_string_segment_option_size) (bit_string_segment_option
(bit_string_segment_option_unit))))) (integer))
(bit_string_segment_option
(integer))))))
(constant (constant
(visibility_modifier) (visibility_modifier)
name: (identifier) name: (identifier)
@ -326,7 +332,7 @@ pub const a = uri.Uri(host: "github.com")
value: (string value: (string
(quoted_content)) (quoted_content))
options: (bit_string_segment_options options: (bit_string_segment_options
(bit_string_segment_option_utf8))))) (bit_string_segment_option)))))
(constant (constant
(visibility_modifier) (visibility_modifier)
name: (identifier) name: (identifier)

@ -764,11 +764,11 @@ fn try_try_again(x, y) -> Int {
(bit_string_segment (bit_string_segment
value: (identifier) value: (identifier)
options: (bit_string_segment_options options: (bit_string_segment_options
(bit_string_segment_option_utf8))) (bit_string_segment_option)))
(bit_string_segment (bit_string_segment
value: (identifier) value: (identifier)
options: (bit_string_segment_options options: (bit_string_segment_options
(bit_string_segment_option_size (bit_string_segment_option
(integer))))) (integer)))))
value: (todo)) value: (todo))
(try (try

@ -0,0 +1,27 @@
fn bit_strings() {
<<3>>
// <- punctuation.bracket
//^ number
// ^ punctuation.bracket
<<3:8>>
//^ number
// ^ punctuation.delimiter
// ^ number
<<3:size(8)>>
//^ number
// ^ punctuation.delimiter
// ^ function.builtin
// ^ punctuation.bracket
// ^ number
// ^ punctuation.bracket
<<code:int-size(8)-unit(2), reason:utf8>>
// ^ variable
// ^ function.builtin
// ^ punctuation.delimiter
// ^ function.builtin
// ^ number
// ^ function.builtin
// ^ number
// ^ variable
// ^ function.builtin
}