Skip to content

Commit

Permalink
docs: add code docs
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Jul 28, 2023
1 parent 4c48242 commit f69ae03
Showing 1 changed file with 73 additions and 20 deletions.
93 changes: 73 additions & 20 deletions grammar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/* eslint-disable arrow-parens */
/* eslint-disable camelcase */
/* eslint-disable-next-line spaced-comment */
/* eslint-disable-no-undef */
/* eslint-disable-no-unused-vars */
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check

'use strict';

const PREC = {
Expand Down Expand Up @@ -40,45 +48,94 @@ const PREC = {
// sync_accept_on, sync_reject_on
};

function optseq() {
return optional(prec.left(seq.apply(null, arguments)));
}

function repseq() {
return repeat(prec.left(seq.apply(null, arguments)));
/**
*
* @param {(Rule|string|RegExp)[]} rules
*
* @return {ChoiceRule}
*
*/
function optseq(...rules) {
return optional(prec.left(seq(...rules)));
}

function commaSep(rule) {
return optional(sep1(',', rule));
}

function commaSep1(rule) {
return seq(rule, repseq(',', rule));
/**
*
* @param {(Rule|string|RegExp)[]} rules
*
* @return {RepeatRule}
*
*/
function repseq(...rules) {
return repeat(prec.left(seq(...rules)));
}

/**
* Creates a rule to match one or more of the rules separated by the separator
*
* @param {string} separator - The separator to use.
* @param {Rule} rule
*
* @return {PrecLeftRule}
*
*/
function sep1(separator, rule) {
return prec.left(seq(
rule,
repeat(prec.left(seq(separator, rule)))
));
}

/**
*
* @param {number} precedence
* @param {string} separator
* @param {Rule} rule
*
* @returns {PrecLeftRule}
*
*/
function psep1(precedence, separator, rule) {
return prec.left(precedence, seq(
rule,
repeat(prec.left(seq(separator, rule)))
));
}

function exprOp ($, prior, ops) {
/**
*
* @param {GrammarSymbols<string>} $
* @param {number} prior
* @param {Rule|string} ops
*
* @returns {PrecLeftRule}
*
*/
function exprOp($, prior, ops) {
return prec.left(prior, seq($.expression, ops, repeat($.attribute_instance), $.expression));
}

function constExprOp ($, prior, ops) {
/**
*
* @param {GrammarSymbols<string>} $
* @param {number} prior
* @param {Rule|string} ops
*
* @returns {PrecLeftRule}
*
*/
function constExprOp($, prior, ops) {
return prec.left(prior, seq($.constant_expression, ops, repeat($.attribute_instance), $.constant_expression));
}

function directive (command) {
/**
*
* @param {string} command
*
* @returns {AliasRule}
*
*/
function directive(command) {
return alias(new RegExp('`' + command), 'directive_' + command);
}

Expand Down Expand Up @@ -2035,7 +2092,7 @@ const rules = {
),

sequence_expr: $ => choice(
prec.left(sep1(',', $.cycle_delay_range, $.sequence_expr)), // FIXME precedence?
prec.left(sep1(',', $.cycle_delay_range)), // FIXME precedence?
prec.left(PREC.SHARP2, seq($.sequence_expr, repeat1(seq($.cycle_delay_range, $.sequence_expr)))),
seq($.expression_or_dist, optional($._boolean_abbrev)),
seq($.sequence_instance, optional($.sequence_abbrev)),
Expand Down Expand Up @@ -4935,7 +4992,3 @@ module.exports = grammar({
[$.module_path_primary, $.primary_literal],
],
});

/* eslint camelcase: 0 */
/* eslint no-undef: 0 */
/* eslint no-unused-vars: 0 */

0 comments on commit f69ae03

Please sign in to comment.