diff options
author | Wilfred Hughes <me@wilfred.me.uk> | 2023-07-20 22:41:56 -0700 |
---|---|---|
committer | Wilfred Hughes <me@wilfred.me.uk> | 2023-07-20 22:41:56 -0700 |
commit | 685a2ef8d510ff9ce6fb396f3357b0476a77ff67 (patch) | |
tree | 34b5ae619ed8e5914d59a062b5effeb8df73a134 | |
parent | a15b92afafbf9dd309c6c9366bd9003e1f4a4300 (diff) | |
parent | 7984b7a59ee6a88c632bb77d00a20ca990001257 (diff) |
Merge remote-tracking branch 'grunweg/master'
44 files changed, 670414 insertions, 0 deletions
@@ -231,6 +231,11 @@ fn main() { extra_files: vec!["scanner.c"], }, TreeSitterParser { + name: "tree-sitter-latex", + src_dir: "vendored_parsers/tree-sitter-latex-src", + extra_files: vec!["scanner.c"], + }, + TreeSitterParser { name: "tree-sitter-lua", src_dir: "vendored_parsers/tree-sitter-lua-src", extra_files: vec!["scanner.cc"], diff --git a/src/parse/guess_language.rs b/src/parse/guess_language.rs index 145d13b14..b2ffb3769 100644 --- a/src/parse/guess_language.rs +++ b/src/parse/guess_language.rs @@ -46,6 +46,7 @@ pub enum Language { Json, Julia, Kotlin, + LaTeX, Lua, Make, Newick, @@ -129,6 +130,7 @@ pub fn language_name(language: Language) -> &'static str { Json => "JSON", Julia => "Julia", Kotlin => "Kotlin", + LaTeX => "LaTeX", Lua => "Lua", Make => "Make", Newick => "Newick", @@ -282,6 +284,7 @@ pub fn language_globs(language: Language) -> Vec<glob::Pattern> { JavascriptJsx => &["*.jsx"], Julia => &["*.jl"], Kotlin => &["*.kt", "*.ktm", "*.kts"], + LaTeX => &["*.aux", "*.cls", "*.sty", "*.tex"], Lua => &["*.lua"], Make => &[ "*.mak", diff --git a/src/parse/tree_sitter_parser.rs b/src/parse/tree_sitter_parser.rs index 2995d922a..ab0cc07da 100644 --- a/src/parse/tree_sitter_parser.rs +++ b/src/parse/tree_sitter_parser.rs @@ -91,6 +91,7 @@ extern "C" { fn tree_sitter_json() -> ts::Language; fn tree_sitter_julia() -> ts::Language; fn tree_sitter_kotlin() -> ts::Language; + fn tree_sitter_latex() -> ts::Language; fn tree_sitter_lua() -> ts::Language; fn tree_sitter_make() -> ts::Language; fn tree_sitter_newick() -> ts::Language; @@ -612,6 +613,20 @@ pub fn from_language(language: guess::Language) -> TreeSitterConfig { sub_languages: vec![], } } + LaTeX => { + let language = unsafe { tree_sitter_latex() }; + TreeSitterConfig { + language, + atom_nodes: vec![].into_iter().collect(), + delimiter_tokens: vec![("{", "}"), ("[", "]")], + highlight_query: ts::Query::new( + language, + include_str!("../../vendored_parsers/highlights/latex.scm"), + ) + .unwrap(), + sub_languages: vec![], + } + } Lua => { let language = unsafe { tree_sitter_lua() }; TreeSitterConfig { diff --git a/vendored_parsers/highlights/latex.scm b/vendored_parsers/highlights/latex.scm new file mode 100644 index 000000000..f8b589ae0 --- /dev/null +++ b/vendored_parsers/highlights/latex.scm @@ -0,0 +1,252 @@ +;; Based on the nvim-treesitter highlighting, which is under the Apache license. +;; https://github.com/nvim-treesitter/nvim-treesitter/blob/f0b50973f334a7a5bb5831cb52b9fd4c770e6cba/queries/latex/highlights.scm + +;; General syntax +(ERROR) @error + +(command_name) @function +(caption + command: _ @function) + +(key_value_pair + key: (_) @parameter + value: (_)) + +[ + (line_comment) + (block_comment) + (comment_environment) +] @comment + +((line_comment) @preproc + (#lua-match? @preproc "^%% !TeX")) + +[ + (brack_group) + (brack_group_argc) +] @parameter + +[(operator) "="] @operator + +"\\item" @punctuation.special + +((word) @punctuation.delimiter +(#eq? @punctuation.delimiter "&")) + +["[" "]" "{" "}"] @punctuation.bracket ; "(" ")" has no syntactical meaning in LaTeX + +;; General environments +(begin + command: _ @text.environment + name: (curly_group_text (text) @text.environment.name)) + +(end + command: _ @text.environment + name: (curly_group_text (text) @text.environment.name)) + +;; Definitions and references +(new_command_definition + command: _ @function.macro + declaration: (curly_group_command_name (_) @function)) +(old_command_definition + command: _ @function.macro + declaration: (_) @function) +(let_command_definition + command: _ @function.macro + declaration: (_) @function) + +(environment_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) + +(theorem_definition + command: _ @function.macro + name: (curly_group_text (_) @text.environment.name)) + +(paired_delimiter_definition + command: _ @function.macro + declaration: (curly_group_command_name (_) @function)) + +(label_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) +(label_reference_range + command: _ @function.macro + from: (curly_group_text (_) @text.reference) + to: (curly_group_text (_) @text.reference)) +(label_reference + command: _ @function.macro + names: (curly_group_text_list (_) @text.reference)) +(label_number + command: _ @function.macro + name: (curly_group_text (_) @text.reference) + number: (_) @text.reference) + +(citation + command: _ @function.macro + keys: (curly_group_text_list) @text.reference) + +(glossary_entry_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) +(glossary_entry_reference + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) + +(acronym_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) +(acronym_reference + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) + +(color_definition + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) +(color_reference + command: _ @function.macro + name: (curly_group_text (_) @text.reference)) + +;; Math +[ + (displayed_equation) + (inline_formula) +] @text.math + +(math_environment + (begin + command: _ @text.math + name: (curly_group_text (text) @text.math))) + +(math_environment + (text) @text.math) + +(math_environment + (end + command: _ @text.math + name: (curly_group_text (text) @text.math))) + +;; Sectioning +(title_declaration + command: _ @namespace + options: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(author_declaration + command: _ @namespace + authors: (curly_group_author_list + ((author)+ @text.title))) + +(chapter + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(part + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(section + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(subsection + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(subsubsection + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(paragraph + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +(subparagraph + command: _ @namespace + toc: (brack_group (_) @text.title)? + text: (curly_group (_) @text.title)) + +;; Beamer frames +(generic_environment + (begin + name: (curly_group_text + (text) @text.environment.name) + (#any-of? @text.environment.name "frame")) + . + (curly_group (_) @text.title)) + +((generic_command + command: (command_name) @_name + arg: (curly_group + (text) @text.title)) + (#eq? @_name "\\frametitle")) + +;; Formatting +((generic_command + command: (command_name) @_name + arg: (curly_group (_) @text.emphasis)) + (#eq? @_name "\\emph")) + +((generic_command + command: (command_name) @_name + arg: (curly_group (_) @text.emphasis)) + (#match? @_name "^(\\\\textit|\\\\mathit)$")) + +((generic_command + command: (command_name) @_name + arg: (curly_group (_) @text.strong)) + (#match? @_name "^(\\\\textbf|\\\\mathbf)$")) + +((generic_command + command: (command_name) @_name + . + arg: (curly_group (_) @text.uri)) + (#match? @_name "^(\\\\url|\\\\href)$")) + +;; File inclusion commands +(class_include + command: _ @include + path: (curly_group_path) @string) + +(package_include + command: _ @include + paths: (curly_group_path_list) @string) + +(latex_include + command: _ @include + path: (curly_group_path) @string) +(import_include + command: _ @include + directory: (curly_group_path) @string + file: (curly_group_path) @string) + +(bibtex_include + command: _ @include + path: (curly_group_path) @string) +(biblatex_include + "\\addbibresource" @include + glob: (curly_group_glob_pattern) @string.regex) + +(graphics_include + command: _ @include + path: (curly_group_path) @string) +(tikz_library_import + command: _ @include + paths: (curly_group_path_list) @string) + +(text) @spell +(inline_formula) @nospell +(displayed_equation) @nospell +(key_value_pair) @nospell +(generic_environment + begin: _ @nospell + end: _ @nospell) +(citation + keys: _ @nospell) +(command_name) @nospell diff --git a/vendored_parsers/tree-sitter-latex-src b/vendored_parsers/tree-sitter-latex-src new file mode 120000 index 000000000..7c2a99111 --- /dev/null +++ b/vendored_parsers/tree-sitter-latex-src @@ -0,0 +1 @@ +tree-sitter-latex/src
\ No newline at end of file diff --git a/vendored_parsers/tree-sitter-latex/.clang-format b/vendored_parsers/tree-sitter-latex/.clang-format new file mode 100644 index 000000000..a66156d74 --- /dev/null +++ b/vendored_parsers/tree-sitter-latex/.clang-format @@ -0,0 +1,5 @@ +--- +BasedOnStyle: LLVM +IndentWidth: 2 +--- + diff --git a/vendored_parsers/tree-sitter-latex/.gitattributes b/vendored_parsers/tree-sitter-latex/.gitattributes new file mode 100644 index 000000000..f60d7b977 --- /dev/null +++ b/vendored_parsers/tree-sitter-latex/.gitattributes @@ -0,0 +1,2 @@ +/src/** linguist-vendored +/examples/* linguist-vendored diff --git a/vendored_parsers/tree-sitter-latex/.github/dependabot.yml b/vendored_parsers/tree-sitter-latex/.github/dependabot.yml new file mode 100644 index 000000000..176ad5a3e --- /dev/null +++ b/vendored_parsers/tree-sitter-latex/.github/dependabot.yml @@ -0,0 +1,17 @@ +version: 2 +updates: + - package-ecosystem: cargo + directory: '/' + schedule: + interval: daily + open-pull-requests-limit: 10 + - package-ecosystem: npm + directory: '/' + schedule: + interval: daily + open-pull-requests-limit: 10 + - package-ecosystem: github-actions + directory: '/' + schedule: + interval: daily + open-pull-requests-limit: 10 diff --git a/vendored_parsers/tree-sitter-latex/.github/workflows/ci.yml b/vendored_parsers/tree-sitter-latex/.github/workflows/ci.yml new file mode 100644 index 000000000..074eacfc9 --- /dev/null +++ b/vendored_parsers/tree-sitter-latex/.github/workflows/ci.yml @@ -0,0 +1,55 @@ +name: CI +on: + push: + branches: [master] + pull_request: +env: + CARGO_INCREMENTAL: 0 + CI: 1 + RUST_BACKTRACE: short + RUSTFLAGS: '-D warnings' + RUSTUP_MAX_RETRIES: 10 +jobs: + binding_node: + name: Node + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v3 + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: '18' + cache: 'npm' + - run: npm install + - run: npm test + binding_rust: + name: Rust + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@stable + - name: Cache Dependencies + uses: Swatinem/rust-cache@v2 + - name: Compile + run: cargo test --no-run + - name: Test + run: cargo test -- --nocapture --quiet + binding_c: + name: C + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + steps: + - uses: actions/checkout@v3 + - run: make + - run: sudo make install diff --git a/vendored_parsers/tree-sitter-latex/.gitignore b/vendored_parsers/tree-sitter-latex/.gitignore new file mode 100644 index 000000000..020cdf946 --- /dev/null +++ b/vendored_parsers/tree-sitter-latex/.gitignore @@ -0,0 +1,248 @@ +# Created by https://www.toptal.com/developers/gitignore/api/c,c++,node,visualstudiocode,rust +# Edit at https://www.toptal.com/developers/gitignore?templates=c,c++,node,visualstudiocode,rust + +### C ### +# Prerequisites +*.d + +# Object files +*.o +*.ko +*.obj +*.elf + +# Linker output +*.ilk +*.map +*.exp + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ +*.su +*.idb +*.pdb + +# Kernel Module Compile Results +*.mod* +*.cmd +.tmp_versions/ +modules.order +Module.symvers +Mkfile.old +dkms.conf + +### C++ ### +# Prerequisites + +# Compiled Object files +*.slo + +# Precompiled Headers + +# Compiled Dynamic libraries + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai + +# Executables + +### Node ### +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test +.env.production + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* + +### Node Patch ### +# Serverless Webpack directories +.webpack/ + +# Optional stylelint cache +.stylelintcache + +# SvelteKit build / generate output +.svelte-kit + +### Rust ### +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# Support for Project snippet scope +!.vscode/*.code-snippets + +# End of https://www.toptal.com/developers/gitignore/api/c,c++,node,visualstudiocode,rust + +build/ +/bindings/c/*.h +/bindings/c/tree-sitter-*.pc + +# Swift Package Manager +.build/
\ No newline at end of file diff --git a/vendored_parsers/tree-sitter-latex/.prettierrc b/vendored_parsers/tree-sitter-latex/.prettierrc new file mode 100644 index 000000000..b4f8e6a6a --- /dev/null +++ b/vendored_parsers/tree-sitter-latex/.prettierrc @@ -0,0 +1,4 @@ +{ + "singleQuote": true, + "arrowParens": "avoid" +} diff --git a/vendored_parsers/tree-sitter-latex/CHANGELOG.md b/vendored_parsers/tree-sitter-latex/CHANGELOG.md new file mode 100644 index 000000000..ce93203d5 --- /dev/null +++ b/vendored_parsers/tree-sitter-latex/CHANGELOG.md @@ -0,0 +1,43 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Added + +- Add support for definition commands found in `xparse` package ([#82](https://github.com/latex-lsp/tree-sitter-latex/issues/82)) +- Add rules for parsing subscript and superscript expressions ([#63](https://github.com/latex-lsp/tree-sitter-latex/pull/63)) +- Add Swift package description ([#76](https://github.com/latex-lsp/tree-sitter-latex/pull/76)) + +### Fixed + +- Parse `pycode` environments correctly ([#67](https://github.com/latex-lsp/tree-sitter-latex/pull/67), [#66](https://github.com/latex-lsp/tree-sitter-latex/issues/66)) + +## [0.3.0] - 2022-10-26 + +### Added + +- Extend list of supported `\big` style commands + +### Changed + +- Do not associate bracket groups with commands by default ([#51](https://github.com/latex-lsp/tree-sitter-latex/pull/51), [#48](https://github.com/latex-lsp/tree-sitter-latex/issues/48)) + +## [0.2.1] - 2022-10-25 + |