Parsers: add reStructuredText

This commit is contained in:
Santos Gallegos 2020-07-26 09:38:53 -05:00 committed by Thomas Vigouroux
parent 121c44a23b
commit 6f01384cb2
9 changed files with 186 additions and 4 deletions

View file

@ -122,6 +122,21 @@ are optional and will not have any effect for now.
builtin builtin
@structure @structure
``` ```
#### Text
Mainly for markup languages.
```
@text
@text.strong
@text.emphasis
@text.underline
@text.title
@text.literal
@text.uri
```
### Locals ### Locals
``` ```
@definition for various definitions @definition for various definitions

View file

@ -284,6 +284,7 @@ List of currently supported languages:
- [x] regex (maintained by @theHamsta) - [x] regex (maintained by @theHamsta)
- [ ] jsdoc - [ ] jsdoc
- [x] dart (maintained by @Akin909) - [x] dart (maintained by @Akin909)
- [x] rst (maintained by @stsewd)
## User Query Extensions ## User Query Extensions

View file

@ -361,4 +361,32 @@ This is left as an exercise for the reader.
For includes: `#include` in C, `use` or `extern crate` in Rust, or `require` For includes: `#include` in C, `use` or `extern crate` in Rust, or `require`
in Lua in Lua
`TSText`
*hl-TSText*
For strings considered text in a markup language.
`TSStrong`
*hl-TSStrong*
For text to be represented with strong.
`TSEmphasis`
*hl-TSEmphasis*
For text to be represented with emphasis.
`TSUnderline`
*hl-TSUnderline*
For text to be represented with an underline.
`TSTitle`
Text that is part of a title.
`TSLiteral`
*hl-TSLiteral*
Literal text.
`TSURI`
*hl-TSURI*
Any URI like a link or email.
vim:tw=78:ts=8:noet:ft=help:norl: vim:tw=78:ts=8:noet:ft=help:norl:

View file

@ -53,6 +53,15 @@ hlmap["type.builtin"] = "TSTypeBuiltin"
hlmap["structure"] = "TSStructure" hlmap["structure"] = "TSStructure"
hlmap["include"] = "TSInclude" hlmap["include"] = "TSInclude"
-- Text
hlmap["text"] = "TSText"
hlmap["text.strong"] = "TSStrong"
hlmap["text.emphasis"] = "TSEmphasis"
hlmap["text.underline"] = "TSUnderline"
hlmap["text.title"] = "TSTitle"
hlmap["text.literal"] = "TSLiteral"
hlmap["text.uri"] = "TSURI"
function M.attach(bufnr, lang) function M.attach(bufnr, lang)
local bufnr = bufnr or api.nvim_get_current_buf() local bufnr = bufnr or api.nvim_get_current_buf()
local lang = lang or parsers.get_buf_lang(bufnr) local lang = lang or parsers.get_buf_lang(bufnr)

View file

@ -214,6 +214,13 @@ list.dart = {
} }
} }
list.rst = {
install_info = {
url = "https://github.com/stsewd/tree-sitter-rst",
files = { "src/parser.c", "src/scanner.c" },
}
}
-- Parsers for injections -- Parsers for injections
list.regex = { list.regex = {
install_info = { install_info = {

View file

@ -62,3 +62,11 @@ highlight default link TSDefinitionUsage Visual
highlight default link TSDefinition Search highlight default link TSDefinition Search
highlight default link TSCurrentScope CursorLine highlight default link TSCurrentScope CursorLine
highlight default link TSText Normal
highlight default TSStrong term=bold cterm=bold gui=bold
highlight default TSEmphasis term=italic cterm=italic gui=italic
highlight default TSUnderline term=underline cterm=underline gui=underline
highlight default link TSTitle Title
highlight default link TSLiteral String
highlight default link TSURI Identifier

View file

@ -0,0 +1,81 @@
; Marks
[
".."
"|"
"--"
"__"
"::"
"bullet"
"adornment"
(transition)
] @punctuation.special
; Directives
(directive
name: (type) @function)
((directive
name: (type) @include)
(#match? @include "^include::$"))
; Blocks
[
(literal_block)
(line_block)
(block_quote)
(doctest_block)
] @text.literal
(substitution_definition
name: (substitution) @constant)
(footnote
name: (label) @constant)
(citation
name: (label) @constant)
(target
name: (reference)? @constant
link: (_) @text.literal)
; Inline markup
(emphasis) @text.emphasis
(strong) @text.strong
(standalone_hyperlink) @text.uri
[
(interpreted_text)
(literal)
] @text.literal
[
(target)
(substitution_reference)
(footnote_reference)
(citation_reference)
(reference)
] @constant
; Embedded
(doctest_block) @embed
(directive
body: (body) @embed)
; Others
(title) @text.title
(attribution) @text.emphasis
(comment) @comment
(comment "..") @comment
(ERROR) @error

31
queries/rst/locals.scm Normal file
View file

@ -0,0 +1,31 @@
;; Scopes
(document) @scope
(directive) @scope
;; Definitions
(substitution_definition
name: (substitution) @definition)
(footnote
name: (label) @definition)
(citation
name: (label) @definition)
(target
name: (reference) @definition)
; Inline targets
(target) @definition
;; References
[
(substitution_reference)
(footnote_reference)
(citation_reference)
(reference)
] @reference

View file

@ -0,0 +1,2 @@
(directive
body: (body) @function.inner) @function.outer