Skip to content

Commit

Permalink
Permit braces in more contexts
Browse files Browse the repository at this point in the history
Allows for free use of `{` and `}` in descriptions when they're not part of inline tags. Also allows for braces in type descriptions as long as they're balanced.
  • Loading branch information
savetheclocktower committed Jan 9, 2024
1 parent d01984d commit 5ee169e
Show file tree
Hide file tree
Showing 6 changed files with 1,107 additions and 832 deletions.
15 changes: 12 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
module.exports = grammar({
name: 'jsdoc',

externals: $ => [
$.type,
],

extras: _ => [
token(choice(
// Skip over stars at the beginnings of lines
Expand All @@ -33,7 +37,7 @@ module.exports = grammar({

description: $ => seq(
$._text,
repeat(choice($._text, $.inline_tag)),
repeat(choice($._text, $.inline_tag, $._inline_tag_false_positive)),
),

tag: $ => choice(
Expand Down Expand Up @@ -66,6 +70,12 @@ module.exports = grammar({
'}',
),

_inline_tag_false_positive: _ => prec.left(1, seq(
'{',
/[^@}]+/,
optional('}'),
)),

tag_name_with_argument: _ => token(choice(
'@access',
'@alias',
Expand All @@ -91,6 +101,7 @@ module.exports = grammar({
'@returns',
'@throw',
'@throws',
'@type',
)),

tag_name: _ => /@[a-zA-Z_]+/,
Expand Down Expand Up @@ -132,8 +143,6 @@ module.exports = grammar({

identifier: _ => /[a-zA-Z_$][a-zA-Z_$0-9]*/,

type: _ => /[^}\n]+/,

_text: _ => token(prec(-1, /[^*{}@\s][^*{}\n]*([^*/{}\n][^*{}\n]*\*+)*/)),

_begin: _ => token(seq('/', repeat('*'))),
Expand Down
48 changes: 43 additions & 5 deletions src/grammar.json

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

Loading

0 comments on commit 5ee169e

Please sign in to comment.