Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: detect type of action arguments #11

Merged
merged 2 commits into from
Dec 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ module.exports = grammar({
_snake_case_identifier : $ => snake_case_seq(),

property : $ => choice($._kebab_case_identifier),

// Value types can be boolean, string, number, "adjustments", or hex color
// `palette` values a handled separately
value: $ => seq(
Expand All @@ -58,6 +59,7 @@ module.exports = grammar({
$.percent_adjustment,
$.numeric_adjustment,
),

string: $ => prec(1, choice(
seq('"', /[^"]*/, '"'),
seq("'", /[^']*/, "'"),
Expand All @@ -66,6 +68,15 @@ module.exports = grammar({
$._raw_value,
)
)),

// The default "string" token disambiguates from (color) by excluding bare strings starting with "#"
// This version does not do that.
_loose_string: $ => prec(1, choice(
seq('"', /[^"]*/, '"'),
seq("'", /[^']*/, "'"),
$._raw_value
)),

color: $ => prec(2, hex_color_seq()),
percent_adjustment: $ => token(
prec(
Expand Down Expand Up @@ -162,10 +173,19 @@ module.exports = grammar({
optional(
seq(
token.immediate(":"),
field("argument", alias(anything, $.action_argument)),
field("argument", alias($._action_arg_value, $.action_argument)),
),
),
),

_action_arg_value: $ => choice(
$.boolean,
alias(
token(prec(2, seq(optional(choice("+", "-")), token.immediate(number)))),
$.number
),
alias($._loose_string, $.string)
),
},
});

Expand All @@ -179,7 +199,7 @@ function hex_color_seq() {
}

function snake_case_seq() {
return seq(word, repeat(seq(token.immediate("_"), token.immediate(word)));
return seq(word, repeat(seq(token.immediate("_"), token.immediate(word))));
}

function directive_seq(key, value) {
Expand Down
133 changes: 121 additions & 12 deletions src/grammar.json

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

27 changes: 23 additions & 4 deletions src/node-types.json

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

Loading
Loading