From b906e05ba448c7485495a4376c17c3216b2de80f Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Sun, 21 May 2023 19:22:56 -0400 Subject: [PATCH] docs: document grammar.js --- grammar.js | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/grammar.js b/grammar.js index 77d68ac..5e3c742 100644 --- a/grammar.js +++ b/grammar.js @@ -1,3 +1,15 @@ +/** + * @file C grammar for tree-sitter + * @author Max Brunsfeld + * @license MIT + */ + +/* eslint-disable arrow-parens */ +/* eslint-disable camelcase */ +/* eslint-disable-next-line spaced-comment */ +/// +// @ts-check + const PREC = { PAREN_DECLARATOR: -10, ASSIGNMENT: -1, @@ -1026,6 +1038,21 @@ module.exports.PREC = PREC function preprocIf (suffix, content) { function elseBlock ($) { +/** + * + * @param {string} suffix + * + * @param {RuleBuilder} content + * + * @return {RuleBuilders} + */ + /** + * + * @param {GrammarSymbols} $ + * + * @return {ChoiceRule} + * + */ return choice( suffix ? alias($['preproc_else' + suffix], $.preproc_else) : $.preproc_else, suffix ? alias($['preproc_elif' + suffix], $.preproc_elif) : $.preproc_elif, @@ -1071,12 +1098,35 @@ function preprocessor (command) { function commaSep (rule) { return optional(commaSep1(rule)) +/** + * Creates a preprocessor regex rule + * + * @param {RegExp|Rule|String} command + * + * @return {AliasRule} + */ } function commaSep1 (rule) { return seq(rule, repeat(seq(',', rule))) +/** + * Creates a rule to optionally match one or more of the rules separated by a comma + * + * @param {Rule} rule + * + * @return {ChoiceRule} + * + */ } function commaSepTrailing (recurSymbol, rule) { return choice(rule, seq(recurSymbol, ',', rule)) +/** + * Creates a rule to match one or more of the rules separated by a comma + * + * @param {Rule} rule + * + * @return {SeqRule} + * + */ }