Skip to content

Commit

Permalink
feat: permit braces in more contexts (#10)
Browse files Browse the repository at this point in the history
* Permit braces in more contexts

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 authored Jan 27, 2024
1 parent 125f65b commit a5e363a
Show file tree
Hide file tree
Showing 9 changed files with 918 additions and 685 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Fuzz Parser

on:
push:
paths:
- src/scanner.c
pull_request:
paths:
- src/scanner.c
workflow_dispatch:

jobs:
test:
name: Parser fuzzing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: vigoux/tree-sitter-fuzz-action@v1
with:
language: jsdoc
external-scanner: src/scanner.c
time: 60
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let package = Package(
],
sources: [
"src/parser.c",
"src/scanner.c",
],
resources: [
.copy("queries")
Expand Down
3 changes: 2 additions & 1 deletion binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
],
"sources": [
"src/parser.c",
"bindings/node/binding.cc"
"bindings/node/binding.cc",
"src/scanner.c",
],
"cflags_c": [
"-std=c99",
Expand Down
4 changes: 4 additions & 0 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ fn main() {
let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);

let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());

c_config.compile("parser");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
}
11 changes: 8 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,8 @@ module.exports = grammar({
'}',
),

_inline_tag_false_positive: _ => token(prec.left(1, /\{[^@}]+\}?/)),

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

tag_name: _ => /@[a-zA-Z_]+/,
Expand Down Expand Up @@ -136,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
30 changes: 25 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 a5e363a

Please sign in to comment.