Skip to content

Commit

Permalink
refactor: reduce state count, move test directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ribru17 committed Oct 1, 2024
1 parent 3d4768b commit 74addc9
Show file tree
Hide file tree
Showing 4 changed files with 1,713 additions and 4,254 deletions.
49 changes: 28 additions & 21 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module.exports = grammar({
name: 'readline',

// Control whitespace explicitly
extras: ($) => [],
extras: (_) => [],

rules: {
source: ($) => repeat($._statement),
Expand All @@ -29,14 +29,12 @@ module.exports = grammar({
seq(repeat(WHITE_SPACE), NEWLINE),
),

comment: ($) => seq(/#/, optional(ANYTHING)),
comment: (_) => seq(/#/, optional(ANYTHING)),

conditional_construct: ($) =>
seq(
alias(/\$if/i, '$if'),
repeat1(WHITE_SPACE),
$.test,
repeat(WHITE_SPACE),
NEWLINE,
alias(repeat($._statement), $.consequence),
optional(seq(
Expand All @@ -46,18 +44,27 @@ module.exports = grammar({
NEWLINE,
alias(repeat($._statement), $.alternative),
)),
$._endif,
),

_endif: (_) =>
seq(
repeat(WHITE_SPACE),
alias(/\$endif/i, '$endif'),
repeat(WHITE_SPACE),
),

test: ($) =>
choice(
$._mode_test,
$._term_test,
$._version_test,
$._application_test,
$._variable_test,
seq(
repeat1(WHITE_SPACE),
choice(
$._mode_test,
$._term_test,
$._version_test,
$._application_test,
$._variable_test,
),
repeat(WHITE_SPACE),
),

_mode_test: ($) =>
Expand Down Expand Up @@ -216,7 +223,7 @@ module.exports = grammar({

bool_value: ($) => choice('1', /on/i, /off/i, ERROR_ALIAS($)),
bell_value: ($) => choice(/none/i, /visible/i, /audible/i, ERROR_ALIAS($)),
string_value: ($) => ANYTHING_STARTING_NON_WHITESPACE,
string_value: (_) => ANYTHING_STARTING_NON_WHITESPACE,
number_value: ($) => choice(/[-+]?\d+/, ERROR_ALIAS($)),
edit_mode_value: ($) => choice(/emacs/i, /vi/i, ERROR_ALIAS($)),
keymap_value: ($) =>
Expand All @@ -225,7 +232,7 @@ module.exports = grammar({
ERROR_ALIAS($),
),

bool_variable: ($) =>
bool_variable: (_) =>
choice(
/bind-tty-special-chars/i,
/blink-matching-paren/i,
Expand Down Expand Up @@ -260,8 +267,8 @@ module.exports = grammar({
/skip-completed-text/i,
/visible-stats/i,
),
bell_variable: ($) => /bell\-style/i,
string_variable: ($) =>
bell_variable: (_) => /bell\-style/i,
string_variable: (_) =>
choice(
/active-region-end-color/i,
/active-region-start-color/i,
Expand All @@ -271,16 +278,16 @@ module.exports = grammar({
/vi-cmd-mode-string/i,
/vi-ins-mode-string/i,
),
number_variable: ($) =>
number_variable: (_) =>
choice(
/completion-display-width/i,
/completion-prefix-display-length/i,
/completion-query-items/i,
/history-size/i,
/keyseq-timeout/i,
),
edit_mode_variable: ($) => /editing\-mode/i,
keymap_variable: ($) => /keymap/i,
edit_mode_variable: (_) => /editing\-mode/i,
keymap_variable: (_) => /keymap/i,

key_binding: ($) =>
seq(
Expand All @@ -291,7 +298,7 @@ module.exports = grammar({
),

// users can define custom function names
function_name: ($) => /[a-zA-Z\-]+/,
function_name: (_) => /[a-zA-Z\-]+/,

keyseq: ($) => $._double_quoted_string,

Expand All @@ -303,7 +310,7 @@ module.exports = grammar({
_quoted_string: ($) =>
seq(/["']/, repeat1(choice(/[^"'\\]/, $.escape_sequence)), /["']/),

escape_sequence: ($) =>
escape_sequence: (_) =>
/\\([abdefnrtv'"\\]|x[0-9a-fA-F]{1,2}|[0-7]{1,3}|[CM]-)/,

keyname: ($) =>
Expand All @@ -312,7 +319,7 @@ module.exports = grammar({
choice($.symbolic_character_name, $.key_literal),
),

symbolic_character_name: ($) =>
symbolic_character_name: (_) =>
choice(
/Control/i,
/Meta/i,
Expand All @@ -328,6 +335,6 @@ module.exports = grammar({
/Spc/i,
),

key_literal: ($) => /\S/,
key_literal: (_) => /\S/,
},
});
72 changes: 43 additions & 29 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 74addc9

Please sign in to comment.