This grammar implements the vimdoc "spec" (ref1, ref2). Predictable results are the primary goal, so that output formats (e.g. HTML) are well-formed; the input (vimdoc) is secondary. The first step should always be to try to fix the input rather than insist on a grammar that handles vimdoc's endless quirks.
blockis the main top-level node, delimited by blank line(s) or any line starting with<(codeblock terminator).- contains
lineandline_linodes.
- contains
line:- contains atoms (words, tags, taglinks, …)
- contains headings (
h1,h2,h3,column_heading) becausecodeblockterminated by "implicit stop" (no terminating<) consumes blank lines, soblockhas no way to end.
line_li("listitem")- lines starting with
-/•(not+/*) are listitems. - consumes lines until blank line, codeblock, or next listitem.
- nesting is ignored: indented listitems are parsed as siblings.
- lines starting with
codeblock:- contained by
lineorline_li, because ">" can start a codeblock at the end of any line. - contains
linenodes withoutwordnodes: it's just the full raw text line including whitespace. This is somewhat dictated by its "preformatted" nature; parsing the contents would require loading a "child" language (injection). See #2. - the terminating
<(and any following whitespace) is discarded (anonymous).
- contained by
h1= "Heading 1":======followed by text and optional*tags*.h2= "Heading 2":------followed by text and optional*tags*.h3= "Heading 3": UPPERCASE WORDS, followed by optional*tags*, followed by atoms.
- Input must end with newline/EOL (
\n). Grammar does not support files without EOL. - Input must end with a blank line. Though this doesn't seem to matter in practice.
- Spec requires that
codeblockdelimiter ">" must be preceded by a space (" >"), not a tab. But currently the grammar doesn't enforce this. Example::help lcs-tab. urldoesn't handle surrounding parens. E.g.(https://example.com/#yay)yieldswordurldoesn't handle nested parens. E.g.(https://example.com/(foo)#yay)column_headingcurrently only recognizes tilde~preceded by space (i.e.foo ~notfoo~). This covers 99% of :help files.column_headingchildren should be plaintext, but currently are parsed as$._atom.modelinemust be preceded by a blank line.
tag_heading: line(s) containing only tags, typically implies a "heading" before a block.
Steps to perform a release: https://tree-sitter.github.io/tree-sitter/creating-parsers/6-publishing.html
- Update tree-sitter CLI.
npm install tree-sitter-cli - Bump the version.
tree-sitter version x.y.z- Choose
patch/minor/majorto indicate query compatibility:patchfor bugfixes (no changes to queries needed)minorfor added nodes (queries may need changes to use new nodes but will not error)majorfor removed or renamed nodes (queries will error if not adapted), other breaking changes
- Choose
- Regenerate and test.
tree-sitter generate && tree-sitter test - Commit the generated files
git add . git commit -m 'release' - Push
git push - Tag and release: https://github.com/neovim/tree-sitter-vimdoc/releases/new