Skip to content

Commit 7b63f73

Browse files
committed
fix: only let option() match $.command_line_option after the flag
To avoid parsing conflicts, only let `$._key_table` match a single string unit, instead of many written together. This is good enough in practice.
1 parent 95e2cc7 commit 7b63f73

5 files changed

Lines changed: 412113 additions & 378453 deletions

File tree

grammar.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,7 @@ module.exports = grammar({
148148
),
149149
),
150150
_note: ($) => option($, "N", alias($._string, $.note)),
151-
_key_table: ($) => option($, "T", alias($._string, $.key_table)),
152-
key: ($) => $._string,
151+
_key_table: ($) => option($, "T", alias($._string_unit, $.key_table)),
153152
bind_key_directive: ($) =>
154153
command(
155154
$,
@@ -918,14 +917,24 @@ module.exports = grammar({
918917
'"',
919918
),
920919
_word: (_) => /[^"';\\\s]+/,
921-
_string: ($) =>
920+
_string: ($) => prec.left(repeat1($._string_unit)),
921+
_string_unit: ($) =>
922+
choice(
923+
$.backslash_escape,
924+
$.str_double_quotes,
925+
$.str_single_quotes,
926+
$._word,
927+
$.block,
928+
),
929+
_word_key: (_) => /-|[^-"';\\\s][^"';\\\s]*/,
930+
key: ($) =>
922931
prec.left(
923932
repeat1(
924933
choice(
925934
$.backslash_escape,
926935
$.str_double_quotes,
927936
$.str_single_quotes,
928-
$._word,
937+
$._word_key,
929938
$.block,
930939
),
931940
),
@@ -987,11 +996,8 @@ function options($, chars) {
987996
return alias(new RegExp("-[" + chars + "]+"), $.command_line_option);
988997
}
989998

990-
function option($, char, ...arg) {
991-
return choice(
992-
seq(alias("-" + char, $.command_line_option), ...arg),
993-
alias(new RegExp("-" + char + "\\S+"), $.command_line_option),
994-
);
999+
function option($, char, ...args) {
1000+
return seq(alias("-" + char, $.command_line_option), ...args);
9951001
}
9961002

9971003
function cmd_opts(...args) {

0 commit comments

Comments
 (0)