├── .github └── workflows │ ├── luarocks.yml │ ├── release-please.yml │ ├── tests.yml │ └── tree-sitter-norg-meta.rockspec.template ├── .gitignore ├── CHANGELOG.md ├── Cargo.toml ├── LICENSE ├── README.md ├── binding.gyp ├── bindings ├── node │ ├── binding.cc │ └── index.js └── rust │ ├── build.rs │ └── lib.rs ├── default.nix ├── flake.lock ├── flake.nix ├── grammar.js ├── package.json ├── queries └── highlights.scm ├── src ├── grammar.json ├── node-types.json ├── parser.c └── tree_sitter │ └── parser.h └── test └── corpus └── document.meta.txt /.github/workflows/luarocks.yml: -------------------------------------------------------------------------------- 1 | name: Push to Luarocks 2 | 3 | on: 4 | push: 5 | release: 6 | types: 7 | - created 8 | tags: 9 | - '*' 10 | workflow_dispatch: 11 | 12 | jobs: 13 | luarocks-upload: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | with: 18 | fetch-depth: 0 # Required to count the commits 19 | - name: Get Version 20 | run: echo "LUAROCKS_VERSION=$(git describe --abbrev=0 --tags)" >> $GITHUB_ENV 21 | - name: Install C/C++ Compiler 22 | uses: rlalik/setup-cpp-compiler@master 23 | with: 24 | compiler: clang-latest 25 | - name: Install Lua 26 | uses: leso-kn/gh-actions-lua@master 27 | with: 28 | luaVersion: "5.1" 29 | - name: Install Luarocks 30 | uses: hishamhm/gh-actions-luarocks@master 31 | - name: Install `luarocks-build-treesitter-parser` Package 32 | run: | 33 | luarocks --verbose --local --lua-version=5.1 install luarocks-build-treesitter-parser 34 | - name: LuaRocks Upload 35 | uses: nvim-neorocks/luarocks-tag-release@v5 36 | env: 37 | LUAROCKS_API_KEY: ${{ secrets.LUAROCKS_API_KEY }} 38 | with: 39 | name: tree-sitter-norg-meta 40 | version: ${{ env.LUAROCKS_VERSION }} 41 | labels: | 42 | neovim 43 | tree-sitter 44 | summary: Treesitter parser for Norg's `@document.meta` blocks. 45 | template: .github/workflows/tree-sitter-norg-meta.rockspec.template 46 | -------------------------------------------------------------------------------- /.github/workflows/release-please.yml: -------------------------------------------------------------------------------- 1 | name: Release Please Automatic Semver 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | jobs: 9 | release: 10 | name: release 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: google-github-actions/release-please-action@v3 14 | with: 15 | release-type: rust 16 | package-name: tree-sitter-norg-meta 17 | -------------------------------------------------------------------------------- /.github/workflows/tests.yml: -------------------------------------------------------------------------------- 1 | name: Parser tests 2 | 3 | on: 4 | push: 5 | branches: 6 | main 7 | pull_request: 8 | 9 | jobs: 10 | test_parser: 11 | strategy: 12 | fail-fast: false 13 | name: Testing 14 | runs-on: ubuntu-latest 15 | env: 16 | CC: clang 17 | steps: 18 | - name: Prepare tree-sitter 19 | uses: actions/checkout@v2 20 | with: 21 | repository: tree-sitter/tree-sitter 22 | 23 | - name: Prepare tree-sitter-norg-meta 24 | uses: actions/checkout@v2 25 | with: 26 | path: test/fixtures/grammars/norg_meta 27 | 28 | - name: Install tree-sitter CLI 29 | run: | 30 | cd test/fixtures/grammars/norg_meta 31 | npm install tree-sitter-cli 32 | 33 | - name: Run tests 34 | run: | 35 | cd test/fixtures/grammars/norg_meta 36 | ./node_modules/tree-sitter-cli/tree-sitter test 37 | -------------------------------------------------------------------------------- /.github/workflows/tree-sitter-norg-meta.rockspec.template: -------------------------------------------------------------------------------- 1 | local git_ref = '$git_ref' 2 | local modrev = '$modrev' 3 | local specrev = '$specrev' 4 | 5 | local repo_url = '$repo_url' 6 | 7 | rockspec_format = '3.0' 8 | package = '$package' 9 | version = modrev ..'-'.. specrev 10 | 11 | description = { 12 | summary = '$summary', 13 | labels = $labels, 14 | homepage = '$homepage', 15 | $license 16 | } 17 | 18 | build_dependencies = { 19 | 'luarocks-build-treesitter-parser >= 1.3.0', 20 | } 21 | 22 | source = { 23 | url = repo_url .. '/archive/' .. git_ref .. '.zip', 24 | dir = '$repo_name-' .. '$archive_dir_suffix', 25 | } 26 | 27 | build = { 28 | type = "treesitter-parser", 29 | lang = "norg_meta", 30 | sources = { "src/parser.c" }, 31 | } 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | Cargo.lock 4 | package-lock.json 5 | yarn.lock 6 | *.log 7 | result 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.1.0 (2024-04-13) 4 | 5 | 6 | ### ⚠ BREAKING CHANGES 7 | 8 | * rewrite the parser to be more error prone 9 | 10 | ### Features 11 | 12 | * add luarocks support ([2673f0e](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/2673f0e57694347bc55bcaf319cb8e0a5e7a4c29)) 13 | * basic delimiter support ([7268ed1](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/7268ed1e2571b21c0ec728b94f06984f7b9ba4be)) 14 | * basic statement_group support ([90a73d1](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/90a73d19f7bdc678ef1e7d40936f1a60e7cd0888)) 15 | * change some node names, add support for nested objects + arrays, write new tests ([7c9057c](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/7c9057ca182bfbcb52d5f9f2e4ea3da21b43c7fb)) 16 | * crude trailing modifier support ([22ae523](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/22ae5236e5e349acd183d32f372ce7184dad1f40)) 17 | * rewrite parser to make it more flexible ([35d9f25](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/35d9f25b440959eec1cf671632757357aa0425d9)) 18 | * rewrite the parser to be more error prone ([0a00389](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/0a003896cf7bb42f52b5f188a90e42f8f3fbe57d)) 19 | * veeery crude named delimiter support ([17741af](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/17741afcf6fd94b81399dab47ca9ece6456c9741)) 20 | 21 | 22 | ### Bug Fixes 23 | 24 | * allow one-char values for pairs ([4687b53](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/4687b53e656b920cde6c0b9a7b9acf9a665cd838)) 25 | * **ast:** don't make the separator a part of `key` ([bf5a57d](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/bf5a57dd74b22048aac72be2a71e13f1fc718e83)) 26 | * broken parsing of values with special chars ([e93dcbc](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/e93dcbc56a472649547cfc288f10ae4a93ef8795)) 27 | * incorrect detection of trailing modifiers ([#3](https://github.com/nvim-neorg/tree-sitter-norg-meta/issues/3)) ([323ef05](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/323ef0576e95d7c530546f6954362173fbaa56ac)) 28 | * multi word descriptions ([ab7f37f](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/ab7f37f9186fdb49a9f9d764079b24db8556830c)) 29 | * remove hard-coded space groups ([99b1ffc](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/99b1ffcc5d1f0fb9a0edb382980ddf21e0f0d546)) 30 | * repo links ([8d9792b](https://github.com/nvim-neorg/tree-sitter-norg-meta/commit/8d9792bf94a22e4a1d0fdf6de52e099c471bf26e)) 31 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tree-sitter-norg-meta" 3 | description = "norg-meta grammar for the tree-sitter parsing library" 4 | version = "0.1.0" 5 | keywords = ["incremental", "parsing", "norg-meta"] 6 | categories = ["parsing", "text-editors"] 7 | repository = "https://github.com/tree-sitter/tree-sitter-norg-meta" 8 | edition = "2018" 9 | license = "MIT" 10 | 11 | build = "bindings/rust/build.rs" 12 | include = [ 13 | "bindings/rust/*", 14 | "grammar.js", 15 | "queries/*", 16 | "src/*", 17 | ] 18 | 19 | [lib] 20 | path = "bindings/rust/lib.rs" 21 | 22 | [dependencies] 23 | tree-sitter = "~0.20.0" 24 | 25 | [build-dependencies] 26 | cc = "1.0" 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Neorg 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NFF Metadata TreeSitter Parser 2 | 3 | 4 | 5 | A TreeSitter grammar for [Neorg's](https://github.com/nvim-neorg/neorg) `document.meta` format. 6 | 7 | ## Available Commands 8 | | Command | Result | 9 | |-------------|-------------------------------------------------------------------------------------| 10 | | `yarn` | installs needed dependencies (only do if you don't have `tree-sitter` in your path) | 11 | | `yarn gen` | `tree-sitter generate && node-gyp build` | 12 | | `yarn test` | `tree-sitter test` | 13 | 14 | - `npm` can be used instead of `yarn` 15 | - When `yarn` is used with no args then it's replaced with `node install` 16 | 17 | # :heart: Contribution 18 | If you know a thing or two about TreeSitter and would like to support us by contributing then please do! 19 | If you have any questions you can ask away in the Github issues or on our discord! The specification can be found in the 20 | `docs/` directory in the [Neorg Repo](https://github.com/nvim-neorg/neorg). 21 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | "target_name": "tree_sitter_norg_meta_binding", 5 | "include_dirs": [ 6 | " 3 | #include "nan.h" 4 | 5 | using namespace v8; 6 | 7 | extern "C" TSLanguage * tree_sitter_norg_meta(); 8 | 9 | namespace { 10 | 11 | NAN_METHOD(New) {} 12 | 13 | void Init(Local exports, Local module) { 14 | Local tpl = Nan::New(New); 15 | tpl->SetClassName(Nan::New("Language").ToLocalChecked()); 16 | tpl->InstanceTemplate()->SetInternalFieldCount(1); 17 | 18 | Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); 19 | Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); 20 | Nan::SetInternalFieldPointer(instance, 0, tree_sitter_norg_meta()); 21 | 22 | Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("norg_meta").ToLocalChecked()); 23 | Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); 24 | } 25 | 26 | NODE_MODULE(tree_sitter_norg_meta_binding, Init) 27 | 28 | } // namespace 29 | -------------------------------------------------------------------------------- /bindings/node/index.js: -------------------------------------------------------------------------------- 1 | try { 2 | module.exports = require("../../build/Release/tree_sitter_norg_meta_binding"); 3 | } catch (error1) { 4 | if (error1.code !== 'MODULE_NOT_FOUND') { 5 | throw error1; 6 | } 7 | try { 8 | module.exports = require("../../build/Debug/tree_sitter_norg_meta_binding"); 9 | } catch (error2) { 10 | if (error2.code !== 'MODULE_NOT_FOUND') { 11 | throw error2; 12 | } 13 | throw error1 14 | } 15 | } 16 | 17 | try { 18 | module.exports.nodeTypeInfo = require("../../src/node-types.json"); 19 | } catch (_) {} 20 | -------------------------------------------------------------------------------- /bindings/rust/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let src_dir = std::path::Path::new("src"); 3 | 4 | let mut c_config = cc::Build::new(); 5 | c_config.include(&src_dir); 6 | c_config 7 | .flag_if_supported("-Wno-unused-parameter") 8 | .flag_if_supported("-Wno-unused-but-set-variable") 9 | .flag_if_supported("-Wno-trigraphs"); 10 | let parser_path = src_dir.join("parser.c"); 11 | c_config.file(&parser_path); 12 | 13 | // If your language uses an external scanner written in C, 14 | // then include this block of code: 15 | 16 | /* 17 | let scanner_path = src_dir.join("scanner.c"); 18 | c_config.file(&scanner_path); 19 | println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); 20 | */ 21 | 22 | c_config.compile("parser"); 23 | println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); 24 | 25 | // If your language uses an external scanner written in C++, 26 | // then include this block of code: 27 | 28 | /* 29 | let mut cpp_config = cc::Build::new(); 30 | cpp_config.cpp(true); 31 | cpp_config.include(&src_dir); 32 | cpp_config 33 | .flag_if_supported("-Wno-unused-parameter") 34 | .flag_if_supported("-Wno-unused-but-set-variable"); 35 | let scanner_path = src_dir.join("scanner.cc"); 36 | cpp_config.file(&scanner_path); 37 | cpp_config.compile("scanner"); 38 | println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); 39 | */ 40 | } 41 | -------------------------------------------------------------------------------- /bindings/rust/lib.rs: -------------------------------------------------------------------------------- 1 | //! This crate provides norg_meta language support for the [tree-sitter][] parsing library. 2 | //! 3 | //! Typically, you will use the [language][language func] function to add this language to a 4 | //! tree-sitter [Parser][], and then use the parser to parse some code: 5 | //! 6 | //! ``` 7 | //! let code = ""; 8 | //! let mut parser = tree_sitter::Parser::new(); 9 | //! parser.set_language(tree_sitter_norg_meta::language()).expect("Error loading norg_meta grammar"); 10 | //! let tree = parser.parse(code, None).unwrap(); 11 | //! ``` 12 | //! 13 | //! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html 14 | //! [language func]: fn.language.html 15 | //! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html 16 | //! [tree-sitter]: https://tree-sitter.github.io/ 17 | 18 | use tree_sitter::Language; 19 | 20 | extern "C" { 21 | fn tree_sitter_norg_meta() -> Language; 22 | } 23 | 24 | /// Get the tree-sitter [Language][] for this grammar. 25 | /// 26 | /// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html 27 | pub fn language() -> Language { 28 | unsafe { tree_sitter_norg_meta() } 29 | } 30 | 31 | /// The content of the [`node-types.json`][] file for this grammar. 32 | /// 33 | /// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types 34 | pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json"); 35 | 36 | // Uncomment these to include any queries that this grammar contains 37 | 38 | // pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); 39 | // pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); 40 | // pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); 41 | // pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm"); 42 | 43 | #[cfg(test)] 44 | mod tests { 45 | #[test] 46 | fn test_can_load_grammar() { 47 | let mut parser = tree_sitter::Parser::new(); 48 | parser 49 | .set_language(super::language()) 50 | .expect("Error loading norg_meta language"); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /default.nix: -------------------------------------------------------------------------------- 1 | (import 2 | ( 3 | let 4 | lock = builtins.fromJSON (builtins.readFile ./flake.lock); 5 | in 6 | fetchTarball { 7 | url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; 8 | sha256 = lock.nodes.flake-compat.locked.narHash; 9 | } 10 | ) 11 | { 12 | src = ./.; 13 | }).defaultNix 14 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "flake-compat": { 4 | "flake": false, 5 | "locked": { 6 | "lastModified": 1641205782, 7 | "narHash": "sha256-4jY7RCWUoZ9cKD8co0/4tFARpWB+57+r1bLLvXNJliY=", 8 | "owner": "edolstra", 9 | "repo": "flake-compat", 10 | "rev": "b7547d3eed6f32d06102ead8991ec52ab0a4f1a7", 11 | "type": "github" 12 | }, 13 | "original": { 14 | "owner": "edolstra", 15 | "repo": "flake-compat", 16 | "type": "github" 17 | } 18 | }, 19 | "flake-utils": { 20 | "locked": { 21 | "lastModified": 1644229661, 22 | "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", 23 | "owner": "numtide", 24 | "repo": "flake-utils", 25 | "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", 26 | "type": "github" 27 | }, 28 | "original": { 29 | "owner": "numtide", 30 | "repo": "flake-utils", 31 | "type": "github" 32 | } 33 | }, 34 | "nixpkgs": { 35 | "locked": { 36 | "lastModified": 1644486793, 37 | "narHash": "sha256-EeijR4guVHgVv+JpOX3cQO+1XdrkJfGmiJ9XVsVU530=", 38 | "owner": "NixOS", 39 | "repo": "nixpkgs", 40 | "rev": "1882c6b7368fd284ad01b0a5b5601ef136321292", 41 | "type": "github" 42 | }, 43 | "original": { 44 | "owner": "NixOS", 45 | "ref": "nixpkgs-unstable", 46 | "repo": "nixpkgs", 47 | "type": "github" 48 | } 49 | }, 50 | "root": { 51 | "inputs": { 52 | "flake-compat": "flake-compat", 53 | "flake-utils": "flake-utils", 54 | "nixpkgs": "nixpkgs" 55 | } 56 | } 57 | }, 58 | "root": "root", 59 | "version": 7 60 | } 61 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | inputs = { 3 | nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; 4 | flake-utils.url = "github:numtide/flake-utils"; 5 | flake-compat = { 6 | url = "github:edolstra/flake-compat"; 7 | flake = false; 8 | }; 9 | }; 10 | outputs = { self, nixpkgs, flake-utils, ... }@inputs: 11 | (flake-utils.lib.eachDefaultSystem (system: 12 | let 13 | pkgs = import nixpkgs { inherit system; }; 14 | grammar = pkgs.callPackage 15 | "${nixpkgs}/pkgs/development/tools/parsing/tree-sitter/grammar.nix" { }; 16 | in rec { 17 | packages.tree-sitter-norg-meta = grammar { 18 | language = "norg-meta"; 19 | source = ./.; 20 | inherit (pkgs.tree-sitter) version; 21 | }; 22 | defaultPackage = packages.tree-sitter-norg-meta; 23 | devShell = pkgs.mkShell { 24 | nativeBuildInputs = with pkgs; [ 25 | python3 26 | nodejs 27 | nodePackages.node-gyp 28 | tree-sitter 29 | ]; 30 | }; 31 | })); 32 | } 33 | -------------------------------------------------------------------------------- /grammar.js: -------------------------------------------------------------------------------- 1 | let newline = choice("\n", "\r", "\r\n"); 2 | let newline_or_eof = choice("\n", "\r", "\r\n", "\0"); 3 | 4 | const precs = { 5 | non_string: 1, 6 | key: 2, 7 | above_key: 3, 8 | }; 9 | 10 | module.exports = grammar({ 11 | name: "norg_meta", 12 | 13 | extras: ($) => [], 14 | 15 | supertypes: ($) => [$.value], 16 | 17 | rules: { 18 | metadata: ($) => 19 | seq( 20 | repeat(newline), 21 | repeat( 22 | seq( 23 | optional($._whitespace), 24 | choice($.pair, $.delimiter), 25 | repeat1(newline_or_eof) 26 | ) 27 | ) 28 | ), 29 | 30 | _whitespace: (_) => 31 | token(prec(precs.non_string, /[\t                 ]+/)), 32 | 33 | key: (_) => token(prec(precs.key, /[^\s:]+/)), 34 | 35 | number: (_) => token(/\d+/), 36 | 37 | array: ($) => 38 | seq( 39 | token(prec(precs.non_string, "[")), 40 | optional(token(prec(precs.non_string, /[\n\r\s]+/))), 41 | optional( 42 | seq( 43 | $.value, 44 | repeat( 45 | prec.left( 46 | seq( 47 | repeat1(newline), 48 | optional($._whitespace), 49 | optional($.value) 50 | ) 51 | ) 52 | ) 53 | ) 54 | ), 55 | token(prec(precs.non_string, "]")) 56 | ), 57 | 58 | string: (_) => /[^\n]+/, 59 | 60 | object: ($) => 61 | seq( 62 | token(prec(precs.non_string, "{")), 63 | optional(token(prec(precs.above_key, /[\n\r\s]+/))), 64 | optional( 65 | seq( 66 | choice($.pair, $.delimiter), 67 | repeat( 68 | prec.left( 69 | seq( 70 | repeat1(newline), 71 | optional($._whitespace), 72 | optional(choice($.pair, $.delimiter)) 73 | ) 74 | ) 75 | ) 76 | ) 77 | ), 78 | token(prec(precs.above_key, "}")) 79 | ), 80 | 81 | value: ($) => choice($.number, $.string, $.array, $.object), 82 | 83 | pair: ($) => 84 | prec.right( 85 | seq($.key, ":", optional(seq($._whitespace, optional($.value)))) 86 | ), 87 | 88 | delimiter: ($) => 89 | seq(token(prec(precs.above_key, /-+/)), optional(/.+/)), 90 | }, 91 | }); 92 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tree-sitter-norg-meta", 3 | "version": "0.1.0", 4 | "description": "A TreeSitter Parser For The NFF Metadata", 5 | "main": "bindings/node", 6 | "scripts": { 7 | "gen": "tree-sitter generate && node-gyp build", 8 | "test": "tree-sitter test", 9 | "parse": "tree-sitter parse" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/nvim-neorg/tree-sitter-norg-meta.git" 14 | }, 15 | "keywords": [ 16 | "neorg", 17 | "norg", 18 | "meta", 19 | "metadata", 20 | "treesitter", 21 | "tree-sitter" 22 | ], 23 | "author": "nvim-neorg", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/nvim-neorg/tree-sitter-norg-meta/issues" 27 | }, 28 | "homepage": "https://github.com/nvim-neorg/tree-sitter-norg-meta#readme", 29 | "dependencies": { 30 | "nan": "^2.15.0" 31 | }, 32 | "devDependencies": { 33 | "tree-sitter-cli": "^0.20.0" 34 | }, 35 | "tree-sitter": [ 36 | { 37 | "scope": "document.norg_meta", 38 | "file-types": [ 39 | "norg_meta" 40 | ] 41 | } 42 | ] 43 | } 44 | -------------------------------------------------------------------------------- /queries/highlights.scm: -------------------------------------------------------------------------------- 1 | (key) @keyword 2 | (value) @string 3 | -------------------------------------------------------------------------------- /src/grammar.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "norg_meta", 3 | "rules": { 4 | "metadata": { 5 | "type": "SEQ", 6 | "members": [ 7 | { 8 | "type": "REPEAT", 9 | "content": { 10 | "type": "CHOICE", 11 | "members": [ 12 | { 13 | "type": "STRING", 14 | "value": "\n" 15 | }, 16 | { 17 | "type": "STRING", 18 | "value": "\r" 19 | }, 20 | { 21 | "type": "STRING", 22 | "value": "\r\n" 23 | } 24 | ] 25 | } 26 | }, 27 | { 28 | "type": "REPEAT", 29 | "content": { 30 | "type": "SEQ", 31 | "members": [ 32 | { 33 | "type": "CHOICE", 34 | "members": [ 35 | { 36 | "type": "SYMBOL", 37 | "name": "_whitespace" 38 | }, 39 | { 40 | "type": "BLANK" 41 | } 42 | ] 43 | }, 44 | { 45 | "type": "CHOICE", 46 | "members": [ 47 | { 48 | "type": "SYMBOL", 49 | "name": "pair" 50 | }, 51 | { 52 | "type": "SYMBOL", 53 | "name": "delimiter" 54 | } 55 | ] 56 | }, 57 | { 58 | "type": "REPEAT1", 59 | "content": { 60 | "type": "CHOICE", 61 | "members": [ 62 | { 63 | "type": "STRING", 64 | "value": "\n" 65 | }, 66 | { 67 | "type": "STRING", 68 | "value": "\r" 69 | }, 70 | { 71 | "type": "STRING", 72 | "value": "\r\n" 73 | }, 74 | { 75 | "type": "STRING", 76 | "value": "\u0000" 77 | } 78 | ] 79 | } 80 | } 81 | ] 82 | } 83 | } 84 | ] 85 | }, 86 | "_whitespace": { 87 | "type": "TOKEN", 88 | "content": { 89 | "type": "PREC", 90 | "value": 1, 91 | "content": { 92 | "type": "PATTERN", 93 | "value": "[\\t                 ]+" 94 | } 95 | } 96 | }, 97 | "key": { 98 | "type": "TOKEN", 99 | "content": { 100 | "type": "PREC", 101 | "value": 2, 102 | "content": { 103 | "type": "PATTERN", 104 | "value": "[^\\s:]+" 105 | } 106 | } 107 | }, 108 | "number": { 109 | "type": "TOKEN", 110 | "content": { 111 | "type": "PATTERN", 112 | "value": "\\d+" 113 | } 114 | }, 115 | "array": { 116 | "type": "SEQ", 117 | "members": [ 118 | { 119 | "type": "TOKEN", 120 | "content": { 121 | "type": "PREC", 122 | "value": 1, 123 | "content": { 124 | "type": "STRING", 125 | "value": "[" 126 | } 127 | } 128 | }, 129 | { 130 | "type": "CHOICE", 131 | "members": [ 132 | { 133 | "type": "TOKEN", 134 | "content": { 135 | "type": "PREC", 136 | "value": 1, 137 | "content": { 138 | "type": "PATTERN", 139 | "value": "[\\n\\r\\s]+" 140 | } 141 | } 142 | }, 143 | { 144 | "type": "BLANK" 145 | } 146 | ] 147 | }, 148 | { 149 | "type": "CHOICE", 150 | "members": [ 151 | { 152 | "type": "SEQ", 153 | "members": [ 154 | { 155 | "type": "SYMBOL", 156 | "name": "value" 157 | }, 158 | { 159 | "type": "REPEAT", 160 | "content": { 161 | "type": "PREC_LEFT", 162 | "value": 0, 163 | "content": { 164 | "type": "SEQ", 165 | "members": [ 166 | { 167 | "type": "REPEAT1", 168 | "content": { 169 | "type": "CHOICE", 170 | "members": [ 171 | { 172 | "type": "STRING", 173 | "value": "\n" 174 | }, 175 | { 176 | "type": "STRING", 177 | "value": "\r" 178 | }, 179 | { 180 | "type": "STRING", 181 | "value": "\r\n" 182 | } 183 | ] 184 | } 185 | }, 186 | { 187 | "type": "CHOICE", 188 | "members": [ 189 | { 190 | "type": "SYMBOL", 191 | "name": "_whitespace" 192 | }, 193 | { 194 | "type": "BLANK" 195 | } 196 | ] 197 | }, 198 | { 199 | "type": "CHOICE", 200 | "members": [ 201 | { 202 | "type": "SYMBOL", 203 | "name": "value" 204 | }, 205 | { 206 | "type": "BLANK" 207 | } 208 | ] 209 | } 210 | ] 211 | } 212 | } 213 | } 214 | ] 215 | }, 216 | { 217 | "type": "BLANK" 218 | } 219 | ] 220 | }, 221 | { 222 | "type": "TOKEN", 223 | "content": { 224 | "type": "PREC", 225 | "value": 1, 226 | "content": { 227 | "type": "STRING", 228 | "value": "]" 229 | } 230 | } 231 | } 232 | ] 233 | }, 234 | "string": { 235 | "type": "PATTERN", 236 | "value": "[^\\n]+" 237 | }, 238 | "object": { 239 | "type": "SEQ", 240 | "members": [ 241 | { 242 | "type": "TOKEN", 243 | "content": { 244 | "type": "PREC", 245 | "value": 1, 246 | "content": { 247 | "type": "STRING", 248 | "value": "{" 249 | } 250 | } 251 | }, 252 | { 253 | "type": "CHOICE", 254 | "members": [ 255 | { 256 | "type": "TOKEN", 257 | "content": { 258 | "type": "PREC", 259 | "value": 3, 260 | "content": { 261 | "type": "PATTERN", 262 | "value": "[\\n\\r\\s]+" 263 | } 264 | } 265 | }, 266 | { 267 | "type": "BLANK" 268 | } 269 | ] 270 | }, 271 | { 272 | "type": "CHOICE", 273 | "members": [ 274 | { 275 | "type": "SEQ", 276 | "members": [ 277 | { 278 | "type": "CHOICE", 279 | "members": [ 280 | { 281 | "type": "SYMBOL", 282 | "name": "pair" 283 | }, 284 | { 285 | "type": "SYMBOL", 286 | "name": "delimiter" 287 | } 288 | ] 289 | }, 290 | { 291 | "type": "REPEAT", 292 | "content": { 293 | "type": "PREC_LEFT", 294 | "value": 0, 295 | "content": { 296 | "type": "SEQ", 297 | "members": [ 298 | { 299 | "type": "REPEAT1", 300 | "content": { 301 | "type": "CHOICE", 302 | "members": [ 303 | { 304 | "type": "STRING", 305 | "value": "\n" 306 | }, 307 | { 308 | "type": "STRING", 309 | "value": "\r" 310 | }, 311 | { 312 | "type": "STRING", 313 | "value": "\r\n" 314 | } 315 | ] 316 | } 317 | }, 318 | { 319 | "type": "CHOICE", 320 | "members": [ 321 | { 322 | "type": "SYMBOL", 323 | "name": "_whitespace" 324 | }, 325 | { 326 | "type": "BLANK" 327 | } 328 | ] 329 | }, 330 | { 331 | "type": "CHOICE", 332 | "members": [ 333 | { 334 | "type": "CHOICE", 335 | "members": [ 336 | { 337 | "type": "SYMBOL", 338 | "name": "pair" 339 | }, 340 | { 341 | "type": "SYMBOL", 342 | "name": "delimiter" 343 | } 344 | ] 345 | }, 346 | { 347 | "type": "BLANK" 348 | } 349 | ] 350 | } 351 | ] 352 | } 353 | } 354 | } 355 | ] 356 | }, 357 | { 358 | "type": "BLANK" 359 | } 360 | ] 361 | }, 362 | { 363 | "type": "TOKEN", 364 | "content": { 365 | "type": "PREC", 366 | "value": 3, 367 | "content": { 368 | "type": "STRING", 369 | "value": "}" 370 | } 371 | } 372 | } 373 | ] 374 | }, 375 | "value": { 376 | "type": "CHOICE", 377 | "members": [ 378 | { 379 | "type": "SYMBOL", 380 | "name": "number" 381 | }, 382 | { 383 | "type": "SYMBOL", 384 | "name": "string" 385 | }, 386 | { 387 | "type": "SYMBOL", 388 | "name": "array" 389 | }, 390 | { 391 | "type": "SYMBOL", 392 | "name": "object" 393 | } 394 | ] 395 | }, 396 | "pair": { 397 | "type": "PREC_RIGHT", 398 | "value": 0, 399 | "content": { 400 | "type": "SEQ", 401 | "members": [ 402 | { 403 | "type": "SYMBOL", 404 | "name": "key" 405 | }, 406 | { 407 | "type": "STRING", 408 | "value": ":" 409 | }, 410 | { 411 | "type": "CHOICE", 412 | "members": [ 413 | { 414 | "type": "SEQ", 415 | "members": [ 416 | { 417 | "type": "SYMBOL", 418 | "name": "_whitespace" 419 | }, 420 | { 421 | "type": "CHOICE", 422 | "members": [ 423 | { 424 | "type": "SYMBOL", 425 | "name": "value" 426 | }, 427 | { 428 | "type": "BLANK" 429 | } 430 | ] 431 | } 432 | ] 433 | }, 434 | { 435 | "type": "BLANK" 436 | } 437 | ] 438 | } 439 | ] 440 | } 441 | }, 442 | "delimiter": { 443 | "type": "SEQ", 444 | "members": [ 445 | { 446 | "type": "TOKEN", 447 | "content": { 448 | "type": "PREC", 449 | "value": 3, 450 | "content": { 451 | "type": "PATTERN", 452 | "value": "-+" 453 | } 454 | } 455 | }, 456 | { 457 | "type": "CHOICE", 458 | "members": [ 459 | { 460 | "type": "PATTERN", 461 | "value": ".+" 462 | }, 463 | { 464 | "type": "BLANK" 465 | } 466 | ] 467 | } 468 | ] 469 | } 470 | }, 471 | "extras": [], 472 | "conflicts": [], 473 | "precedences": [], 474 | "externals": [], 475 | "inline": [], 476 | "supertypes": [ 477 | "value" 478 | ] 479 | } 480 | 481 | -------------------------------------------------------------------------------- /src/node-types.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "type": "value", 4 | "named": true, 5 | "subtypes": [ 6 | { 7 | "type": "array", 8 | "named": true 9 | }, 10 | { 11 | "type": "number", 12 | "named": true 13 | }, 14 | { 15 | "type": "object", 16 | "named": true 17 | }, 18 | { 19 | "type": "string", 20 | "named": true 21 | } 22 | ] 23 | }, 24 | { 25 | "type": "array", 26 | "named": true, 27 | "fields": {}, 28 | "children": { 29 | "multiple": true, 30 | "required": false, 31 | "types": [ 32 | { 33 | "type": "value", 34 | "named": true 35 | } 36 | ] 37 | } 38 | }, 39 | { 40 | "type": "delimiter", 41 | "named": true, 42 | "fields": {} 43 | }, 44 | { 45 | "type": "metadata", 46 | "named": true, 47 | "fields": {}, 48 | "children": { 49 | "multiple": true, 50 | "required": false, 51 | "types": [ 52 | { 53 | "type": "delimiter", 54 | "named": true 55 | }, 56 | { 57 | "type": "pair", 58 | "named": true 59 | } 60 | ] 61 | } 62 | }, 63 | { 64 | "type": "object", 65 | "named": true, 66 | "fields": {}, 67 | "children": { 68 | "multiple": true, 69 | "required": false, 70 | "types": [ 71 | { 72 | "type": "delimiter", 73 | "named": true 74 | }, 75 | { 76 | "type": "pair", 77 | "named": true 78 | } 79 | ] 80 | } 81 | }, 82 | { 83 | "type": "pair", 84 | "named": true, 85 | "fields": {}, 86 | "children": { 87 | "multiple": true, 88 | "required": true, 89 | "types": [ 90 | { 91 | "type": "key", 92 | "named": true 93 | }, 94 | { 95 | "type": "value", 96 | "named": true 97 | } 98 | ] 99 | } 100 | }, 101 | { 102 | "type": "\u0000", 103 | "named": false 104 | }, 105 | { 106 | "type": "\n", 107 | "named": false 108 | }, 109 | { 110 | "type": "\r", 111 | "named": false 112 | }, 113 | { 114 | "type": "\r\n", 115 | "named": false 116 | }, 117 | { 118 | "type": ":", 119 | "named": false 120 | }, 121 | { 122 | "type": "[", 123 | "named": false 124 | }, 125 | { 126 | "type": "]", 127 | "named": false 128 | }, 129 | { 130 | "type": "key", 131 | "named": true 132 | }, 133 | { 134 | "type": "number", 135 | "named": true 136 | }, 137 | { 138 | "type": "string", 139 | "named": true 140 | }, 141 | { 142 | "type": "{", 143 | "named": false 144 | }, 145 | { 146 | "type": "}", 147 | "named": false 148 | } 149 | ] -------------------------------------------------------------------------------- /src/parser.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #if defined(__GNUC__) || defined(__clang__) 4 | #pragma GCC diagnostic push 5 | #pragma GCC diagnostic ignored "-Wmissing-field-initializers" 6 | #endif 7 | 8 | #define LANGUAGE_VERSION 14 9 | #define STATE_COUNT 57 10 | #define LARGE_STATE_COUNT 2 11 | #define SYMBOL_COUNT 29 12 | #define ALIAS_COUNT 0 13 | #define TOKEN_COUNT 18 14 | #define EXTERNAL_TOKEN_COUNT 0 15 | #define FIELD_COUNT 0 16 | #define MAX_ALIAS_SEQUENCE_LENGTH 5 17 | #define PRODUCTION_ID_COUNT 1 18 | 19 | enum { 20 | anon_sym_LF = 1, 21 | anon_sym_CR = 2, 22 | anon_sym_CR_LF = 3, 23 | anon_sym_ = 4, 24 | sym__whitespace = 5, 25 | sym_key = 6, 26 | sym_number = 7, 27 | anon_sym_LBRACK = 8, 28 | aux_sym_array_token1 = 9, 29 | anon_sym_RBRACK = 10, 30 | sym_string = 11, 31 | anon_sym_LBRACE = 12, 32 | aux_sym_object_token1 = 13, 33 | anon_sym_RBRACE = 14, 34 | anon_sym_COLON = 15, 35 | aux_sym_delimiter_token1 = 16, 36 | aux_sym_delimiter_token2 = 17, 37 | sym_metadata = 18, 38 | sym_array = 19, 39 | sym_object = 20, 40 | sym_value = 21, 41 | sym_pair = 22, 42 | sym_delimiter = 23, 43 | aux_sym_metadata_repeat1 = 24, 44 | aux_sym_metadata_repeat2 = 25, 45 | aux_sym_metadata_repeat3 = 26, 46 | aux_sym_array_repeat1 = 27, 47 | aux_sym_object_repeat1 = 28, 48 | }; 49 | 50 | static const char * const ts_symbol_names[] = { 51 | [ts_builtin_sym_end] = "end", 52 | [anon_sym_LF] = "\n", 53 | [anon_sym_CR] = "\r", 54 | [anon_sym_CR_LF] = "\r\n", 55 | [anon_sym_] = "", 56 | [sym__whitespace] = "_whitespace", 57 | [sym_key] = "key", 58 | [sym_number] = "number", 59 | [anon_sym_LBRACK] = "[", 60 | [aux_sym_array_token1] = "array_token1", 61 | [anon_sym_RBRACK] = "]", 62 | [sym_string] = "string", 63 | [anon_sym_LBRACE] = "{", 64 | [aux_sym_object_token1] = "object_token1", 65 | [anon_sym_RBRACE] = "}", 66 | [anon_sym_COLON] = ":", 67 | [aux_sym_delimiter_token1] = "delimiter_token1", 68 | [aux_sym_delimiter_token2] = "delimiter_token2", 69 | [sym_metadata] = "metadata", 70 | [sym_array] = "array", 71 | [sym_object] = "object", 72 | [sym_value] = "value", 73 | [sym_pair] = "pair", 74 | [sym_delimiter] = "delimiter", 75 | [aux_sym_metadata_repeat1] = "metadata_repeat1", 76 | [aux_sym_metadata_repeat2] = "metadata_repeat2", 77 | [aux_sym_metadata_repeat3] = "metadata_repeat3", 78 | [aux_sym_array_repeat1] = "array_repeat1", 79 | [aux_sym_object_repeat1] = "object_repeat1", 80 | }; 81 | 82 | static const TSSymbol ts_symbol_map[] = { 83 | [ts_builtin_sym_end] = ts_builtin_sym_end, 84 | [anon_sym_LF] = anon_sym_LF, 85 | [anon_sym_CR] = anon_sym_CR, 86 | [anon_sym_CR_LF] = anon_sym_CR_LF, 87 | [anon_sym_] = anon_sym_, 88 | [sym__whitespace] = sym__whitespace, 89 | [sym_key] = sym_key, 90 | [sym_number] = sym_number, 91 | [anon_sym_LBRACK] = anon_sym_LBRACK, 92 | [aux_sym_array_token1] = aux_sym_array_token1, 93 | [anon_sym_RBRACK] = anon_sym_RBRACK, 94 | [sym_string] = sym_string, 95 | [anon_sym_LBRACE] = anon_sym_LBRACE, 96 | [aux_sym_object_token1] = aux_sym_object_token1, 97 | [anon_sym_RBRACE] = anon_sym_RBRACE, 98 | [anon_sym_COLON] = anon_sym_COLON, 99 | [aux_sym_delimiter_token1] = aux_sym_delimiter_token1, 100 | [aux_sym_delimiter_token2] = aux_sym_delimiter_token2, 101 | [sym_metadata] = sym_metadata, 102 | [sym_array] = sym_array, 103 | [sym_object] = sym_object, 104 | [sym_value] = sym_value, 105 | [sym_pair] = sym_pair, 106 | [sym_delimiter] = sym_delimiter, 107 | [aux_sym_metadata_repeat1] = aux_sym_metadata_repeat1, 108 | [aux_sym_metadata_repeat2] = aux_sym_metadata_repeat2, 109 | [aux_sym_metadata_repeat3] = aux_sym_metadata_repeat3, 110 | [aux_sym_array_repeat1] = aux_sym_array_repeat1, 111 | [aux_sym_object_repeat1] = aux_sym_object_repeat1, 112 | }; 113 | 114 | static const TSSymbolMetadata ts_symbol_metadata[] = { 115 | [ts_builtin_sym_end] = { 116 | .visible = false, 117 | .named = true, 118 | }, 119 | [anon_sym_LF] = { 120 | .visible = true, 121 | .named = false, 122 | }, 123 | [anon_sym_CR] = { 124 | .visible = true, 125 | .named = false, 126 | }, 127 | [anon_sym_CR_LF] = { 128 | .visible = true, 129 | .named = false, 130 | }, 131 | [anon_sym_] = { 132 | .visible = true, 133 | .named = false, 134 | }, 135 | [sym__whitespace] = { 136 | .visible = false, 137 | .named = true, 138 | }, 139 | [sym_key] = { 140 | .visible = true, 141 | .named = true, 142 | }, 143 | [sym_number] = { 144 | .visible = true, 145 | .named = true, 146 | }, 147 | [anon_sym_LBRACK] = { 148 | .visible = true, 149 | .named = false, 150 | }, 151 | [aux_sym_array_token1] = { 152 | .visible = false, 153 | .named = false, 154 | }, 155 | [anon_sym_RBRACK] = { 156 | .visible = true, 157 | .named = false, 158 | }, 159 | [sym_string] = { 160 | .visible = true, 161 | .named = true, 162 | }, 163 | [anon_sym_LBRACE] = { 164 | .visible = true, 165 | .named = false, 166 | }, 167 | [aux_sym_object_token1] = { 168 | .visible = false, 169 | .named = false, 170 | }, 171 | [anon_sym_RBRACE] = { 172 | .visible = true, 173 | .named = false, 174 | }, 175 | [anon_sym_COLON] = { 176 | .visible = true, 177 | .named = false, 178 | }, 179 | [aux_sym_delimiter_token1] = { 180 | .visible = false, 181 | .named = false, 182 | }, 183 | [aux_sym_delimiter_token2] = { 184 | .visible = false, 185 | .named = false, 186 | }, 187 | [sym_metadata] = { 188 | .visible = true, 189 | .named = true, 190 | }, 191 | [sym_array] = { 192 | .visible = true, 193 | .named = true, 194 | }, 195 | [sym_object] = { 196 | .visible = true, 197 | .named = true, 198 | }, 199 | [sym_value] = { 200 | .visible = false, 201 | .named = true, 202 | .supertype = true, 203 | }, 204 | [sym_pair] = { 205 | .visible = true, 206 | .named = true, 207 | }, 208 | [sym_delimiter] = { 209 | .visible = true, 210 | .named = true, 211 | }, 212 | [aux_sym_metadata_repeat1] = { 213 | .visible = false, 214 | .named = false, 215 | }, 216 | [aux_sym_metadata_repeat2] = { 217 | .visible = false, 218 | .named = false, 219 | }, 220 | [aux_sym_metadata_repeat3] = { 221 | .visible = false, 222 | .named = false, 223 | }, 224 | [aux_sym_array_repeat1] = { 225 | .visible = false, 226 | .named = false, 227 | }, 228 | [aux_sym_object_repeat1] = { 229 | .visible = false, 230 | .named = false, 231 | }, 232 | }; 233 | 234 | static const TSSymbol ts_alias_sequences[PRODUCTION_ID_COUNT][MAX_ALIAS_SEQUENCE_LENGTH] = { 235 | [0] = {0}, 236 | }; 237 | 238 | static const uint16_t ts_non_terminal_alias_map[] = { 239 | 0, 240 | }; 241 | 242 | static const TSStateId ts_primary_state_ids[STATE_COUNT] = { 243 | [0] = 0, 244 | [1] = 1, 245 | [2] = 2, 246 | [3] = 3, 247 | [4] = 4, 248 | [5] = 5, 249 | [6] = 4, 250 | [7] = 7, 251 | [8] = 8, 252 | [9] = 9, 253 | [10] = 10, 254 | [11] = 11, 255 | [12] = 12, 256 | [13] = 7, 257 | [14] = 14, 258 | [15] = 15, 259 | [16] = 7, 260 | [17] = 17, 261 | [18] = 18, 262 | [19] = 19, 263 | [20] = 20, 264 | [21] = 21, 265 | [22] = 22, 266 | [23] = 23, 267 | [24] = 24, 268 | [25] = 25, 269 | [26] = 26, 270 | [27] = 27, 271 | [28] = 28, 272 | [29] = 29, 273 | [30] = 30, 274 | [31] = 31, 275 | [32] = 32, 276 | [33] = 33, 277 | [34] = 34, 278 | [35] = 35, 279 | [36] = 36, 280 | [37] = 37, 281 | [38] = 38, 282 | [39] = 39, 283 | [40] = 40, 284 | [41] = 41, 285 | [42] = 41, 286 | [43] = 43, 287 | [44] = 44, 288 | [45] = 43, 289 | [46] = 46, 290 | [47] = 47, 291 | [48] = 48, 292 | [49] = 49, 293 | [50] = 50, 294 | [51] = 51, 295 | [52] = 52, 296 | [53] = 53, 297 | [54] = 54, 298 | [55] = 55, 299 | [56] = 55, 300 | }; 301 | 302 | static bool ts_lex(TSLexer *lexer, TSStateId state) { 303 | START_LEXER(); 304 | eof = lexer->eof(lexer); 305 | switch (state) { 306 | case 0: 307 | if (eof) ADVANCE(13); 308 | if (lookahead == 0) ADVANCE(25); 309 | if (lookahead == '\n') ADVANCE(35); 310 | if (lookahead == '\r') ADVANCE(33); 311 | if (lookahead == '-') ADVANCE(38); 312 | if (lookahead == ':') ADVANCE(37); 313 | if (lookahead == '[') ADVANCE(25); 314 | if (lookahead == ']') ADVANCE(25); 315 | if (lookahead == '{') ADVANCE(25); 316 | if (lookahead == '}') ADVANCE(36); 317 | if (lookahead == '\t' || 318 | lookahead == ' ') ADVANCE(34); 319 | if (('0' <= lookahead && lookahead <= '9')) ADVANCE(23); 320 | if (lookahead == 160 || 321 | lookahead == 5760 || 322 | (8192 <= lookahead && lookahead <= 8202) || 323 | lookahead == 8239 || 324 | lookahead == 8287 || 325 | lookahead == 12288) ADVANCE(24); 326 | if (lookahead != 0) ADVANCE(25); 327 | END_STATE(); 328 | case 1: 329 | if (lookahead == 0) ADVANCE(20); 330 | if (lookahead == '\n') ADVANCE(14); 331 | if (lookahead == '\r') ADVANCE(16); 332 | if (lookahead == '[') ADVANCE(27); 333 | if (lookahead == '{') ADVANCE(32); 334 | if (('0' <= lookahead && lookahead <= '9')) ADVANCE(26); 335 | if (lookahead != 0) ADVANCE(31); 336 | END_STATE(); 337 | case 2: 338 | if (lookahead == 0) ADVANCE(19); 339 | if (lookahead == '\n') ADVANCE(14); 340 | if (lookahead == '\r') ADVANCE(15); 341 | if (lookahead == ']') ADVANCE(30); 342 | if (lookahead == '}') ADVANCE(36); 343 | if (lookahead == '\t' || 344 | lookahead == ' ' || 345 | lookahead == 160 || 346 | lookahead == 5760 || 347 | (8192 <= lookahead && lookahead <= 8202) || 348 | lookahead == 8239 || 349 | lookahead == 8287 || 350 | lookahead == 12288) ADVANCE(22); 351 | END_STATE(); 352 | case 3: 353 | if (lookahead == 0) ADVANCE(21); 354 | if (lookahead == '\n') ADVANCE(14); 355 | if (lookahead == '\r') ADVANCE(17); 356 | if (lookahead != 0) ADVANCE(39); 357 | END_STATE(); 358 | case 4: 359 | if (lookahead == '\n') ADVANCE(14); 360 | if (lookahead == '\r') ADVANCE(15); 361 | if (lookahead == '-') ADVANCE(38); 362 | if (lookahead == '}') ADVANCE(36); 363 | if (lookahead == '\t' || 364 | lookahead == ' ') ADVANCE(22); 365 | if (lookahead == 160 || 366 | lookahead == 5760 || 367 | (8192 <= lookahead && lookahead <= 8202) || 368 | lookahead == 8239 || 369 | lookahead == 8287 || 370 | lookahead == 12288) ADVANCE(24); 371 | if (lookahead != 0 && 372 | lookahead != ':') ADVANCE(25); 373 | END_STATE(); 374 | case 5: 375 | if (lookahead == '\n') ADVANCE(14); 376 | if (lookahead == '\r') ADVANCE(16); 377 | if (lookahead == '[') ADVANCE(27); 378 | if (lookahead == ']') ADVANCE(30); 379 | if (lookahead == '{') ADVANCE(32); 380 | if (('0' <= lookahead && lookahead <= '9')) ADVANCE(26); 381 | if (lookahead == '\t' || 382 | lookahead == ' ' || 383 | lookahead == 160 || 384 | lookahead == 5760 || 385 | (8192 <= lookahead && lookahead <= 8202) || 386 | lookahead == 8239 || 387 | lookahead == 8287 || 388 | lookahead == 12288) ADVANCE(22); 389 | if (lookahead != 0) ADVANCE(31); 390 | END_STATE(); 391 | case 6: 392 | if (lookahead == '\n') ADVANCE(14); 393 | if (lookahead == '\r') ADVANCE(16); 394 | if (lookahead == '[') ADVANCE(27); 395 | if (lookahead == ']') ADVANCE(30); 396 | if (lookahead == '{') ADVANCE(32); 397 | if (('0' <= lookahead && lookahead <= '9')) ADVANCE(26); 398 | if (lookahead != 0) ADVANCE(31); 399 | END_STATE(); 400 | case 7: 401 | if (lookahead == '\n') ADVANCE(14); 402 | if (lookahead == '\r') ADVANCE(16); 403 | if (lookahead == '[') ADVANCE(27); 404 | if (lookahead == '{') ADVANCE(32); 405 | if (lookahead == '}') ADVANCE(36); 406 | if (('0' <= lookahead && lookahead <= '9')) ADVANCE(26); 407 | if (lookahead != 0) ADVANCE(31); 408 | END_STATE(); 409 | case 8: 410 | if (lookahead == '\n') ADVANCE(14); 411 | if (lookahead == '\r') ADVANCE(17); 412 | if (lookahead == '}') ADVANCE(36); 413 | if (lookahead != 0) ADVANCE(39); 414 | END_STATE(); 415 | case 9: 416 | if (lookahead == '\n') ADVANCE(29); 417 | if (lookahead == '[') ADVANCE(27); 418 | if (lookahead == ']') ADVANCE(30); 419 | if (lookahead == '{') ADVANCE(32); 420 | if (lookahead == '\t' || 421 | lookahead == '\r' || 422 | lookahead == ' ') ADVANCE(28); 423 | if (('0' <= lookahead && lookahead <= '9')) ADVANCE(26); 424 | if (lookahead != 0) ADVANCE(31); 425 | END_STATE(); 426 | case 10: 427 | if (lookahead == '-') ADVANCE(38); 428 | if (lookahead == '}') ADVANCE(36); 429 | if (lookahead == '\t' || 430 | lookahead == '\n' || 431 | lookahead == '\r' || 432 | lookahead == ' ') ADVANCE(35); 433 | if (lookahead != 0 && 434 | lookahead != ':') ADVANCE(25); 435 | END_STATE(); 436 | case 11: 437 | if (lookahead == '[') ADVANCE(27); 438 | if (lookahead == ']') ADVANCE(30); 439 | if (lookahead == '{') ADVANCE(32); 440 | if (('0' <= lookahead && lookahead <= '9')) ADVANCE(26); 441 | if (lookahead != 0 && 442 | lookahead != '\n') ADVANCE(31); 443 | END_STATE(); 444 | case 12: 445 | if (eof) ADVANCE(13); 446 | if (lookahead == 0) ADVANCE(25); 447 | if (lookahead == '\n') ADVANCE(14); 448 | if (lookahead == '\r') ADVANCE(15); 449 | if (lookahead == '-') ADVANCE(38); 450 | if (lookahead == '\t' || 451 | lookahead == ' ') ADVANCE(22); 452 | if (lookahead == 160 || 453 | lookahead == 5760 || 454 | (8192 <= lookahead && lookahead <= 8202) || 455 | lookahead == 8239 || 456 | lookahead == 8287 || 457 | lookahead == 12288) ADVANCE(24); 458 | if (lookahead != 0 && 459 | lookahead != ':') ADVANCE(25); 460 | END_STATE(); 461 | case 13: 462 | ACCEPT_TOKEN(ts_builtin_sym_end); 463 | END_STATE(); 464 | case 14: 465 | ACCEPT_TOKEN(anon_sym_LF); 466 | END_STATE(); 467 | case 15: 468 | ACCEPT_TOKEN(anon_sym_CR); 469 | if (lookahead == '\n') ADVANCE(18); 470 | END_STATE(); 471 | case 16: 472 | ACCEPT_TOKEN(anon_sym_CR); 473 | if (lookahead == '\n') ADVANCE(18); 474 | if (lookahead != 0) ADVANCE(31); 475 | END_STATE(); 476 | case 17: 477 | ACCEPT_TOKEN(anon_sym_CR); 478 | if (lookahead == '\n') ADVANCE(18); 479 | if (lookahead != 0) ADVANCE(39); 480 | END_STATE(); 481 | case 18: 482 | ACCEPT_TOKEN(anon_sym_CR_LF); 483 | END_STATE(); 484 | case 19: 485 | ACCEPT_TOKEN(anon_sym_); 486 | END_STATE(); 487 | case 20: 488 | ACCEPT_TOKEN(anon_sym_); 489 | if (lookahead != 0 && 490 | lookahead != '\n') ADVANCE(31); 491 | END_STATE(); 492 | case 21: 493 | ACCEPT_TOKEN(anon_sym_); 494 | if (lookahead != 0 && 495 | lookahead != '\n') ADVANCE(39); 496 | END_STATE(); 497 | case 22: 498 | ACCEPT_TOKEN(sym__whitespace); 499 | if (lookahead == '\t' || 500 | lookahead == ' ' || 501 | lookahead == 160 || 502 | lookahead == 5760 || 503 | (8192 <= lookahead && lookahead <= 8202) || 504 | lookahead == 8239 || 505 | lookahead == 8287 || 506 | lookahead == 12288) ADVANCE(22); 507 | END_STATE(); 508 | case 23: 509 | ACCEPT_TOKEN(sym_key); 510 | if (('0' <= lookahead && lookahead <= '9')) ADVANCE(23); 511 | if (lookahead != 0 && 512 | lookahead != '\t' && 513 | lookahead != '\n' && 514 | lookahead != '\r' && 515 | lookahead != ' ' && 516 | lookahead != ':') ADVANCE(25); 517 | END_STATE(); 518 | case 24: 519 | ACCEPT_TOKEN(sym_key); 520 | if (lookahead == 160 || 521 | lookahead == 5760 || 522 | (8192 <= lookahead && lookahead <= 8202) || 523 | lookahead == 8239 || 524 | lookahead == 8287 || 525 | lookahead == 12288) ADVANCE(24); 526 | if (lookahead != 0 && 527 | lookahead != '\t' && 528 | lookahead != '\n' && 529 | lookahead != '\r' && 530 | lookahead != ' ' && 531 | lookahead != ':') ADVANCE(25); 532 | END_STATE(); 533 | case 25: 534 | ACCEPT_TOKEN(sym_key); 535 | if (lookahead != 0 && 536 | lookahead != '\t' && 537 | lookahead != '\n' && 538 | lookahead != '\r' && 539 | lookahead != ' ' && 540 | lookahead != ':') ADVANCE(25); 541 | END_STATE(); 542 | case 26: 543 | ACCEPT_TOKEN(sym_number); 544 | if (('0' <= lookahead && lookahead <= '9')) ADVANCE(26); 545 | if (lookahead != 0 && 546 | lookahead != '\n') ADVANCE(31); 547 | END_STATE(); 548 | case 27: 549 | ACCEPT_TOKEN(anon_sym_LBRACK); 550 | END_STATE(); 551 | case 28: 552 | ACCEPT_TOKEN(aux_sym_array_token1); 553 | if (lookahead == '\n') ADVANCE(29); 554 | if (lookahead == '\t' || 555 | lookahead == '\r' || 556 | lookahead == ' ') ADVANCE(28); 557 | END_STATE(); 558 | case 29: 559 | ACCEPT_TOKEN(aux_sym_array_token1); 560 | if (lookahead == '\t' || 561 | lookahead == '\n' || 562 | lookahead == '\r' || 563 | lookahead == ' ') ADVANCE(29); 564 | END_STATE(); 565 | case 30: 566 | ACCEPT_TOKEN(anon_sym_RBRACK); 567 | END_STATE(); 568 | case 31: 569 | ACCEPT_TOKEN(sym_string); 570 | if (lookahead != 0 && 571 | lookahead != '\n') ADVANCE(31); 572 | END_STATE(); 573 | case 32: 574 | ACCEPT_TOKEN(anon_sym_LBRACE); 575 | END_STATE(); 576 | case 33: 577 | ACCEPT_TOKEN(aux_sym_object_token1); 578 | if (lookahead == '\n') ADVANCE(35); 579 | if (lookahead == '\t' || 580 | lookahead == '\r' || 581 | lookahead == ' ') ADVANCE(35); 582 | END_STATE(); 583 | case 34: 584 | ACCEPT_TOKEN(aux_sym_object_token1); 585 | if (lookahead == '\t' || 586 | lookahead == ' ') ADVANCE(34); 587 | if (lookahead == '\n' || 588 | lookahead == '\r') ADVANCE(35); 589 | END_STATE(); 590 | case 35: 591 | ACCEPT_TOKEN(aux_sym_object_token1); 592 | if (lookahead == '\t' || 593 | lookahead == '\n' || 594 | lookahead == '\r' || 595 | lookahead == ' ') ADVANCE(35); 596 | END_STATE(); 597 | case 36: 598 | ACCEPT_TOKEN(anon_sym_RBRACE); 599 | END_STATE(); 600 | case 37: 601 | ACCEPT_TOKEN(anon_sym_COLON); 602 | END_STATE(); 603 | case 38: 604 | ACCEPT_TOKEN(aux_sym_delimiter_token1); 605 | if (lookahead == '-') ADVANCE(38); 606 | END_STATE(); 607 | case 39: 608 | ACCEPT_TOKEN(aux_sym_delimiter_token2); 609 | if (lookahead != 0 && 610 | lookahead != '\n') ADVANCE(39); 611 | END_STATE(); 612 | default: 613 | return false; 614 | } 615 | } 616 | 617 | static const TSLexMode ts_lex_modes[STATE_COUNT] = { 618 | [0] = {.lex_state = 0}, 619 | [1] = {.lex_state = 12}, 620 | [2] = {.lex_state = 5}, 621 | [3] = {.lex_state = 12}, 622 | [4] = {.lex_state = 7}, 623 | [5] = {.lex_state = 6}, 624 | [6] = {.lex_state = 1}, 625 | [7] = {.lex_state = 5}, 626 | [8] = {.lex_state = 4}, 627 | [9] = {.lex_state = 9}, 628 | [10] = {.lex_state = 12}, 629 | [11] = {.lex_state = 12}, 630 | [12] = {.lex_state = 12}, 631 | [13] = {.lex_state = 4}, 632 | [14] = {.lex_state = 4}, 633 | [15] = {.lex_state = 11}, 634 | [16] = {.lex_state = 12}, 635 | [17] = {.lex_state = 12}, 636 | [18] = {.lex_state = 12}, 637 | [19] = {.lex_state = 12}, 638 | [20] = {.lex_state = 4}, 639 | [21] = {.lex_state = 2}, 640 | [22] = {.lex_state = 2}, 641 | [23] = {.lex_state = 10}, 642 | [24] = {.lex_state = 2}, 643 | [25] = {.lex_state = 2}, 644 | [26] = {.lex_state = 2}, 645 | [27] = {.lex_state = 4}, 646 | [28] = {.lex_state = 2}, 647 | [29] = {.lex_state = 2}, 648 | [30] = {.lex_state = 2}, 649 | [31] = {.lex_state = 4}, 650 | [32] = {.lex_state = 2}, 651 | [33] = {.lex_state = 2}, 652 | [34] = {.lex_state = 4}, 653 | [35] = {.lex_state = 2}, 654 | [36] = {.lex_state = 4}, 655 | [37] = {.lex_state = 2}, 656 | [38] = {.lex_state = 2}, 657 | [39] = {.lex_state = 2}, 658 | [40] = {.lex_state = 2}, 659 | [41] = {.lex_state = 2}, 660 | [42] = {.lex_state = 2}, 661 | [43] = {.lex_state = 3}, 662 | [44] = {.lex_state = 2}, 663 | [45] = {.lex_state = 8}, 664 | [46] = {.lex_state = 4}, 665 | [47] = {.lex_state = 2}, 666 | [48] = {.lex_state = 2}, 667 | [49] = {.lex_state = 2}, 668 | [50] = {.lex_state = 4}, 669 | [51] = {.lex_state = 12}, 670 | [52] = {.lex_state = 4}, 671 | [53] = {.lex_state = 2}, 672 | [54] = {.lex_state = 0}, 673 | [55] = {.lex_state = 0}, 674 | [56] = {.lex_state = 0}, 675 | }; 676 | 677 | static const uint16_t ts_parse_table[LARGE_STATE_COUNT][SYMBOL_COUNT] = { 678 | [0] = { 679 | [ts_builtin_sym_end] = ACTIONS(1), 680 | [anon_sym_LF] = ACTIONS(1), 681 | [anon_sym_CR] = ACTIONS(1), 682 | [anon_sym_CR_LF] = ACTIONS(1), 683 | [anon_sym_] = ACTIONS(1), 684 | [sym__whitespace] = ACTIONS(1), 685 | [sym_key] = ACTIONS(1), 686 | [sym_number] = ACTIONS(1), 687 | [anon_sym_LBRACK] = ACTIONS(1), 688 | [anon_sym_RBRACK] = ACTIONS(1), 689 | [anon_sym_LBRACE] = ACTIONS(1), 690 | [aux_sym_object_token1] = ACTIONS(1), 691 | [anon_sym_RBRACE] = ACTIONS(1), 692 | [anon_sym_COLON] = ACTIONS(1), 693 | [aux_sym_delimiter_token1] = ACTIONS(1), 694 | }, 695 | [1] = { 696 | [sym_metadata] = STATE(54), 697 | [sym_pair] = STATE(40), 698 | [sym_delimiter] = STATE(40), 699 | [aux_sym_metadata_repeat1] = STATE(3), 700 | [aux_sym_metadata_repeat3] = STATE(17), 701 | [ts_builtin_sym_end] = ACTIONS(3), 702 | [anon_sym_LF] = ACTIONS(5), 703 | [anon_sym_CR] = ACTIONS(7), 704 | [anon_sym_CR_LF] = ACTIONS(5), 705 | [sym__whitespace] = ACTIONS(9), 706 | [sym_key] = ACTIONS(11), 707 | [aux_sym_delimiter_token1] = ACTIONS(13), 708 | }, 709 | }; 710 | 711 | static const uint16_t ts_small_parse_table[] = { 712 | [0] = 9, 713 | ACTIONS(17), 1, 714 | anon_sym_CR, 715 | ACTIONS(19), 1, 716 | sym__whitespace, 717 | ACTIONS(23), 1, 718 | anon_sym_LBRACK, 719 | ACTIONS(25), 1, 720 | anon_sym_LBRACE, 721 | STATE(7), 1, 722 | aux_sym_metadata_repeat1, 723 | STATE(53), 1, 724 | sym_value, 725 | ACTIONS(21), 2, 726 | sym_number, 727 | sym_string, 728 | STATE(22), 2, 729 | sym_array, 730 | sym_object, 731 | ACTIONS(15), 3, 732 | anon_sym_LF, 733 | anon_sym_CR_LF, 734 | anon_sym_RBRACK, 735 | [32] = 9, 736 | ACTIONS(9), 1, 737 | sym__whitespace, 738 | ACTIONS(11), 1, 739 | sym_key, 740 | ACTIONS(13), 1, 741 | aux_sym_delimiter_token1, 742 | ACTIONS(27), 1, 743 | ts_builtin_sym_end, 744 | ACTIONS(31), 1, 745 | anon_sym_CR, 746 | STATE(16), 1, 747 | aux_sym_metadata_repeat1, 748 | STATE(18), 1, 749 | aux_sym_metadata_repeat3, 750 | ACTIONS(29), 2, 751 | anon_sym_LF, 752 | anon_sym_CR_LF, 753 | STATE(40), 2, 754 | sym_pair, 755 | sym_delimiter, 756 | [62] = 7, 757 | ACTIONS(23), 1, 758 | anon_sym_LBRACK, 759 | ACTIONS(25), 1, 760 | anon_sym_LBRACE, 761 | ACTIONS(35), 1, 762 | anon_sym_CR, 763 | STATE(47), 1, 764 | sym_value, 765 | ACTIONS(21), 2, 766 | sym_number, 767 | sym_string, 768 | STATE(22), 2, 769 | sym_array, 770 | sym_object, 771 | ACTIONS(33), 3, 772 | anon_sym_LF, 773 | anon_sym_CR_LF, 774 | anon_sym_RBRACE, 775 | [88] = 7, 776 | ACTIONS(23), 1, 777 | anon_sym_LBRACK, 778 | ACTIONS(25), 1, 779 | anon_sym_LBRACE, 780 | ACTIONS(39), 1, 781 | anon_sym_CR, 782 | STATE(49), 1, 783 | sym_value, 784 | ACTIONS(21), 2, 785 | sym_number, 786 | sym_string, 787 | STATE(22), 2, 788 | sym_array, 789 | sym_object, 790 | ACTIONS(37), 3, 791 | anon_sym_LF, 792 | anon_sym_CR_LF, 793 | anon_sym_RBRACK, 794 | [114] = 7, 795 | ACTIONS(23), 1, 796 | anon_sym_LBRACK, 797 | ACTIONS(25), 1, 798 | anon_sym_LBRACE, 799 | STATE(47), 1, 800 | sym_value, 801 | ACTIONS(21), 2, 802 | sym_number, 803 | sym_string, 804 | ACTIONS(33), 2, 805 | anon_sym_LF, 806 | anon_sym_CR_LF, 807 | ACTIONS(35), 2, 808 | anon_sym_CR, 809 | anon_sym_, 810 | STATE(22), 2, 811 | sym_array, 812 | sym_object, 813 | [140] = 5, 814 | ACTIONS(44), 1, 815 | anon_sym_CR, 816 | STATE(7), 1, 817 | aux_sym_metadata_repeat1, 818 | ACTIONS(41), 2, 819 | anon_sym_LF, 820 | anon_sym_CR_LF, 821 | ACTIONS(49), 2, 822 | sym_number, 823 | sym_string, 824 | ACTIONS(47), 4, 825 | sym__whitespace, 826 | anon_sym_LBRACK, 827 | anon_sym_RBRACK, 828 | anon_sym_LBRACE, 829 | [161] = 7, 830 | ACTIONS(53), 1, 831 | anon_sym_CR, 832 | ACTIONS(55), 1, 833 | sym__whitespace, 834 | ACTIONS(57), 1, 835 | sym_key, 836 | ACTIONS(59), 1, 837 | aux_sym_delimiter_token1, 838 | STATE(13), 1, 839 | aux_sym_metadata_repeat1, 840 | STATE(52), 2, 841 | sym_pair, 842 | sym_delimiter, 843 | ACTIONS(51), 3, 844 | anon_sym_LF, 845 | anon_sym_CR_LF, 846 | anon_sym_RBRACE, 847 | [186] = 7, 848 | ACTIONS(23), 1, 849 | anon_sym_LBRACK, 850 | ACTIONS(25), 1, 851 | anon_sym_LBRACE, 852 | ACTIONS(61), 1, 853 | aux_sym_array_token1, 854 | ACTIONS(63), 1, 855 | anon_sym_RBRACK, 856 | STATE(26), 1, 857 | sym_value, 858 | ACTIONS(21), 2, 859 | sym_number, 860 | sym_string, 861 | STATE(22), 2, 862 | sym_array, 863 | sym_object, 864 | [210] = 5, 865 | STATE(12), 1, 866 | aux_sym_metadata_repeat2, 867 | ACTIONS(65), 2, 868 | ts_builtin_sym_end, 869 | aux_sym_delimiter_token1, 870 | ACTIONS(67), 2, 871 | anon_sym_LF, 872 | anon_sym_CR_LF, 873 | ACTIONS(69), 2, 874 | anon_sym_CR, 875 | anon_sym_, 876 | ACTIONS(71), 2, 877 | sym__whitespace, 878 | sym_key, 879 | [230] = 5, 880 | STATE(12), 1, 881 | aux_sym_metadata_repeat2, 882 | ACTIONS(67), 2, 883 | anon_sym_LF, 884 | anon_sym_CR_LF, 885 | ACTIONS(69), 2, 886 | anon_sym_CR, 887 | anon_sym_, 888 | ACTIONS(73), 2, 889 | ts_builtin_sym_end, 890 | aux_sym_delimiter_token1, 891 | ACTIONS(75), 2, 892 | sym__whitespace, 893 | sym_key, 894 | [250] = 5, 895 | STATE(12), 1, 896 | aux_sym_metadata_repeat2, 897 | ACTIONS(77), 2, 898 | ts_builtin_sym_end, 899 | aux_sym_delimiter_token1, 900 | ACTIONS(79), 2, 901 | anon_sym_LF, 902 | anon_sym_CR_LF, 903 | ACTIONS(82), 2, 904 | anon_sym_CR, 905 | anon_sym_, 906 | ACTIONS(85), 2, 907 | sym__whitespace, 908 | sym_key, 909 | [270] = 5, 910 | ACTIONS(90), 1, 911 | anon_sym_CR, 912 | STATE(13), 1, 913 | aux_sym_metadata_repeat1, 914 | ACTIONS(47), 2, 915 | anon_sym_RBRACE, 916 | aux_sym_delimiter_token1, 917 | ACTIONS(49), 2, 918 | sym__whitespace, 919 | sym_key, 920 | ACTIONS(87), 2, 921 | anon_sym_LF, 922 | anon_sym_CR_LF, 923 | [289] = 5, 924 | ACTIONS(57), 1, 925 | sym_key, 926 | ACTIONS(59), 1, 927 | aux_sym_delimiter_token1, 928 | ACTIONS(95), 1, 929 | anon_sym_CR, 930 | STATE(50), 2, 931 | sym_pair, 932 | sym_delimiter, 933 | ACTIONS(93), 3, 934 | anon_sym_LF, 935 | anon_sym_CR_LF, 936 | anon_sym_RBRACE, 937 | [308] = 6, 938 | ACTIONS(23), 1, 939 | anon_sym_LBRACK, 940 | ACTIONS(25), 1, 941 | anon_sym_LBRACE, 942 | ACTIONS(97), 1, 943 | anon_sym_RBRACK, 944 | STATE(30), 1, 945 | sym_value, 946 | ACTIONS(21), 2, 947 | sym_number, 948 | sym_string, 949 | STATE(22), 2, 950 | sym_array, 951 | sym_object, 952 | [329] = 5, 953 | ACTIONS(102), 1, 954 | anon_sym_CR, 955 | STATE(16), 1, 956 | aux_sym_metadata_repeat1, 957 | ACTIONS(47), 2, 958 | ts_builtin_sym_end, 959 | aux_sym_delimiter_token1, 960 | ACTIONS(49), 2, 961 | sym__whitespace, 962 | sym_key, 963 | ACTIONS(99), 2, 964 | anon_sym_LF, 965 | anon_sym_CR_LF, 966 | [348] = 6, 967 | ACTIONS(9), 1, 968 | sym__whitespace, 969 | ACTIONS(11), 1, 970 | sym_key, 971 | ACTIONS(13), 1, 972 | aux_sym_delimiter_token1, 973 | ACTIONS(27), 1, 974 | ts_builtin_sym_end, 975 | STATE(19), 1, 976 | aux_sym_metadata_repeat3, 977 | STATE(40), 2, 978 | sym_pair, 979 | sym_delimiter, 980 | [368] = 6, 981 | ACTIONS(9), 1, 982 | sym__whitespace, 983 | ACTIONS(11), 1, 984 | sym_key, 985 | ACTIONS(13), 1, 986 | aux_sym_delimiter_token1, 987 | ACTIONS(105), 1, 988 | ts_builtin_sym_end, 989 | STATE(19), 1, 990 | aux_sym_metadata_repeat3, 991 | STATE(40), 2, 992 | sym_pair, 993 | sym_delimiter, 994 | [388] = 6, 995 | ACTIONS(65), 1, 996 | ts_builtin_sym_end, 997 | ACTIONS(107), 1, 998 | sym__whitespace, 999 | ACTIONS(110), 1, 1000 | sym_key, 1001 | ACTIONS(113), 1, 1002 | aux_sym_delimiter_token1, 1003 | STATE(19), 1, 1004 | aux_sym_metadata_repeat3, 1005 | STATE(40), 2, 1006 | sym_pair, 1007 | sym_delimiter, 1008 | [408] = 5, 1009 | ACTIONS(118), 1, 1010 | anon_sym_CR, 1011 | ACTIONS(120), 1, 1012 | anon_sym_RBRACE, 1013 | STATE(8), 1, 1014 | aux_sym_metadata_repeat1, 1015 | STATE(36), 1, 1016 | aux_sym_object_repeat1, 1017 | ACTIONS(116), 2, 1018 | anon_sym_LF, 1019 | anon_sym_CR_LF, 1020 | [425] = 2, 1021 | ACTIONS(124), 1, 1022 | anon_sym_CR, 1023 | ACTIONS(122), 5, 1024 | anon_sym_LF, 1025 | anon_sym_CR_LF, 1026 | anon_sym_, 1027 | anon_sym_RBRACK, 1028 | anon_sym_RBRACE, 1029 | [436] = 2, 1030 | ACTIONS(128), 1, 1031 | anon_sym_CR, 1032 | ACTIONS(126), 5, 1033 | anon_sym_LF, 1034 | anon_sym_CR_LF, 1035 | anon_sym_, 1036 | anon_sym_RBRACK, 1037 | anon_sym_RBRACE, 1038 | [447] = 5, 1039 | ACTIONS(57), 1, 1040 | sym_key, 1041 | ACTIONS(59), 1, 1042 | aux_sym_delimiter_token1, 1043 | ACTIONS(130), 1, 1044 | aux_sym_object_token1, 1045 | ACTIONS(132), 1, 1046 | anon_sym_RBRACE, 1047 | STATE(20), 2, 1048 | sym_pair, 1049 | sym_delimiter, 1050 | [464] = 2, 1051 | ACTIONS(136), 1, 1052 | anon_sym_CR, 1053 | ACTIONS(134), 5, 1054 | anon_sym_LF, 1055 | anon_sym_CR_LF, 1056 | anon_sym_, 1057 | anon_sym_RBRACK, 1058 | anon_sym_RBRACE, 1059 | [475] = 2, 1060 | ACTIONS(140), 1, 1061 | anon_sym_CR, 1062 | ACTIONS(138), 5, 1063 | anon_sym_LF, 1064 | anon_sym_CR_LF, 1065 | anon_sym_, 1066 | anon_sym_RBRACK, 1067 | anon_sym_RBRACE, 1068 | [486] = 5, 1069 | ACTIONS(97), 1, 1070 | anon_sym_RBRACK, 1071 | ACTIONS(144), 1, 1072 | anon_sym_CR, 1073 | STATE(2), 1, 1074 | aux_sym_metadata_repeat1, 1075 | STATE(32), 1, 1076 | aux_sym_array_repeat1, 1077 | ACTIONS(142), 2, 1078 | anon_sym_LF, 1079 | anon_sym_CR_LF, 1080 | [503] = 5, 1081 | ACTIONS(93), 1, 1082 | anon_sym_RBRACE, 1083 | ACTIONS(149), 1, 1084 | anon_sym_CR, 1085 | STATE(8), 1, 1086 | aux_sym_metadata_repeat1, 1087 | STATE(27), 1, 1088 | aux_sym_object_repeat1, 1089 | ACTIONS(146), 2, 1090 | anon_sym_LF, 1091 | anon_sym_CR_LF, 1092 | [520] = 2, 1093 | ACTIONS(154), 1, 1094 | anon_sym_CR, 1095 | ACTIONS(152), 5, 1096 | anon_sym_LF, 1097 | anon_sym_CR_LF, 1098 | anon_sym_, 1099 | anon_sym_RBRACK, 1100 | anon_sym_RBRACE, 1101 | [531] = 2, 1102 | ACTIONS(158), 1, 1103 | anon_sym_CR, 1104 | ACTIONS(156), 5, 1105 | anon_sym_LF, 1106 | anon_sym_CR_LF, 1107 | anon_sym_, 1108 | anon_sym_RBRACK, 1109 | anon_sym_RBRACE, 1110 | [542] = 5, 1111 | ACTIONS(144), 1, 1112 | anon_sym_CR, 1113 | ACTIONS(160), 1, 1114 | anon_sym_RBRACK, 1115 | STATE(2), 1, 1116 | aux_sym_metadata_repeat1, 1117 | STATE(38), 1, 1118 | aux_sym_array_repeat1, 1119 | ACTIONS(142), 2, 1120 | anon_sym_LF, 1121 | anon_sym_CR_LF, 1122 | [559] = 5, 1123 | ACTIONS(118), 1, 1124 | anon_sym_CR, 1125 | ACTIONS(162), 1, 1126 | anon_sym_RBRACE, 1127 | STATE(8), 1, 1128 | aux_sym_metadata_repeat1, 1129 | STATE(27), 1, 1130 | aux_sym_object_repeat1, 1131 | ACTIONS(116), 2, 1132 | anon_sym_LF, 1133 | anon_sym_CR_LF, 1134 | [576] = 5, 1135 | ACTIONS(144), 1, 1136 | anon_sym_CR, 1137 | ACTIONS(160), 1, 1138 | anon_sym_RBRACK, 1139 | STATE(2), 1, 1140 | aux_sym_metadata_repeat1, 1141 | STATE(39), 1, 1142 | aux_sym_array_repeat1, 1143 | ACTIONS(142), 2, 1144 | anon_sym_LF, 1145 | anon_sym_CR_LF, 1146 | [593] = 2, 1147 | ACTIONS(166), 1, 1148 | anon_sym_CR, 1149 | ACTIONS(164), 5, 1150 | anon_sym_LF, 1151 | anon_sym_CR_LF, 1152 | anon_sym_, 1153 | anon_sym_RBRACK, 1154 | anon_sym_RBRACE, 1155 | [604] = 5, 1156 | ACTIONS(118), 1, 1157 | anon_sym_CR, 1158 | ACTIONS(168), 1, 1159 | anon_sym_RBRACE, 1160 | STATE(8), 1, 1161 | aux_sym_metadata_repeat1, 1162 | STATE(31), 1, 1163 | aux_sym_object_repeat1, 1164 | ACTIONS(116), 2, 1165 | anon_sym_LF, 1166 | anon_sym_CR_LF, 1167 | [621] = 2, 1168 | ACTIONS(172), 1, 1169 | anon_sym_CR, 1170 | ACTIONS(170), 5, 1171 | anon_sym_LF, 1172 | anon_sym_CR_LF, 1173 | anon_sym_, 1174 | anon_sym_RBRACK, 1175 | anon_sym_RBRACE, 1176 | [632] = 5, 1177 | ACTIONS(118), 1, 1178 | anon_sym_CR, 1179 | ACTIONS(168), 1, 1180 | anon_sym_RBRACE, 1181 | STATE(8), 1, 1182 | aux_sym_metadata_repeat1, 1183 | STATE(27), 1, 1184 | aux_sym_object_repeat1, 1185 | ACTIONS(116), 2, 1186 | anon_sym_LF, 1187 | anon_sym_CR_LF, 1188 | [649] = 2, 1189 | ACTIONS(176), 1, 1190 | anon_sym_CR, 1191 | ACTIONS(174), 5, 1192 | anon_sym_LF, 1193 | anon_sym_CR_LF, 1194 | anon_sym_, 1195 | anon_sym_RBRACK, 1196 | anon_sym_RBRACE, 1197 | [660] = 5, 1198 | ACTIONS(144), 1, 1199 | anon_sym_CR, 1200 | ACTIONS(178), 1, 1201 | anon_sym_RBRACK, 1202 | STATE(2), 1, 1203 | aux_sym_metadata_repeat1, 1204 | STATE(39), 1, 1205 | aux_sym_array_repeat1, 1206 | ACTIONS(142), 2, 1207 | anon_sym_LF, 1208 | anon_sym_CR_LF, 1209 | [677] = 5, 1210 | ACTIONS(37), 1, 1211 | anon_sym_RBRACK, 1212 | ACTIONS(183), 1, 1213 | anon_sym_CR, 1214 | STATE(2), 1, 1215 | aux_sym_metadata_repeat1, 1216 | STATE(39), 1, 1217 | aux_sym_array_repeat1, 1218 | ACTIONS(180), 2, 1219 | anon_sym_LF, 1220 | anon_sym_CR_LF, 1221 | [694] = 3, 1222 | ACTIONS(188), 1, 1223 | anon_sym_CR, 1224 | STATE(10), 1, 1225 | aux_sym_metadata_repeat2, 1226 | ACTIONS(186), 3, 1227 | anon_sym_LF, 1228 | anon_sym_CR_LF, 1229 | anon_sym_, 1230 | [706] = 3, 1231 | ACTIONS(192), 1, 1232 | anon_sym_CR, 1233 | ACTIONS(194), 1, 1234 | sym__whitespace, 1235 | ACTIONS(190), 3, 1236 | anon_sym_LF, 1237 | anon_sym_CR_LF, 1238 | anon_sym_RBRACE, 1239 | [718] = 3, 1240 | ACTIONS(192), 1, 1241 | anon_sym_CR, 1242 | ACTIONS(196), 1, 1243 | sym__whitespace, 1244 | ACTIONS(190), 3, 1245 | anon_sym_LF, 1246 | anon_sym_CR_LF, 1247 | anon_sym_, 1248 | [730] = 3, 1249 | ACTIONS(202), 1, 1250 | aux_sym_delimiter_token2, 1251 | ACTIONS(198), 2, 1252 | anon_sym_LF, 1253 | anon_sym_CR_LF, 1254 | ACTIONS(200), 2, 1255 | anon_sym_CR, 1256 | anon_sym_, 1257 | [742] = 3, 1258 | ACTIONS(206), 1, 1259 | anon_sym_CR, 1260 | STATE(11), 1, 1261 | aux_sym_metadata_repeat2, 1262 | ACTIONS(204), 3, 1263 | anon_sym_LF, 1264 | anon_sym_CR_LF, 1265 | anon_sym_, 1266 | [754] = 3, 1267 | ACTIONS(200), 1, 1268 | anon_sym_CR, 1269 | ACTIONS(202), 1, 1270 | aux_sym_delimiter_token2, 1271 | ACTIONS(198), 3, 1272 | anon_sym_LF, 1273 | anon_sym_CR_LF, 1274 | anon_sym_RBRACE, 1275 | [766] = 4, 1276 | ACTIONS(57), 1, 1277 | sym_key, 1278 | ACTIONS(59), 1, 1279 | aux_sym_delimiter_token1, 1280 | ACTIONS(120), 1, 1281 | anon_sym_RBRACE, 1282 | STATE(34), 2, 1283 | sym_pair, 1284 | sym_delimiter, 1285 | [780] = 2, 1286 | ACTIONS(210), 1, 1287 | anon_sym_CR, 1288 | ACTIONS(208), 4, 1289 | anon_sym_LF, 1290 | anon_sym_CR_LF, 1291 | anon_sym_, 1292 | anon_sym_RBRACE, 1293 | [790] = 2, 1294 | ACTIONS(214), 1, 1295 | anon_sym_CR, 1296 | ACTIONS(212), 4, 1297 | anon_sym_LF, 1298 | anon_sym_CR_LF, 1299 | anon_sym_, 1300 | anon_sym_RBRACE, 1301 | [800] = 2, 1302 | ACTIONS(218), 1, 1303 | anon_sym_CR, 1304 | ACTIONS(216), 3, 1305 | anon_sym_LF, 1306 | anon_sym_CR_LF, 1307 | anon_sym_RBRACK, 1308 | [809] = 2, 1309 | ACTIONS(222), 1, 1310 | anon_sym_CR, 1311 | ACTIONS(220), 3, 1312 | anon_sym_LF, 1313 | anon_sym_CR_LF, 1314 | anon_sym_RBRACE, 1315 | [818] = 3, 1316 | ACTIONS(11), 1, 1317 | sym_key, 1318 | ACTIONS(13), 1, 1319 | aux_sym_delimiter_token1, 1320 | STATE(44), 2, 1321 | sym_pair, 1322 | sym_delimiter, 1323 | [829] = 2, 1324 | ACTIONS(95), 1, 1325 | anon_sym_CR, 1326 | ACTIONS(93), 3, 1327 | anon_sym_LF, 1328 | anon_sym_CR_LF, 1329 | anon_sym_RBRACE, 1330 | [838] = 2, 1331 | ACTIONS(39), 1, 1332 | anon_sym_CR, 1333 | ACTIONS(37), 3, 1334 | anon_sym_LF, 1335 | anon_sym_CR_LF, 1336 | anon_sym_RBRACK, 1337 | [847] = 1, 1338 | ACTIONS(224), 1, 1339 | ts_builtin_sym_end, 1340 | [851] = 1, 1341 | ACTIONS(226), 1, 1342 | anon_sym_COLON, 1343 | [855] = 1, 1344 | ACTIONS(228), 1, 1345 | anon_sym_COLON, 1346 | }; 1347 | 1348 | static const uint32_t ts_small_parse_table_map[] = { 1349 | [SMALL_STATE(2)] = 0, 1350 | [SMALL_STATE(3)] = 32, 1351 | [SMALL_STATE(4)] = 62, 1352 | [SMALL_STATE(5)] = 88, 1353 | [SMALL_STATE(6)] = 114, 1354 | [SMALL_STATE(7)] = 140, 1355 | [SMALL_STATE(8)] = 161, 1356 | [SMALL_STATE(9)] = 186, 1357 | [SMALL_STATE(10)] = 210, 1358 | [SMALL_STATE(11)] = 230, 1359 | [SMALL_STATE(12)] = 250, 1360 | [SMALL_STATE(13)] = 270, 1361 | [SMALL_STATE(14)] = 289, 1362 | [SMALL_STATE(15)] = 308, 1363 | [SMALL_STATE(16)] = 329, 1364 | [SMALL_STATE(17)] = 348, 1365 | [SMALL_STATE(18)] = 368, 1366 | [SMALL_STATE(19)] = 388, 1367 | [SMALL_STATE(20)] = 408, 1368 | [SMALL_STATE(21)] = 425, 1369 | [SMALL_STATE(22)] = 436, 1370 | [SMALL_STATE(23)] = 447, 1371 | [SMALL_STATE(24)] = 464, 1372 | [SMALL_STATE(25)] = 475, 1373 | [SMALL_STATE(26)] = 486, 1374 | [SMALL_STATE(27)] = 503, 1375 | [SMALL_STATE(28)] = 520, 1376 | [SMALL_STATE(29)] = 531, 1377 | [SMALL_STATE(30)] = 542, 1378 | [SMALL_STATE(31)] = 559, 1379 | [SMALL_STATE(32)] = 576, 1380 | [SMALL_STATE(33)] = 593, 1381 | [SMALL_STATE(34)] = 604, 1382 | [SMALL_STATE(35)] = 621, 1383 | [SMALL_STATE(36)] = 632, 1384 | [SMALL_STATE(37)] = 649, 1385 | [SMALL_STATE(38)] = 660, 1386 | [SMALL_STATE(39)] = 677, 1387 | [SMALL_STATE(40)] = 694, 1388 | [SMALL_STATE(41)] = 706, 1389 | [SMALL_STATE(42)] = 718, 1390 | [SMALL_STATE(43)] = 730, 1391 | [SMALL_STATE(44)] = 742, 1392 | [SMALL_STATE(45)] = 754, 1393 | [SMALL_STATE(46)] = 766, 1394 | [SMALL_STATE(47)] = 780, 1395 | [SMALL_STATE(48)] = 790, 1396 | [SMALL_STATE(49)] = 800, 1397 | [SMALL_STATE(50)] = 809, 1398 | [SMALL_STATE(51)] = 818, 1399 | [SMALL_STATE(52)] = 829, 1400 | [SMALL_STATE(53)] = 838, 1401 | [SMALL_STATE(54)] = 847, 1402 | [SMALL_STATE(55)] = 851, 1403 | [SMALL_STATE(56)] = 855, 1404 | }; 1405 | 1406 | static const TSParseActionEntry ts_parse_actions[] = { 1407 | [0] = {.entry = {.count = 0, .reusable = false}}, 1408 | [1] = {.entry = {.count = 1, .reusable = false}}, RECOVER(), 1409 | [3] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_metadata, 0), 1410 | [5] = {.entry = {.count = 1, .reusable = true}}, SHIFT(3), 1411 | [7] = {.entry = {.count = 1, .reusable = false}}, SHIFT(3), 1412 | [9] = {.entry = {.count = 1, .reusable = false}}, SHIFT(51), 1413 | [11] = {.entry = {.count = 1, .reusable = false}}, SHIFT(55), 1414 | [13] = {.entry = {.count = 1, .reusable = true}}, SHIFT(43), 1415 | [15] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_array_repeat1, 1), 1416 | [17] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_array_repeat1, 1), 1417 | [19] = {.entry = {.count = 1, .reusable = true}}, SHIFT(5), 1418 | [21] = {.entry = {.count = 1, .reusable = false}}, SHIFT(22), 1419 | [23] = {.entry = {.count = 1, .reusable = true}}, SHIFT(9), 1420 | [25] = {.entry = {.count = 1, .reusable = true}}, SHIFT(23), 1421 | [27] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_metadata, 1), 1422 | [29] = {.entry = {.count = 1, .reusable = true}}, SHIFT(16), 1423 | [31] = {.entry = {.count = 1, .reusable = false}}, SHIFT(16), 1424 | [33] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_pair, 3), 1425 | [35] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_pair, 3), 1426 | [37] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_array_repeat1, 2), 1427 | [39] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_array_repeat1, 2), 1428 | [41] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_metadata_repeat1, 2), SHIFT_REPEAT(7), 1429 | [44] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_metadata_repeat1, 2), SHIFT_REPEAT(7), 1430 | [47] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_metadata_repeat1, 2), 1431 | [49] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_metadata_repeat1, 2), 1432 | [51] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_object_repeat1, 1), 1433 | [53] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_object_repeat1, 1), 1434 | [55] = {.entry = {.count = 1, .reusable = false}}, SHIFT(14), 1435 | [57] = {.entry = {.count = 1, .reusable = false}}, SHIFT(56), 1436 | [59] = {.entry = {.count = 1, .reusable = true}}, SHIFT(45), 1437 | [61] = {.entry = {.count = 1, .reusable = true}}, SHIFT(15), 1438 | [63] = {.entry = {.count = 1, .reusable = true}}, SHIFT(25), 1439 | [65] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_metadata_repeat3, 2), 1440 | [67] = {.entry = {.count = 1, .reusable = true}}, SHIFT(12), 1441 | [69] = {.entry = {.count = 1, .reusable = false}}, SHIFT(12), 1442 | [71] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_metadata_repeat3, 2), 1443 | [73] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_metadata_repeat3, 3), 1444 | [75] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_metadata_repeat3, 3), 1445 | [77] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_metadata_repeat2, 2), 1446 | [79] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_metadata_repeat2, 2), SHIFT_REPEAT(12), 1447 | [82] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_metadata_repeat2, 2), SHIFT_REPEAT(12), 1448 | [85] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_metadata_repeat2, 2), 1449 | [87] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_metadata_repeat1, 2), SHIFT_REPEAT(13), 1450 | [90] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_metadata_repeat1, 2), SHIFT_REPEAT(13), 1451 | [93] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_object_repeat1, 2), 1452 | [95] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_object_repeat1, 2), 1453 | [97] = {.entry = {.count = 1, .reusable = true}}, SHIFT(29), 1454 | [99] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_metadata_repeat1, 2), SHIFT_REPEAT(16), 1455 | [102] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_metadata_repeat1, 2), SHIFT_REPEAT(16), 1456 | [105] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_metadata, 2), 1457 | [107] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_metadata_repeat3, 2), SHIFT_REPEAT(51), 1458 | [110] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_metadata_repeat3, 2), SHIFT_REPEAT(55), 1459 | [113] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_metadata_repeat3, 2), SHIFT_REPEAT(43), 1460 | [116] = {.entry = {.count = 1, .reusable = true}}, SHIFT(8), 1461 | [118] = {.entry = {.count = 1, .reusable = false}}, SHIFT(8), 1462 | [120] = {.entry = {.count = 1, .reusable = true}}, SHIFT(33), 1463 | [122] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 4), 1464 | [124] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_object, 4), 1465 | [126] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_value, 1), 1466 | [128] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_value, 1), 1467 | [130] = {.entry = {.count = 1, .reusable = true}}, SHIFT(46), 1468 | [132] = {.entry = {.count = 1, .reusable = true}}, SHIFT(28), 1469 | [134] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 5), 1470 | [136] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_array, 5), 1471 | [138] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 2), 1472 | [140] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_array, 2), 1473 | [142] = {.entry = {.count = 1, .reusable = true}}, SHIFT(2), 1474 | [144] = {.entry = {.count = 1, .reusable = false}}, SHIFT(2), 1475 | [146] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_object_repeat1, 2), SHIFT_REPEAT(8), 1476 | [149] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_object_repeat1, 2), SHIFT_REPEAT(8), 1477 | [152] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 2), 1478 | [154] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_object, 2), 1479 | [156] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 3), 1480 | [158] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_array, 3), 1481 | [160] = {.entry = {.count = 1, .reusable = true}}, SHIFT(37), 1482 | [162] = {.entry = {.count = 1, .reusable = true}}, SHIFT(35), 1483 | [164] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 3), 1484 | [166] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_object, 3), 1485 | [168] = {.entry = {.count = 1, .reusable = true}}, SHIFT(21), 1486 | [170] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_object, 5), 1487 | [172] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_object, 5), 1488 | [174] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array, 4), 1489 | [176] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_array, 4), 1490 | [178] = {.entry = {.count = 1, .reusable = true}}, SHIFT(24), 1491 | [180] = {.entry = {.count = 2, .reusable = true}}, REDUCE(aux_sym_array_repeat1, 2), SHIFT_REPEAT(2), 1492 | [183] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_array_repeat1, 2), SHIFT_REPEAT(2), 1493 | [186] = {.entry = {.count = 1, .reusable = true}}, SHIFT(10), 1494 | [188] = {.entry = {.count = 1, .reusable = false}}, SHIFT(10), 1495 | [190] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_pair, 2), 1496 | [192] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_pair, 2), 1497 | [194] = {.entry = {.count = 1, .reusable = true}}, SHIFT(4), 1498 | [196] = {.entry = {.count = 1, .reusable = true}}, SHIFT(6), 1499 | [198] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_delimiter, 1), 1500 | [200] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_delimiter, 1), 1501 | [202] = {.entry = {.count = 1, .reusable = false}}, SHIFT(48), 1502 | [204] = {.entry = {.count = 1, .reusable = true}}, SHIFT(11), 1503 | [206] = {.entry = {.count = 1, .reusable = false}}, SHIFT(11), 1504 | [208] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_pair, 4), 1505 | [210] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_pair, 4), 1506 | [212] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_delimiter, 2), 1507 | [214] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_delimiter, 2), 1508 | [216] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_array_repeat1, 3), 1509 | [218] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_array_repeat1, 3), 1510 | [220] = {.entry = {.count = 1, .reusable = true}}, REDUCE(aux_sym_object_repeat1, 3), 1511 | [222] = {.entry = {.count = 1, .reusable = false}}, REDUCE(aux_sym_object_repeat1, 3), 1512 | [224] = {.entry = {.count = 1, .reusable = true}}, ACCEPT_INPUT(), 1513 | [226] = {.entry = {.count = 1, .reusable = true}}, SHIFT(42), 1514 | [228] = {.entry = {.count = 1, .reusable = true}}, SHIFT(41), 1515 | }; 1516 | 1517 | #ifdef __cplusplus 1518 | extern "C" { 1519 | #endif 1520 | #ifdef _WIN32 1521 | #define extern __declspec(dllexport) 1522 | #endif 1523 | 1524 | extern const TSLanguage *tree_sitter_norg_meta(void) { 1525 | static const TSLanguage language = { 1526 | .version = LANGUAGE_VERSION, 1527 | .symbol_count = SYMBOL_COUNT, 1528 | .alias_count = ALIAS_COUNT, 1529 | .token_count = TOKEN_COUNT, 1530 | .external_token_count = EXTERNAL_TOKEN_COUNT, 1531 | .state_count = STATE_COUNT, 1532 | .large_state_count = LARGE_STATE_COUNT, 1533 | .production_id_count = PRODUCTION_ID_COUNT, 1534 | .field_count = FIELD_COUNT, 1535 | .max_alias_sequence_length = MAX_ALIAS_SEQUENCE_LENGTH, 1536 | .parse_table = &ts_parse_table[0][0], 1537 | .small_parse_table = ts_small_parse_table, 1538 | .small_parse_table_map = ts_small_parse_table_map, 1539 | .parse_actions = ts_parse_actions, 1540 | .symbol_names = ts_symbol_names, 1541 | .symbol_metadata = ts_symbol_metadata, 1542 | .public_symbol_map = ts_symbol_map, 1543 | .alias_map = ts_non_terminal_alias_map, 1544 | .alias_sequences = &ts_alias_sequences[0][0], 1545 | .lex_modes = ts_lex_modes, 1546 | .lex_fn = ts_lex, 1547 | .primary_state_ids = ts_primary_state_ids, 1548 | }; 1549 | return &language; 1550 | } 1551 | #ifdef __cplusplus 1552 | } 1553 | #endif 1554 | -------------------------------------------------------------------------------- /src/tree_sitter/parser.h: -------------------------------------------------------------------------------- 1 | #ifndef TREE_SITTER_PARSER_H_ 2 | #define TREE_SITTER_PARSER_H_ 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #define ts_builtin_sym_error ((TSSymbol)-1) 13 | #define ts_builtin_sym_end 0 14 | #define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024 15 | 16 | typedef uint16_t TSStateId; 17 | 18 | #ifndef TREE_SITTER_API_H_ 19 | typedef uint16_t TSSymbol; 20 | typedef uint16_t TSFieldId; 21 | typedef struct TSLanguage TSLanguage; 22 | #endif 23 | 24 | typedef struct { 25 | TSFieldId field_id; 26 | uint8_t child_index; 27 | bool inherited; 28 | } TSFieldMapEntry; 29 | 30 | typedef struct { 31 | uint16_t index; 32 | uint16_t length; 33 | } TSFieldMapSlice; 34 | 35 | typedef struct { 36 | bool visible; 37 | bool named; 38 | bool supertype; 39 | } TSSymbolMetadata; 40 | 41 | typedef struct TSLexer TSLexer; 42 | 43 | struct TSLexer { 44 | int32_t lookahead; 45 | TSSymbol result_symbol; 46 | void (*advance)(TSLexer *, bool); 47 | void (*mark_end)(TSLexer *); 48 | uint32_t (*get_column)(TSLexer *); 49 | bool (*is_at_included_range_start)(const TSLexer *); 50 | bool (*eof)(const TSLexer *); 51 | }; 52 | 53 | typedef enum { 54 | TSParseActionTypeShift, 55 | TSParseActionTypeReduce, 56 | TSParseActionTypeAccept, 57 | TSParseActionTypeRecover, 58 | } TSParseActionType; 59 | 60 | typedef union { 61 | struct { 62 | uint8_t type; 63 | TSStateId state; 64 | bool extra; 65 | bool repetition; 66 | } shift; 67 | struct { 68 | uint8_t type; 69 | uint8_t child_count; 70 | TSSymbol symbol; 71 | int16_t dynamic_precedence; 72 | uint16_t production_id; 73 | } reduce; 74 | uint8_t type; 75 | } TSParseAction; 76 | 77 | typedef struct { 78 | uint16_t lex_state; 79 | uint16_t external_lex_state; 80 | } TSLexMode; 81 | 82 | typedef union { 83 | TSParseAction action; 84 | struct { 85 | uint8_t count; 86 | bool reusable; 87 | } entry; 88 | } TSParseActionEntry; 89 | 90 | struct TSLanguage { 91 | uint32_t version; 92 | uint32_t symbol_count; 93 | uint32_t alias_count; 94 | uint32_t token_count; 95 | uint32_t external_token_count; 96 | uint32_t state_count; 97 | uint32_t large_state_count; 98 | uint32_t production_id_count; 99 | uint32_t field_count; 100 | uint16_t max_alias_sequence_length; 101 | const uint16_t *parse_table; 102 | const uint16_t *small_parse_table; 103 | const uint32_t *small_parse_table_map; 104 | const TSParseActionEntry *parse_actions; 105 | const char * const *symbol_names; 106 | const char * const *field_names; 107 | const TSFieldMapSlice *field_map_slices; 108 | const TSFieldMapEntry *field_map_entries; 109 | const TSSymbolMetadata *symbol_metadata; 110 | const TSSymbol *public_symbol_map; 111 | const uint16_t *alias_map; 112 | const TSSymbol *alias_sequences; 113 | const TSLexMode *lex_modes; 114 | bool (*lex_fn)(TSLexer *, TSStateId); 115 | bool (*keyword_lex_fn)(TSLexer *, TSStateId); 116 | TSSymbol keyword_capture_token; 117 | struct { 118 | const bool *states; 119 | const TSSymbol *symbol_map; 120 | void *(*create)(void); 121 | void (*destroy)(void *); 122 | bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist); 123 | unsigned (*serialize)(void *, char *); 124 | void (*deserialize)(void *, const char *, unsigned); 125 | } external_scanner; 126 | const TSStateId *primary_state_ids; 127 | }; 128 | 129 | /* 130 | * Lexer Macros 131 | */ 132 | 133 | #define START_LEXER() \ 134 | bool result = false; \ 135 | bool skip = false; \ 136 | bool eof = false; \ 137 | int32_t lookahead; \ 138 | goto start; \ 139 | next_state: \ 140 | lexer->advance(lexer, skip); \ 141 | start: \ 142 | skip = false; \ 143 | lookahead = lexer->lookahead; 144 | 145 | #define ADVANCE(state_value) \ 146 | { \ 147 | state = state_value; \ 148 | goto next_state; \ 149 | } 150 | 151 | #define SKIP(state_value) \ 152 | { \ 153 | skip = true; \ 154 | state = state_value; \ 155 | goto next_state; \ 156 | } 157 | 158 | #define ACCEPT_TOKEN(symbol_value) \ 159 | result = true; \ 160 | lexer->result_symbol = symbol_value; \ 161 | lexer->mark_end(lexer); 162 | 163 | #define END_STATE() return result; 164 | 165 | /* 166 | * Parse Table Macros 167 | */ 168 | 169 | #define SMALL_STATE(id) id - LARGE_STATE_COUNT 170 | 171 | #define STATE(id) id 172 | 173 | #define ACTIONS(id) id 174 | 175 | #define SHIFT(state_value) \ 176 | {{ \ 177 | .shift = { \ 178 | .type = TSParseActionTypeShift, \ 179 | .state = state_value \ 180 | } \ 181 | }} 182 | 183 | #define SHIFT_REPEAT(state_value) \ 184 | {{ \ 185 | .shift = { \ 186 | .type = TSParseActionTypeShift, \ 187 | .state = state_value, \ 188 | .repetition = true \ 189 | } \ 190 | }} 191 | 192 | #define SHIFT_EXTRA() \ 193 | {{ \ 194 | .shift = { \ 195 | .type = TSParseActionTypeShift, \ 196 | .extra = true \ 197 | } \ 198 | }} 199 | 200 | #define REDUCE(symbol_val, child_count_val, ...) \ 201 | {{ \ 202 | .reduce = { \ 203 | .type = TSParseActionTypeReduce, \ 204 | .symbol = symbol_val, \ 205 | .child_count = child_count_val, \ 206 | __VA_ARGS__ \ 207 | }, \ 208 | }} 209 | 210 | #define RECOVER() \ 211 | {{ \ 212 | .type = TSParseActionTypeRecover \ 213 | }} 214 | 215 | #define ACCEPT_INPUT() \ 216 | {{ \ 217 | .type = TSParseActionTypeAccept \ 218 | }} 219 | 220 | #ifdef __cplusplus 221 | } 222 | #endif 223 | 224 | #endif // TREE_SITTER_PARSER_H_ 225 | -------------------------------------------------------------------------------- /test/corpus/document.meta.txt: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | Key Pairs 3 | ================================================================================ 4 | title: Neorg 5 | -------------------------------------------------------------------------------- 6 | 7 | (metadata 8 | (pair 9 | (key) 10 | (string))) 11 | 12 | ================================================================================ 13 | Metadata 14 | ================================================================================ 15 | title: Neorg 16 | author: nvim-neorg 17 | -------------------------------------------------------------------------------- 18 | 19 | (metadata 20 | (pair 21 | (key) 22 | (string)) 23 | (pair 24 | (key) 25 | (string))) 26 | 27 | ================================================================================ 28 | Multi-word strings 29 | ================================================================================ 30 | description: This is a longer text. 31 | -------------------------------------------------------------------------------- 32 | 33 | (metadata 34 | (pair 35 | (key) 36 | (string))) 37 | 38 | ================================================================================ 39 | Numbers 40 | ================================================================================ 41 | should-be-a-number: 320 42 | not-a-number: 530 and some text here 43 | -------------------------------------------------------------------------------- 44 | 45 | (metadata 46 | (pair 47 | (key) 48 | (number)) 49 | (pair 50 | (key) 51 | (string))) 52 | 53 | ================================================================================ 54 | Empty delimiters 55 | ================================================================================ 56 | key: Value! 57 | empty-key-with-no-whitespace: 58 | other-empty-key-with-whitespace-and-tab: 59 | key: Value! 60 | -------------------------------------------------------------------------------- 61 | 62 | (metadata 63 | (pair 64 | (key) 65 | (string)) 66 | (pair 67 | (key)) 68 | (pair 69 | (key)) 70 | (pair 71 | (key) 72 | (string))) 73 | 74 | ================================================================================ 75 | Basic delimiter 76 | ================================================================================ 77 | title: Neorg 78 | --- 79 | author: nvim-neorg 80 | -------------------------------------------------------------------------------- 81 | 82 | (metadata 83 | (pair 84 | (key) 85 | (string)) 86 | (delimiter) 87 | (pair 88 | (key) 89 | (string))) 90 | 91 | ================================================================================ 92 | Named delimiter 93 | ================================================================================ 94 | title: Neorg 95 | 96 | --- AUTHOR --- 97 | author: nvim-neorg 98 | 99 | -------------------------------------------------------------------------------- 100 | 101 | (metadata 102 | (pair 103 | (key) 104 | (string)) 105 | (delimiter) 106 | (pair 107 | (key) 108 | (string))) 109 | 110 | ================================================================================ 111 | Groups 112 | ================================================================================ 113 | tangle: { 114 | file: location 115 | language: lua 116 | } 117 | -------------------------------------------------------------------------------- 118 | 119 | (metadata 120 | (pair 121 | (key) 122 | (object 123 | (pair 124 | (key) 125 | (string)) 126 | (pair 127 | (key) 128 | (string))))) 129 | 130 | ================================================================================ 131 | Groups within Groups 132 | ================================================================================ 133 | parent_key: { 134 | nested_key: { 135 | key: string 136 | otherkey: string 137 | } 138 | } 139 | -------------------------------------------------------------------------------- 140 | 141 | (metadata 142 | (pair 143 | (key) 144 | (object 145 | (pair 146 | (key) 147 | (object 148 | (pair 149 | (key) 150 | (string)) 151 | (pair 152 | (key) 153 | (string))))))) 154 | 155 | ================================================================================ 156 | Arrays of Items 157 | ================================================================================ 158 | key: [ 159 | array item 1 160 | array item 2 161 | 162 | array item 3 163 | ] 164 | -------------------------------------------------------------------------------- 165 | 166 | (metadata 167 | (pair 168 | (key) 169 | (array 170 | (string) 171 | (string) 172 | (string)))) 173 | 174 | ================================================================================ 175 | Arrays Within Objects 176 | ================================================================================ 177 | object: { 178 | array: [ 179 | item 1 180 | item 2 181 | item 3 182 | ] 183 | } 184 | -------------------------------------------------------------------------------- 185 | 186 | (metadata 187 | (pair 188 | (key) 189 | (object 190 | (pair 191 | (key) 192 | (array 193 | (string) 194 | (string) 195 | (string)))))) 196 | --------------------------------------------------------------------------------