Skip to content

Commit

Permalink
style: clean up warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Dec 21, 2024
1 parent 8aebbb6 commit 706805c
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/**
* @file Make grammar for tree-sitter
* @author Alexandre Muller
* @author Amaan Qureshi <[email protected]>
* @license MIT
*/

/// <reference types="tree-sitter-cli/dsl" />
// @ts-check

const CHARSET = 'a-zA-Z0-9%\\+\\-\\.@_\\*\\?\\/';
const ESCAPE_SET = 'abtnvfrE!"#\\$&\'\\(\\)\\*,;<>\\?\\[\\\\\\]^`{\\|}~';

Expand Down Expand Up @@ -66,15 +76,11 @@ module.exports = grammar({
],

extras: $ => [
/[\s]/,
/\s/,
alias(token(seq('\\', /\r?\n|\r/)), '\\'),
$.comment,
],

conflicts: $ => [],

precedences: $ => [],

rules: {
// 3.1
makefile: $ => repeat($._thing),
Expand Down Expand Up @@ -419,7 +425,7 @@ module.exports = grammar({
),

// 10.5.3
automatic_variable: $ => seq(
automatic_variable: _ => seq(
choice('$', '$$'),
choice(
choice(
Expand Down Expand Up @@ -520,7 +526,7 @@ module.exports = grammar({
token(prec(-1, /([^'"$\r\n\\]|\\\\|\\[^\r\n])+/)),
)),

word: $ => token(repeat1(choice(
word: _ => token(repeat1(choice(
new RegExp('[' + CHARSET + ']'),
new RegExp('\\\\[' + ESCAPE_SET + ']'),
new RegExp('\\\\[0-9]{3}'),
Expand All @@ -536,12 +542,12 @@ module.exports = grammar({
// }}}
// Tokens {{{
// TODO external parser for .RECIPEPREFIX
_recipeprefix: $ => '\t',
_recipeprefix: _ => '\t',

// TODO prefixed line in define is recipe
_rawline: $ => token(/.*[\r\n]+/), // any line
_rawline: _ => token(/.*[\r\n]+/), // any line

_shell_text_without_split: $ => text($,
_shell_text_without_split: $ => text(
noneOf(...['\\$', '\\r', '\\n', '\\']),
choice(
$._variable,
Expand All @@ -562,7 +568,7 @@ module.exports = grammar({
$.shell_command,
),

text: $ => text($,
text: $ => text(
choice(
noneOf(...['\\$', '\\(', '\\)', '\\n', '\\r', '\\']),
SPLIT,
Expand All @@ -576,7 +582,7 @@ module.exports = grammar({
),
// }}}

comment: $ => token(prec(-1, /#.*/)),
comment: _ => token(prec(-1, /#.*/)),
},
});

Expand All @@ -591,7 +597,7 @@ function noneOf(...characters) {

/**
*
* @param rule
* @param {RuleOrLiteral} rule
*/
function delimitedVariable(rule) {
return choice(
Expand All @@ -602,11 +608,10 @@ function delimitedVariable(rule) {

/**
*
* @param $
* @param text
* @param fenced_vars
* @param {RuleOrLiteral} text
* @param {RuleOrLiteral} fenced_vars
*/
function text($, text, fenced_vars) {
function text(text, fenced_vars) {
const raw_text = token(repeat1(choice(
text,
new RegExp('\\\\[' + ESCAPE_SET + ']'),
Expand Down

0 comments on commit 706805c

Please sign in to comment.