Skip to content
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
61 changes: 39 additions & 22 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ module.exports = grammar({
identifier: _ => _identifier_rules(false),

long_flag_identifier: _ =>
token.immediate(/[0-9\p{XID_Start}_][\p{XID_Continue}?_-]*/),
token.immediate(/[0-9\p{XID_Start}_][\p{XID_Continue}?_-]*/u),

_command_name: $ =>
choice(
Expand All @@ -146,7 +146,7 @@ module.exports = grammar({
/// Attributes
attribute_list: $ => repeat1(seq($.attribute, choice(';', $._newline))),
attribute_identifier: _ =>
token.immediate(/[0-9\p{XID_Start}][0-9\p{XID_Continue}_-]*/),
token.immediate(/[0-9\p{XID_Start}][0-9\p{XID_Continue}_-]*/u),
attribute: $ =>
seq(
'@',
Expand Down Expand Up @@ -359,7 +359,7 @@ module.exports = grammar({
seq(operator().minus, field('name', $.param_short_flag_identifier)),

param_short_flag_identifier: _ =>
token.immediate(/[\p{Punctuation}\p{Symbol}\p{XID_Continue}]/),
token.immediate(/[\p{Punctuation}\p{Symbol}\p{XID_Continue}]/u),

/// Controls

Expand Down Expand Up @@ -545,6 +545,7 @@ module.exports = grammar({
seq(_env_variable_rule(false, $), $.command),
$._ctrl_expression,
$.where_command,
$.assignment,
alias($._stmt_let_shortcut, $.stmt_let),
),

Expand All @@ -561,6 +562,7 @@ module.exports = grammar({
),

$._ctrl_expression_parenthesized,
alias($.assignment_parenthesized, $.assignment),
alias($.where_command_parenthesized, $.where_command),
alias($._stmt_let_shortcut, $.stmt_let),
),
Expand Down Expand Up @@ -1170,7 +1172,7 @@ module.exports = grammar({

cell_path: $ => repeat1($.path),

_path_suffix: $ => choice('?', '!', seq('?', '!'), seq('!', '?')),
_path_suffix: _$ => choice('?', '!', seq('?', '!'), seq('!', '?')),

path: $ => {
const path = choice(
Expand Down Expand Up @@ -1249,7 +1251,7 @@ module.exports = grammar({
),

short_flag_identifier: _ =>
token.immediate(/[\p{XID_Continue}:?@!%_-]+/),
token.immediate(/[\p{XID_Continue}:?@!%_-]+/u),

long_flag: $ =>
seq(
Expand Down Expand Up @@ -1327,7 +1329,7 @@ function _identifier_rules(immediate) {
* @param {any} entry base build block
* @param {any} separator separator between entries
* @param {any} preceding separator before first entry, defaults to separator
* @param {Array} alt_sep array of rules to override default separator
* @param {any} alt_sep array of rules to override default separator
* @param {any} empty_unit optional for empty body
*/
function general_body_rules(
Expand Down Expand Up @@ -1362,8 +1364,11 @@ function parenthesized_body_rules() {
return {
..._block_body_rules('_parenthesized'),

/// pipeline

/**
* pipeline_parenthesized
*
* @param {GrammarSymbols<string>} $
*/
pipeline_parenthesized: $ =>
seq(
repeat(
Expand All @@ -1385,8 +1390,11 @@ function block_body_rules() {
return {
..._block_body_rules(''),

/// pipeline

/**
* pipeline
*
* @param {GrammarSymbols<string>} $
*/
pipeline: $ =>
seq(
repeat(seq($.pipe_element, $._pipe_separator, optional($._newline))),
Expand Down Expand Up @@ -1466,7 +1474,10 @@ function _block_body_rules(suffix) {
),

['stmt_mut' + suffix]: (/** @type {{ [x: string]: RuleOrLiteral; }} */ $) =>
prec.right(1, seq(keyword().mut, $['_assignment_pattern' + suffix])),
prec.right(
prec_map().assignment,
seq(keyword().mut, $['_assignment_pattern' + suffix]),
),

['stmt_const' + suffix]: (
/** @type {{ [x: string]: RuleOrLiteral; }} */ $,
Expand Down Expand Up @@ -1522,7 +1533,6 @@ function _block_body_rules(suffix) {
['_statement' + suffix]: (/** @type {any} */ $) =>
choice(
$._ctrl_statement,
alias_for_suffix($, 'assignment', suffix),
alias_for_suffix($, 'stmt_let', suffix),
alias_for_suffix($, 'stmt_mut', suffix),
alias_for_suffix($, 'stmt_const', suffix),
Expand All @@ -1535,7 +1545,7 @@ function _block_body_rules(suffix) {
* Insert optional($._repeat_newline) in-between
*
* @param {any} $
* @param {Array} sequence
* @param {Array<any>} sequence
* @param {boolean} begin allow newline in beginning
* @param {boolean} end allow newline in end
*/
Expand Down Expand Up @@ -1681,7 +1691,7 @@ function _binary_predicate_rule(parenthesized) {
$._binary_predicate_parenthesized :
$._binary_predicate;
return choice(
...binary().map(([precedence, opr]) => {
...binary().map(({prec: precedence, name: opr}) => {
const seq_array = [
field('lhs', choice($.where_predicate, _expr)),
field('opr', opr),
Expand Down Expand Up @@ -1826,6 +1836,9 @@ function _range_rule(anonymous) {
* @param {string} type
*/
function _unquoted_with_expr_rule(type) {
/**
* @param {GrammarSymbols<string>} $
*/
return $ => {
let excluded = '';
let unquoted_head = $.unquoted;
Expand Down Expand Up @@ -1893,10 +1906,14 @@ function _unquoted_rule(type) {
const pattern = token(seq(none_of(excluded_first), repeat(pattern_once)));
const pattern_repeat = token(repeat(pattern_once));

// because this catches almost anything, we want to ensure it is
// picked as the a last resort after everything else has failed.
// so we give it a ridiculously low precedence and place it at the
// very end
/**
* because this catches almost anything, we want to ensure it is
* picked as the a last resort after everything else has failed.
* so we give it a ridiculously low precedence and place it at the
* very end
*
* @param {GrammarSymbols<string>} $
*/
return $ => {
let pattern_repeat1 = $._unquoted_pattern;
switch (type) {
Expand Down Expand Up @@ -2167,17 +2184,17 @@ function table() {
[prec_map().bit_and, operator().bit_and],
[prec_map().bit_xor, operator().bit_xor],
[prec_map().bit_or, operator().bit_or],
].concat(binary(), predicate());
].concat(binary().map(({prec, name}) => [prec, name]), predicate());
}

/**
*
*/
function binary() {
return [
[prec_map().and, operator().and],
[prec_map().xor, operator().xor],
[prec_map().or, operator().or],
{prec: prec_map().and, name: operator().and},
{prec: prec_map().xor, name: operator().xor},
{prec: prec_map().or, name: operator().or},
];
}

Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"eslint": "^9.39.1",
"eslint-config-treesitter": "^1.0.2",
"prebuildify": "^6.0.1",
"tree-sitter-cli": "^0.25.9"
"tree-sitter-cli": "^0.25.10"
},
"peerDependencies": {
"tree-sitter": "^0.25.0"
Expand Down
1 change: 0 additions & 1 deletion script/known-failures.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ examples/nu_scripts/custom-completions/pytest/pytest-completions.nu
examples/nu_scripts/custom-menus/current_session_history_menu.nu
examples/nu_scripts/example-config/init.nu
examples/nu_scripts/make_release/gen-ts-ext.nu
examples/nu_scripts/make_release/notes/notice.nu
examples/nu_scripts/make_release/notes/tools.nu
examples/nu_scripts/modules/duplicates/example.nu
examples/nu_scripts/modules/kubernetes/complete.nu
Expand Down
38 changes: 21 additions & 17 deletions src/grammar.json

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

28 changes: 4 additions & 24 deletions src/node-types.json

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

Loading
Loading