Use tree-sitter-toml from crates.io

pull/795/head
Wilfred Hughes 2024-12-20 09:07:52 +07:00
parent c73b18be77
commit a6eb339f71
45 changed files with 31 additions and 11582 deletions

@ -12,7 +12,7 @@ Improved language detection when one argument is a named pipe.
Updated to the latest tree-sitter parser for Bash, C, C++, C#, CSS,
Go, Haskell, HTML, Java, JavaScript, JSON, Julia, Objective-C, OCaml,
PHP, Python, Ruby, Scala and TypeScript.
PHP, Python, Ruby, Scala, TOML and TypeScript.
### Syntax Highlighting

11
Cargo.lock generated

@ -268,6 +268,7 @@ dependencies = [
"tree-sitter-python",
"tree-sitter-ruby",
"tree-sitter-scala",
"tree-sitter-toml-ng",
"tree-sitter-typescript",
"tree_magic_mini",
"typed-arena",
@ -1206,6 +1207,16 @@ dependencies = [
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-toml-ng"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9adc2c898ae49730e857d75be403da3f92bb81d8e37a2f918a08dd10de5ebb1"
dependencies = [
"cc",
"tree-sitter-language",
]
[[package]]
name = "tree-sitter-typescript"
version = "0.23.2"

@ -97,6 +97,7 @@ tree-sitter-php = "0.23.11"
tree-sitter-json = "0.24.8"
tree-sitter-html = "0.23.2"
tree-sitter-css = "0.23.1"
tree-sitter-toml-ng = "0.7.0"
[dev-dependencies]
# assert_cmd 2.0.10 requires predicates 3.

@ -247,11 +247,6 @@ fn main() {
src_dir: "vendored_parsers/tree-sitter-swift-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-toml",
src_dir: "vendored_parsers/tree-sitter-toml-src",
extra_files: vec!["scanner.c"],
},
TreeSitterParser {
name: "tree-sitter-vhdl",
src_dir: "vendored_parsers/tree-sitter-vhdl-src",

@ -60,16 +60,16 @@ with `difft --list-languages`.
## Structured Text Formats
| Language | Parser Used |
|----------|-------------------------------------------------------------------------------------|
| CSS | [tree-sitter/tree-sitter-css](https://github.com/tree-sitter/tree-sitter-css) |
| HCL | [MichaHoffmann/tree-sitter-hcl](https://github.com/MichaHoffmann/tree-sitter-hcl) |
| HTML | [tree-sitter/tree-sitter-html](https://github.com/tree-sitter/tree-sitter-html) |
| JSON | [tree-sitter/tree-sitter-json](https://github.com/tree-sitter/tree-sitter-json) |
| LaTeX | [latex-lsp/tree-sitter-latex](https://github.com/latex-lsp/tree-sitter-latex) |
| Newick | [delehef/tree-sitter-newick](https://github.com/delehef/tree-sitter-newick) |
| SCSS | [serenadeai/tree-sitter-scss](https://github.com/serenadeai/tree-sitter-scss) |
| TOML | [ikatyang/tree-sitter-toml](https://github.com/ikatyang/tree-sitter-toml) |
| XML | [ObserverOfTime/tree-sitter-xml](https://github.com/ObserverOfTime/tree-sitter-xml) |
| YAML | [ikatyang/tree-sitter-yaml](https://github.com/ikatyang/tree-sitter-yaml) |
| Language | Parser Used |
|----------|---------------------------------------------------------------------------------------------------|
| CSS | [tree-sitter/tree-sitter-css](https://github.com/tree-sitter/tree-sitter-css) |
| HCL | [MichaHoffmann/tree-sitter-hcl](https://github.com/MichaHoffmann/tree-sitter-hcl) |
| HTML | [tree-sitter/tree-sitter-html](https://github.com/tree-sitter/tree-sitter-html) |
| JSON | [tree-sitter/tree-sitter-json](https://github.com/tree-sitter/tree-sitter-json) |
| LaTeX | [latex-lsp/tree-sitter-latex](https://github.com/latex-lsp/tree-sitter-latex) |
| Newick | [delehef/tree-sitter-newick](https://github.com/delehef/tree-sitter-newick) |
| SCSS | [serenadeai/tree-sitter-scss](https://github.com/serenadeai/tree-sitter-scss) |
| TOML | [tree-sitter-grammars/tree-sitter-toml](https://github.com/tree-sitter-grammars/tree-sitter-toml) |
| XML | [ObserverOfTime/tree-sitter-xml](https://github.com/ObserverOfTime/tree-sitter-xml) |
| YAML | [ikatyang/tree-sitter-yaml](https://github.com/ikatyang/tree-sitter-yaml) |

@ -278,7 +278,7 @@ sample_files/todomvc_1.gleam sample_files/todomvc_2.gleam
9fe64f7d77ad99095ac29357554f3d71 -
sample_files/toml_1.toml sample_files/toml_2.toml
a771827287e174fc2e18a1cd2624bc9c -
c331bdb54c00b0a5b5a622dbd250042a -
sample_files/trailling_newline_1.yaml sample_files/trailling_newline_2.yaml
8e37febfec957288576f9c2020cfc4f2 -

@ -97,7 +97,6 @@ extern "C" {
fn tree_sitter_solidity() -> ts::Language;
fn tree_sitter_sql() -> ts::Language;
fn tree_sitter_swift() -> ts::Language;
fn tree_sitter_toml() -> ts::Language;
fn tree_sitter_vhdl() -> ts::Language;
fn tree_sitter_xml() -> ts::Language;
fn tree_sitter_yaml() -> ts::Language;
@ -1038,16 +1037,15 @@ pub(crate) fn from_language(language: guess::Language) -> TreeSitterConfig {
}
}
Toml => {
let language = unsafe { tree_sitter_toml() };
let language_fn = tree_sitter_toml_ng::LANGUAGE;
let language = tree_sitter::Language::new(language_fn);
TreeSitterConfig {
language: language.clone(),
atom_nodes: vec!["string", "quoted_key"].into_iter().collect(),
delimiter_tokens: vec![("{", "}"), ("[", "]")],
highlight_query: ts::Query::new(
&language,
include_str!("../../vendored_parsers/highlights/toml.scm"),
)
.unwrap(),
highlight_query: ts::Query::new(&language, tree_sitter_toml_ng::HIGHLIGHTS_QUERY)
.unwrap(),
sub_languages: vec![],
}
}

@ -1 +0,0 @@
../tree-sitter-toml/queries/highlights.scm

@ -1 +0,0 @@
tree-sitter-toml/src

@ -1,12 +0,0 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[corpus/*]
trim_trailing_whitespace = false

@ -1,7 +0,0 @@
* text eol=lf
*.wasm binary
/src/** linguist-generated
/src/scanner.c linguist-generated=false
/index.js linguist-generated
/binding.gyp linguist-detectable=false

@ -1,5 +0,0 @@
/build
/node_modules
/bindings/rust
/Cargo.toml

@ -1,4 +0,0 @@
[submodule "tree-sitter"]
path = tree-sitter
url = https://github.com/ikatyang/tree-sitter
branch = v0.19.3-custom

@ -1,13 +0,0 @@
language: rust
rust:
- stable
script:
- if [ ! -d "./tree-sitter/target/release" ]; then bash ./scripts/setup-tree-sitter.sh; fi
- ./tree-sitter/target/release/tree-sitter test
cache:
cargo: true
directories:
- ./tree-sitter

@ -1,95 +0,0 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [0.5.1](https://github.com/ikatyang/tree-sitter-toml/compare/v0.5.0...v0.5.1) (2021-03-21)
### Bug Fixes
* add missing binding.gyp ([5366d87](https://github.com/ikatyang/tree-sitter-toml/commit/5366d87))
# [0.5.0](https://github.com/ikatyang/tree-sitter-toml/compare/v0.4.1...v0.5.0) (2021-03-14)
### Features
* upgrade to tree-sitter@0.19.3 ([e880176](https://github.com/ikatyang/tree-sitter-toml/commit/e880176))
### BREAKING CHANGES
* require tree-sitter 0.19+
## [0.4.1](https://github.com/ikatyang/tree-sitter-toml/compare/v0.4.0...v0.4.1) (2020-11-14)
### Bug Fixes
* immediate hash in string is considered content instead of comment ([#18](https://github.com/ikatyang/tree-sitter-toml/issues/18)) ([4993307](https://github.com/ikatyang/tree-sitter-toml/commit/4993307))
# [0.4.0](https://github.com/ikatyang/tree-sitter-toml/compare/v0.3.0...v0.4.0) (2020-07-04)
### Features
* add queries for highlighting ([#13](https://github.com/ikatyang/tree-sitter-toml/issues/13)) ([64da30c](https://github.com/ikatyang/tree-sitter-toml/commit/64da30c))
# [0.3.0](https://github.com/ikatyang/tree-sitter-toml/compare/v0.2.0...v0.3.0) (2020-06-28)
### Features
* upgrade to TOML spec v1.0.0-rc.1 ([#11](https://github.com/ikatyang/tree-sitter-toml/issues/11)) ([7df9880](https://github.com/ikatyang/tree-sitter-toml/commit/7df9880))
## [0.2.0](https://github.com/ikatyang/tree-sitter-toml/compare/v0.1.3...v0.2.0) (2019-08-31)
### ⚠ BREAKING CHANGES
- rename `file` with `document`.
- rename `table_array` with `table_array_element`.
- unflatten `table` and `table_array_element`, i.e., `pair`s are now their children instead of siblings.
### Features
* unflatten structure and rename nodes ([#4](https://github.com/ikatyang/tree-sitter-toml/issues/4)) ([42afd6a](https://github.com/ikatyang/tree-sitter-toml/commit/42afd6a))
### [0.1.3](https://github.com/ikatyang/tree-sitter-toml/compare/v0.1.2...v0.1.3) (2019-08-21)
### Bug Fixes
* trailing whitespaces are allowed for `local_time` ([#3](https://github.com/ikatyang/tree-sitter-toml/issues/3)) ([752419c](https://github.com/ikatyang/tree-sitter-toml/commit/752419c))
### [0.1.2](https://github.com/ikatyang/tree-sitter-toml/compare/v0.1.1...v0.1.2) (2019-08-20)
### Features
* flatten table/table-array structure ([#2](https://github.com/ikatyang/tree-sitter-toml/issues/2)) ([a381203](https://github.com/ikatyang/tree-sitter-toml/commit/a381203))
* rename `root` with `file` ([a0cd384](https://github.com/ikatyang/tree-sitter-toml/commit/a0cd384))
### [0.1.1](https://github.com/ikatyang/tree-sitter-toml/compare/v0.1.0...v0.1.1) (2019-08-20)
### Bug Fixes
* disallow invalid whitespaces between scalar components ([#1](https://github.com/ikatyang/tree-sitter-toml/issues/1)) ([e2b28db](https://github.com/ikatyang/tree-sitter-toml/commit/e2b28db))
## 0.1.0 (2019-08-18)
### Features
* initial implementation ([5acac39](https://github.com/ikatyang/tree-sitter-toml/commit/5acac39))

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) Ika <ikatyang@gmail.com> (https://github.com/ikatyang)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -1,41 +0,0 @@
# tree-sitter-toml
[![npm](https://img.shields.io/npm/v/tree-sitter-toml.svg)](https://www.npmjs.com/package/tree-sitter-toml)
[![build](https://img.shields.io/travis/com/ikatyang/tree-sitter-toml/master.svg)](https://travis-ci.com/ikatyang/tree-sitter-toml/builds)
TOML ([TOML Spec v1.0.0-rc.1](https://github.com/toml-lang/toml/blob/v1.0.0-rc.1/versions/en/toml-v1.0.0-rc.1.md)) grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter)
[Changelog](https://github.com/ikatyang/tree-sitter-toml/blob/master/CHANGELOG.md)
## Install
```sh
npm install tree-sitter-toml tree-sitter
```
## Usage
```js
const Parser = require("tree-sitter");
const TOML = require("tree-sitter-toml");
const parser = new Parser();
parser.setLanguage(TOML);
const sourceCode = `
[hello]
world = true
`;
const tree = parser.parse(sourceCode);
console.log(tree.rootNode.toString());
// (document
// (table
// (key)
// (pair
// (key) (boolean))))
```
## License
MIT © [Ika](https://github.com/ikatyang)

@ -1,19 +0,0 @@
{
"targets": [
{
"target_name": "tree_sitter_toml_binding",
"include_dirs": [
"<!(node -e \"require('nan')\")",
"src"
],
"sources": [
"src/parser.c",
"src/scanner.c",
"bindings/node/binding.cc"
],
"cflags_c": [
"-std=c99",
]
}
]
}

@ -1,28 +0,0 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
using namespace v8;
extern "C" TSLanguage * tree_sitter_toml();
namespace {
NAN_METHOD(New) {}
void Init(Local<Object> exports, Local<Object> module) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_toml());
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("toml").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}
NODE_MODULE(tree_sitter_toml_binding, Init)
} // namespace

@ -1,19 +0,0 @@
try {
module.exports = require("../../build/Release/tree_sitter_toml_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_toml_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
}
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}

@ -1,296 +0,0 @@
================================================================================
VALID - empty file
================================================================================
--------------------------------------------------------------------------------
(document)
================================================================================
INVALID - key/value pair - multiline string for keys are not allowed
================================================================================
"""
invalid
multiline
basic
key
""" = false
'''
invalid
multiline
literal
key
''' = false
--------------------------------------------------------------------------------
(document
(ERROR
(quoted_key)
(bare_key)
(bare_key)
(bare_key))
(pair
(bare_key)
(ERROR)
(boolean))
(ERROR
(quoted_key)
(bare_key)
(bare_key)
(bare_key))
(pair
(bare_key)
(ERROR)
(boolean)))
================================================================================
INVALID - float - whitespaces between its components are not allowed
================================================================================
invalid_fractional = 1 .0
invalid_exponent = 1 e 2
invalid_both = 1 .0 e 2
--------------------------------------------------------------------------------
(document
(ERROR
(bare_key)
(integer)
(bare_key)
(bare_key)
(bare_key)
(bare_key)
(bare_key)
(bare_key)
(bare_key)
(bare_key)
(bare_key)
(bare_key)))
================================================================================
INVALID - offset date time - whitespaces between its components are not allowed
================================================================================
invalid1 = 1979-05-27 07:32:00 Z
invalid2 = 1979-05-27 T 07:32:00 Z
--------------------------------------------------------------------------------
(document
(ERROR
(bare_key)
(local_date)
(local_time)
(bare_key)
(bare_key)
(bare_key)
(bare_key)
(local_time)
(bare_key)))
================================================================================
INVALID - local date time - whitespaces between its components are not allowed
================================================================================
invalid1 = 1979-05-27 07:32:00
invalid2 = 1979-05-27 T 07:32:00
--------------------------------------------------------------------------------
(document
(ERROR
(bare_key)
(local_date)
(local_time)
(bare_key)
(bare_key)
(bare_key)
(local_time)))
================================================================================
VALID - local date - trailing whitespaces are allowed
================================================================================
valid = 1979-05-27
--------------------------------------------------------------------------------
(document
(pair
(bare_key)
(local_date)))
================================================================================
INVALID - table - multiline string for header keys are not allowed
================================================================================
["""
invalid
multiline
basic
key
"""]
['''
invalid
multiline
basic
key
''']
--------------------------------------------------------------------------------
(document
(table
(ERROR
(quoted_key)
(bare_key)
(bare_key)
(bare_key))
(bare_key)
(ERROR))
(table
(ERROR
(quoted_key)
(bare_key)
(bare_key)
(bare_key))
(bare_key)
(ERROR)))
================================================================================
INVALID - inline table - newlines outside of pairs are not allowed
================================================================================
key = {
newline = true
}
--------------------------------------------------------------------------------
(document
(pair
(bare_key)
(inline_table
(ERROR)
(pair
(bare_key)
(boolean))
(ERROR))))
================================================================================
INVALID - array of tables - multiline string for header keys are not allowed
================================================================================
[["""
invalid
multiline
basic
key
"""]]
[['''
invalid
multiline
basic
key
''']]
--------------------------------------------------------------------------------
(document
(ERROR
(ERROR
(quoted_key)
(bare_key)
(bare_key)
(bare_key)
(bare_key)
(bare_key)
(bare_key)
(bare_key))
(bare_key)))
================================================================================
VALID - table - empty content separated by comments
================================================================================
[table]
# comment
--------------------------------------------------------------------------------
(document
(table
(bare_key)
(comment)))
================================================================================
VALID - array of tables - empty content separated by comments
================================================================================
[[array-table]]
# comment
--------------------------------------------------------------------------------
(document
(table_array_element
(bare_key)
(comment)))
================================================================================
VALID - table - two pairs separated by comments
================================================================================
[table]
a = 1
# comment
b = 2
--------------------------------------------------------------------------------
(document
(table
(bare_key)
(pair
(bare_key)
(integer))
(comment)
(pair
(bare_key)
(integer))))
================================================================================
VALID - array of tables - two pairs separated by comments
================================================================================
[[array-table]]
a = 1
# comment
b = 2
--------------------------------------------------------------------------------
(document
(table_array_element
(bare_key)
(pair
(bare_key)
(integer))
(comment)
(pair
(bare_key)
(integer))))

@ -1,19 +0,0 @@
================================================================================
VALID - issue #17 - immediate hash in string is considered content instead of comment
================================================================================
# This is a full-line comment
key = "value" # This is a comment at the end of a line
another = "# This is not a comment"
--------------------------------------------------------------------------------
(document
(comment)
(pair
(bare_key)
(string)
(comment))
(pair
(bare_key)
(string)))

File diff suppressed because it is too large Load Diff

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2018 Max Brunsfeld
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -1,469 +0,0 @@
let tree;
(async () => {
const CAPTURE_REGEX = /@\s*([\w\._-]+)/g;
const COLORS_BY_INDEX = [
'blue',
'chocolate',
'darkblue',
'darkcyan',
'darkgreen',
'darkred',
'darkslategray',
'dimgray',
'green',
'indigo',
'navy',
'red',
'sienna',
];
const scriptURL = document.currentScript.getAttribute('src');
const codeInput = document.getElementById('code-input');
const languageSelect = document.getElementById('language-select');
const loggingCheckbox = document.getElementById('logging-checkbox');
const outputContainer = document.getElementById('output-container');
const outputContainerScroll = document.getElementById('output-container-scroll');
const playgroundContainer = document.getElementById('playground-container');
const queryCheckbox = document.getElementById('query-checkbox');
const queryContainer = document.getElementById('query-container');
const queryInput = document.getElementById('query-input');
const updateTimeSpan = document.getElementById('update-time');
const languagesByName = {};
loadState();
await TreeSitter.init();
const parser = new TreeSitter();
const codeEditor = CodeMirror.fromTextArea(codeInput, {
lineNumbers: true,
showCursorWhenSelecting: true
});
const queryEditor = CodeMirror.fromTextArea(queryInput, {
lineNumbers: true,
showCursorWhenSelecting: true
});
const cluster = new Clusterize({
rows: [],
noDataText: null,
contentElem: outputContainer,
scrollElem: outputContainerScroll
});
const renderTreeOnCodeChange = debounce(renderTree, 50);
const saveStateOnChange = debounce(saveState, 2000);
const runTreeQueryOnChange = debounce(runTreeQuery, 50);
let languageName = languageSelect.value;
let treeRows = null;
let treeRowHighlightedIndex = -1;
let parseCount = 0;
let isRendering = 0;
let query;
codeEditor.on('changes', handleCodeChange);
codeEditor.on('viewportChange', runTreeQueryOnChange);
codeEditor.on('cursorActivity', debounce(handleCursorMovement, 150));
queryEditor.on('changes', debounce(handleQueryChange, 150));
loggingCheckbox.addEventListener('change', handleLoggingChange);
queryCheckbox.addEventListener('change', handleQueryEnableChange);
languageSelect.addEventListener('change', handleLanguageChange);
outputContainer.addEventListener('click', handleTreeClick);
handleQueryEnableChange();
await handleLanguageChange()
playgroundContainer.style.visibility = 'visible';
async function handleLanguageChange() {
const newLanguageName = languageSelect.value;
if (!languagesByName[newLanguageName]) {
const url = `${LANGUAGE_BASE_URL}/tree-sitter-${newLanguageName}.wasm`
languageSelect.disabled = true;
try {
languagesByName[newLanguageName] = await TreeSitter.Language.load(url);
} catch (e) {
console.error(e);
languageSelect.value = languageName;
return
} finally {
languageSelect.disabled = false;
}
}
tree = null;
languageName = newLanguageName;
parser.setLanguage(languagesByName[newLanguageName]);
handleCodeChange();
handleQueryChange();
}
async function handleCodeChange(editor, changes) {
const newText = codeEditor.getValue();
const edits = tree && changes && changes.map(treeEditForEditorChange);
const start = performance.now();
if (edits) {
for (const edit of edits) {
tree.edit(edit);
}
}
const newTree = parser.parse(newText, tree);
const duration = (performance.now() - start).toFixed(1);
updateTimeSpan.innerText = `${duration} ms`;
if (tree) tree.delete();
tree = newTree;
parseCount++;
renderTreeOnCodeChange();
runTreeQueryOnChange();
saveStateOnChange();
}
async function renderTree() {
isRendering++;
const cursor = tree.walk();
let currentRenderCount = parseCount;
let row = '';
let rows = [];
let finishedRow = false;
let visitedChildren = false;
let indentLevel = 0;
for (let i = 0;; i++) {
if (i > 0 && i % 10000 === 0) {
await new Promise(r => setTimeout(r, 0));
if (parseCount !== currentRenderCount) {
cursor.delete();
isRendering--;
return;
}
}
let displayName;
if (cursor.nodeIsMissing) {
displayName = `MISSING ${cursor.nodeType}`
} else if (cursor.nodeIsNamed) {
displayName = cursor.nodeType;
}
if (visitedChildren) {
if (displayName) {
finishedRow = true;
}
if (cursor.gotoNextSibling()) {
visitedChildren = false;
} else if (cursor.gotoParent()) {
visitedChildren = true;
indentLevel--;
} else {
break;
}
} else {
if (displayName) {
if (finishedRow) {
row += '</div>';
rows.push(row);
finishedRow = false;
}
const start = cursor.startPosition;
const end = cursor.endPosition;
const id = cursor.nodeId;
let fieldName = cursor.currentFieldName();
if (fieldName) {
fieldName += ': ';
} else {
fieldName = '';
}
row = `<div>${' '.repeat(indentLevel)}${fieldName}<a class='plain' href="#" data-id=${id} data-range="${start.row},${start.column},${end.row},${end.column}">${displayName}</a> [${start.row}, ${start.column}] - [${end.row}, ${end.column}])`;
finishedRow = true;
}
if (cursor.gotoFirstChild()) {
visitedChildren = false;
indentLevel++;
} else {
visitedChildren = true;
}
}
}
if (finishedRow) {
row += '</div>';
rows.push(row);
}
cursor.delete();
cluster.update(rows);
treeRows = rows;
isRendering--;
handleCursorMovement();
}
function runTreeQuery(_, startRow, endRow) {
if (endRow == null) {
const viewport = codeEditor.getViewport();
startRow = viewport.from;
endRow = viewport.to;
}
codeEditor.operation(() => {
const marks = codeEditor.getAllMarks();
marks.forEach(m => m.clear());
if (tree && query) {
const captures = query.captures(
tree.rootNode,
{row: startRow, column: 0},
{row: endRow, column: 0},
);
let lastNodeId;
for (const {name, node} of captures) {
if (node.id === lastNodeId) continue;
lastNodeId = node.id;
const {startPosition, endPosition} = node;
codeEditor.markText(
{line: startPosition.row, ch: startPosition.column},
{line: endPosition.row, ch: endPosition.column},
{
inclusiveLeft: true,
inclusiveRight: true,
css: `color: ${colorForCaptureName(name)}`
}
);
}
}
});
}
function handleQueryChange() {
if (query) {
query.delete();
query.deleted = true;
query = null;
}
queryEditor.operation(() => {
queryEditor.getAllMarks().forEach(m => m.clear());
if (!queryCheckbox.checked) return;
const queryText = queryEditor.getValue();
try {
query = parser.getLanguage().query(queryText);
let match;
let row = 0;
queryEditor.eachLine((line) => {
while (match = CAPTURE_REGEX.exec(line.text)) {
queryEditor.markText(
{line: row, ch: match.index},
{line: row, ch: match.index + match[0].length},
{
inclusiveLeft: true,
inclusiveRight: true,
css: `color: ${colorForCaptureName(match[1])}`
}
);
}
row++;
});
} catch (error) {
const startPosition = queryEditor.posFromIndex(error.index);
const endPosition = {
line: startPosition.line,
ch: startPosition.ch + (error.length || Infinity)
};
if (error.index === queryText.length) {
if (startPosition.ch > 0) {
startPosition.ch--;
} else if (startPosition.row > 0) {
startPosition.row--;
startPosition.column = Infinity;
}
}
queryEditor.markText(
startPosition,
endPosition,
{
className: 'query-error',
inclusiveLeft: true,
inclusiveRight: true,
attributes: {title: error.message}
}
);
}
});
runTreeQuery();
saveQueryState();
}
function handleCursorMovement() {
if (isRendering) return;
const selection = codeEditor.getDoc().listSelections()[0];
let start = {row: selection.anchor.line, column: selection.anchor.ch};
let end = {row: selection.head.line, column: selection.head.ch};
if (
start.row > end.row ||
(
start.row === end.row &&
start.column > end.column
)
) {
let swap = end;
end = start;
start = swap;
}
const node = tree.rootNode.namedDescendantForPosition(start, end);
if (treeRows) {
if (treeRowHighlightedIndex !== -1) {
const row = treeRows[treeRowHighlightedIndex];
if (row) treeRows[treeRowHighlightedIndex] = row.replace('highlighted', 'plain');
}
treeRowHighlightedIndex = treeRows.findIndex(row => row.includes(`data-id=${node.id}`));
if (treeRowHighlightedIndex !== -1) {
const row = treeRows[treeRowHighlightedIndex];
if (row) treeRows[treeRowHighlightedIndex] = row.replace('plain', 'highlighted');
}
cluster.update(treeRows);
const lineHeight = cluster.options.item_height;
const scrollTop = outputContainerScroll.scrollTop;
const containerHeight = outputContainerScroll.clientHeight;
const offset = treeRowHighlightedIndex * lineHeight;
if (scrollTop > offset - 20) {
$(outputContainerScroll).animate({scrollTop: offset - 20}, 150);
} else if (scrollTop < offset + lineHeight + 40 - containerHeight) {
$(outputContainerScroll).animate({scrollTop: offset - containerHeight + 40}, 150);
}
}
}
function handleTreeClick(event) {
if (event.target.tagName === 'A') {
event.preventDefault();
const [startRow, startColumn, endRow, endColumn] = event
.target
.dataset
.range
.split(',')
.map(n => parseInt(n));
codeEditor.focus();
codeEditor.setSelection(
{line: startRow, ch: startColumn},
{line: endRow, ch: endColumn}
);
}
}
function handleLoggingChange() {
if (loggingCheckbox.checked) {
parser.setLogger((message, lexing) => {
if (lexing) {
console.log(" ", message)
} else {
console.log(message)
}
});
} else {
parser.setLogger(null);
}
}
function handleQueryEnableChange() {
if (queryCheckbox.checked) {
queryContainer.style.visibility = '';
queryContainer.style.position = '';
} else {
queryContainer.style.visibility = 'hidden';
queryContainer.style.position = 'absolute';
}
handleQueryChange();
}
function treeEditForEditorChange(change) {
const oldLineCount = change.removed.length;
const newLineCount = change.text.length;
const lastLineLength = change.text[newLineCount - 1].length;
const startPosition = {row: change.from.line, column: change.from.ch};
const oldEndPosition = {row: change.to.line, column: change.to.ch};
const newEndPosition = {
row: startPosition.row + newLineCount - 1,
column: newLineCount === 1
? startPosition.column + lastLineLength
: lastLineLength
};
const startIndex = codeEditor.indexFromPos(change.from);
let newEndIndex = startIndex + newLineCount - 1;
let oldEndIndex = startIndex + oldLineCount - 1;
for (let i = 0; i < newLineCount; i++) newEndIndex += change.text[i].length;
for (let i = 0; i < oldLineCount; i++) oldEndIndex += change.removed[i].length;
return {
startIndex, oldEndIndex, newEndIndex,
startPosition, oldEndPosition, newEndPosition
};
}
function colorForCaptureName(capture) {
const id = query.captureNames.indexOf(capture);
return COLORS_BY_INDEX[id % COLORS_BY_INDEX.length];
}
function getLocalStorageItem(key) {
return localStorage.getItem(`${document.title}:${key}`);
}
function setLocalStorageItem(key, value) {
localStorage.setItem(`${document.title}:${key}`, value);
}
function loadState() {
const language = getLocalStorageItem("language");
const sourceCode = getLocalStorageItem("sourceCode");
const query = getLocalStorageItem("query");
const queryEnabled = getLocalStorageItem("queryEnabled");
if (language != null && sourceCode != null && query != null) {
queryInput.value = query;
codeInput.value = sourceCode;
languageSelect.value = language;
queryCheckbox.checked = (queryEnabled === 'true');
}
}
function saveState() {
setLocalStorageItem("language", languageSelect.value);
setLocalStorageItem("sourceCode", codeEditor.getValue());
saveQueryState();
}
function saveQueryState() {
setLocalStorageItem("queryEnabled", queryCheckbox.checked);
setLocalStorageItem("query", queryEditor.getValue());
}
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
}
})();

File diff suppressed because one or more lines are too long

@ -1,21 +0,0 @@
The MIT License (MIT)
Copyright (c) 2018 Max Brunsfeld
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

File diff suppressed because one or more lines are too long

@ -1,162 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="assets/tree-sitter-playground-0.19.3/style.css" media="screen" type="text/css">
<title>Tree-sitter TOML Playground</title>
</head>
<body>
<div id="container">
<main id="main-content">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.45.0/codemirror.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/clusterize.js/0.18.0/clusterize.min.css">
<style>
.version {
font-size: 0.5em;
}
.credit {
font-style: italic;
margin-top: 20px;
text-align: center;
}
</style>
<h1><a href="https://github.com/ikatyang/tree-sitter-toml">Tree-sitter TOML</a> <span class="version">v0.5.1</span></h1>
<div id="playground-container" style="visibility: hidden;">
<h4>Code</h4>
<select id="language-select">
<option value="toml" selected="selected">TOML</option>
</select>
<input id="logging-checkbox" type="checkbox"></input>
<label for="logging-checkbox">Log</label>
<input id="query-checkbox" type="checkbox"></input>
<label for="query-checkbox">Query</label>
<textarea id="code-input">
</textarea>
<div id="query-container" style="visibility: hidden; position: absolute;">
<h4>Query</h4>
<textarea id="query-input"></textarea>
</div>
<h4>Tree</h4>
<span id="update-time"></span>
<div id="output-container-scroll">
<pre id="output-container" class="highlight"></pre>
</div>
</div>
<div class="credit">
This playground was modified from <a href="https://tree-sitter.github.io/tree-sitter/playground">the official Tree-sitter Playground</a>.
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/5.45.0/codemirror.min.js"></script>
<script>LANGUAGE_BASE_URL = "assets/tree-sitter-toml-0.5.1";</script>
<script src="assets/web-tree-sitter-0.19.3/tree-sitter.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/clusterize.js/0.18.0/clusterize.min.js"></script>
<script src="assets/tree-sitter-playground-0.19.3/playground.js"></script>
<script>
((codeExample, queryExample) => {
const handle = setInterval(() => {
const $codeEditor = document.querySelector('.CodeMirror');
const $queryEditor = document.querySelector('#query-container .CodeMirror');
const $queryCheckbox = document.querySelector('#query-checkbox');
if ($codeEditor && $queryEditor) {
$codeEditor.CodeMirror.setValue(codeExample);
if (queryExample) {
$queryEditor.CodeMirror.setValue(queryExample);
if (!$queryCheckbox.checked) $queryCheckbox.click();
}
clearInterval(handle);
}
}, 500);
})(`# This is a TOML document.
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates
[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true
[servers]
# Indentation (tabs and/or spaces) is allowed but not required
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"
[clients]
data = [ ["gamma", "delta"], [1, 2] ]
# Line breaks are OK when inside arrays
hosts = [
"alpha",
"omega"
]
`, `; Properties
;-----------
(bare_key) @property
(quoted_key) @string
; Literals
;---------
(boolean) @constant.builtin
(comment) @comment
(string) @string
(integer) @number
(float) @number
(offset_date_time) @string.special
(local_date_time) @string.special
(local_date) @string.special
(local_time) @string.special
; Punctuation
;------------
"." @punctuation.delimiter
"," @punctuation.delimiter
"=" @operator
"[" @punctuation.bracket
"]" @punctuation.bracket
"[[" @punctuation.bracket
"]]" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket
`);
</script>
</main>
</div>
</body>
</html>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
crossorigin="anonymous">
</script>

@ -1,33 +0,0 @@
# This is a TOML document.
title = "TOML Example"
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates
[database]
server = "192.168.1.1"
ports = [ 8001, 8001, 8002 ]
connection_max = 5000
enabled = true
[servers]
# Indentation (tabs and/or spaces) is allowed but not required
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"
[clients]
data = [ ["gamma", "delta"], [1, 2] ]
# Line breaks are OK when inside arrays
hosts = [
"alpha",
"omega"
]

@ -1,214 +0,0 @@
const { Charset } = require("regexp-util");
const getInverseRegex = charset =>
new RegExp(`[^${charset.toString().slice(1, -1)}]`);
const control_chars = new Charset([0x0, 0x1f], 0x7f);
const newline = /\r?\n/;
const decimal_integer = /[+-]?(0|[1-9](_?[0-9])*)/;
const decimal_integer_in_float_exponent_part = /[+-]?[0-9](_?[0-9])*/; // allow leading zeros
const hexadecimal_integer = /0x[0-9a-fA-F](_?[0-9a-fA-F])*/;
const octal_integer = /0o[0-7](_?[0-7])*/;
const binary_integer = /0b[01](_?[01])*/;
const float_fractional_part = /[.][0-9](_?[0-9])*/;
const float_exponent_part = seq(/[eE]/, decimal_integer_in_float_exponent_part);
const rfc3339_date = /([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])/;
const rfc3339_delimiter = /[ tT]/;
const rfc3339_time = /([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)([.][0-9]+)?/;
const rfc3339_offset = /([zZ])|([+-]([01][0-9]|2[0-3]):[0-5][0-9])/;
module.exports = grammar({
name: "toml",
externals: $ => [
$._line_ending_or_eof,
$._multiline_basic_string_content,
$._multiline_basic_string_end,
$._multiline_literal_string_content,
$._multiline_literal_string_end,
],
extras: $ => [$.comment, /[ \t]/],
rules: {
document: $ =>
seq(
repeat(choice($.pair, newline)),
repeat(choice($.table, $.table_array_element)),
),
comment: $ =>
token(prec(-1, seq(
"#",
repeat(getInverseRegex(control_chars.subtract("\t"))),
))),
table: $ =>
seq(
"[",
choice($.dotted_key, $._key),
"]",
$._line_ending_or_eof,
repeat(choice($.pair, newline)),
),
table_array_element: $ =>
seq(
"[[",
choice($.dotted_key, $._key),
"]]",
$._line_ending_or_eof,
repeat(choice($.pair, newline)),
),
pair: $ => seq($._inline_pair, $._line_ending_or_eof),
_inline_pair: $ => seq(choice($.dotted_key, $._key), "=", $._inline_value),
_key: $ => choice($.bare_key, $.quoted_key),
dotted_key: $ => seq(choice($.dotted_key, $._key), ".", $._key),
bare_key: $ => /[A-Za-z0-9_-]+/,
quoted_key: $ => choice($._basic_string, $._literal_string),
_inline_value: $ =>
choice(
$.string,
$.integer,
$.float,
$.boolean,
$.offset_date_time,
$.local_date_time,
$.local_date,
$.local_time,
$.array,
$.inline_table,
),
string: $ =>
choice(
$._basic_string,
$._multiline_basic_string,
$._literal_string,
$._multiline_literal_string,
),
_basic_string: $ =>
seq(
'"',
repeat(
choice(
token.immediate(
repeat1(
getInverseRegex(control_chars.subtract("\t").union('"', "\\")),
),
),
$.escape_sequence,
),
),
token.immediate('"'),
),
_multiline_basic_string: $ =>
seq(
'"""',
repeat(
choice(
token.immediate(
repeat1(
getInverseRegex(control_chars.subtract("\t").union('"', "\\")),
),
),
$._multiline_basic_string_content,
token.immediate(newline),
$.escape_sequence,
alias($._escape_line_ending, $.escape_sequence),
),
),
$._multiline_basic_string_end,
),
escape_sequence: $ =>
token.immediate(/\\([btnfr"\\]|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})/),
_escape_line_ending: $ => token.immediate(seq(/\\/, newline)),
_literal_string: $ =>
seq(
"'",
optional(
token.immediate(
repeat1(getInverseRegex(control_chars.union("'").subtract("\t"))),
),
),
token.immediate("'"),
),
_multiline_literal_string: $ =>
seq(
"'''",
repeat(
choice(
token.immediate(
repeat1(getInverseRegex(control_chars.union("'").subtract("\t"))),
),
$._multiline_literal_string_content,
token.immediate(newline),
),
),
$._multiline_literal_string_end,
),
integer: $ =>
choice(
decimal_integer,
hexadecimal_integer,
octal_integer,
binary_integer,
),
float: $ =>
choice(
token(
seq(
decimal_integer,
choice(
float_fractional_part,
seq(optional(float_fractional_part), float_exponent_part),
),
),
),
/[+-]?(inf|nan)/,
),
boolean: $ => /true|false/,
offset_date_time: $ =>
token(seq(rfc3339_date, rfc3339_delimiter, rfc3339_time, rfc3339_offset)),
local_date_time: $ =>
token(seq(rfc3339_date, rfc3339_delimiter, rfc3339_time)),
local_date: $ => rfc3339_date,
local_time: $ => rfc3339_time,
array: $ =>
seq(
"[",
repeat(newline),
optional(
seq(
$._inline_value,
repeat(newline),
repeat(seq(",", repeat(newline), $._inline_value, repeat(newline))),
optional(seq(",", repeat(newline))),
),
),
"]",
),
inline_table: $ =>
seq(
"{",
optional(
seq(
alias($._inline_pair, $.pair),
repeat(seq(",", alias($._inline_pair, $.pair))),
),
),
"}",
),
},
});

@ -1,56 +0,0 @@
{
"name": "tree-sitter-toml",
"version": "0.5.1",
"description": "TOML grammar for tree-sitter",
"keywords": [
"parser",
"lexer"
],
"main": "bindings/node",
"repository": "https://github.com/ikatyang/tree-sitter-toml",
"homepage": "https://github.com/ikatyang/tree-sitter-toml#readme",
"author": {
"name": "Ika",
"email": "ikatyang@gmail.com",
"url": "https://github.com/ikatyang"
},
"license": "MIT",
"scripts": {
"test": "yarn tree-sitter test",
"prepack": "yarn tree-sitter generate",
"release": "standard-version --commit-all",
"tree-sitter": "./tree-sitter/target/release/tree-sitter"
},
"standard-version": {
"preset": "angular",
"scripts": {
"postbump": "rm -r docs && node scripts/generate-playground.js && git add docs"
}
},
"dependencies": {
"nan": "^2.14.0"
},
"devDependencies": {
"regexp-util": "1.2.2",
"standard-version": "7.0.0"
},
"files": [
"/src/",
"/queries/",
"/bindings/node/",
"/binding.gyp",
"/grammar.js"
],
"tree-sitter": [
{
"scope": "source.toml",
"file-types": [
"toml"
],
"highlights": [
"queries/highlights.scm"
],
"injection-regex": "^toml$"
}
]
}

@ -1,33 +0,0 @@
; Properties
;-----------
(bare_key) @property
(quoted_key) @string
; Literals
;---------
(boolean) @constant.builtin
(comment) @comment
(string) @string
(integer) @number
(float) @number
(offset_date_time) @string.special
(local_date_time) @string.special
(local_date) @string.special
(local_time) @string.special
; Punctuation
;------------
"." @punctuation.delimiter
"," @punctuation.delimiter
"=" @operator
"[" @punctuation.bracket
"]" @punctuation.bracket
"[[" @punctuation.bracket
"]]" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket

@ -1,15 +0,0 @@
const fs = require("fs");
const path = require("path");
const generatePlayground = require("../tree-sitter/script/generate-playground");
generatePlayground("docs", {
name: "TOML",
codeExample: fs.readFileSync(
path.resolve(__dirname, "../examples/toml-lang.toml"),
"utf8",
),
queryExample: fs.readFileSync(
path.resolve(__dirname, "../queries/highlights.scm"),
"utf8",
),
});

@ -1,4 +0,0 @@
git submodule update --init
cd tree-sitter
./script/build-wasm
cargo build --release

@ -1,838 +0,0 @@
{
"name": "toml",
"rules": {
"document": {
"type": "SEQ",
"members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "pair"
},
{
"type": "PATTERN",
"value": "\\r?\\n"
}
]
}
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "table"
},
{
"type": "SYMBOL",
"name": "table_array_element"
}
]
}
}
]
},
"comment": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": -1,
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "#"
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "[^\\u0000-\\u0008\\u000a-\\u001f\\u007f]"
}
}
]
}
}
},
"table": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "dotted_key"
},
{
"type": "SYMBOL",
"name": "_key"
}
]
},
{
"type": "STRING",
"value": "]"
},
{
"type": "SYMBOL",
"name": "_line_ending_or_eof"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "pair"
},
{
"type": "PATTERN",
"value": "\\r?\\n"
}
]
}
}
]
},
"table_array_element": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "[["
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "dotted_key"
},
{
"type": "SYMBOL",
"name": "_key"
}
]
},
{
"type": "STRING",
"value": "]]"
},
{
"type": "SYMBOL",
"name": "_line_ending_or_eof"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "pair"
},
{
"type": "PATTERN",
"value": "\\r?\\n"
}
]
}
}
]
},
"pair": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_inline_pair"
},
{
"type": "SYMBOL",
"name": "_line_ending_or_eof"
}
]
},
"_inline_pair": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "dotted_key"
},
{
"type": "SYMBOL",
"name": "_key"
}
]
},
{
"type": "STRING",
"value": "="
},
{
"type": "SYMBOL",
"name": "_inline_value"
}
]
},
"_key": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "bare_key"
},
{
"type": "SYMBOL",
"name": "quoted_key"
}
]
},
"dotted_key": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "dotted_key"
},
{
"type": "SYMBOL",
"name": "_key"
}
]
},
{
"type": "STRING",
"value": "."
},
{
"type": "SYMBOL",
"name": "_key"
}
]
},
"bare_key": {
"type": "PATTERN",
"value": "[A-Za-z0-9_-]+"
},
"quoted_key": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_basic_string"
},
{
"type": "SYMBOL",
"name": "_literal_string"
}
]
},
"_inline_value": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "string"
},
{
"type": "SYMBOL",
"name": "integer"
},
{
"type": "SYMBOL",
"name": "float"
},
{
"type": "SYMBOL",
"name": "boolean"
},
{
"type": "SYMBOL",
"name": "offset_date_time"
},
{
"type": "SYMBOL",
"name": "local_date_time"
},
{
"type": "SYMBOL",
"name": "local_date"
},
{
"type": "SYMBOL",
"name": "local_time"
},
{
"type": "SYMBOL",
"name": "array"
},
{
"type": "SYMBOL",
"name": "inline_table"
}
]
},
"string": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_basic_string"
},
{
"type": "SYMBOL",
"name": "_multiline_basic_string"
},
{
"type": "SYMBOL",
"name": "_literal_string"
},
{
"type": "SYMBOL",
"name": "_multiline_literal_string"
}
]
},
"_basic_string": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[^\\u0000-\\u0008\\u000a-\\u001f\\u0022\\u005c\\u007f]"
}
}
},
{
"type": "SYMBOL",
"name": "escape_sequence"
}
]
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "\""
}
}
]
},
"_multiline_basic_string": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\"\"\""
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[^\\u0000-\\u0008\\u000a-\\u001f\\u0022\\u005c\\u007f]"
}
}
},
{
"type": "SYMBOL",
"name": "_multiline_basic_string_content"
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "\\r?\\n"
}
},
{
"type": "SYMBOL",
"name": "escape_sequence"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_escape_line_ending"
},
"named": true,
"value": "escape_sequence"
}
]
}
},
{
"type": "SYMBOL",
"name": "_multiline_basic_string_end"
}
]
},
"escape_sequence": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "\\\\([btnfr\"\\\\]|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})"
}
},
"_escape_line_ending": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "\\\\"
},
{
"type": "PATTERN",
"value": "\\r?\\n"
}
]
}
},
"_literal_string": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "'"
},
{
"type": "CHOICE",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[^\\u0000-\\u0008\\u000a-\\u001f\\u0027\\u007f]"
}
}
},
{
"type": "BLANK"
}
]
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "'"
}
}
]
},
"_multiline_literal_string": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "'''"
},
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "REPEAT1",
"content": {
"type": "PATTERN",
"value": "[^\\u0000-\\u0008\\u000a-\\u001f\\u0027\\u007f]"
}
}
},
{
"type": "SYMBOL",
"name": "_multiline_literal_string_content"
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "\\r?\\n"
}
}
]
}
},
{
"type": "SYMBOL",
"name": "_multiline_literal_string_end"
}
]
},
"integer": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[+-]?(0|[1-9](_?[0-9])*)"
},
{
"type": "PATTERN",
"value": "0x[0-9a-fA-F](_?[0-9a-fA-F])*"
},
{
"type": "PATTERN",
"value": "0o[0-7](_?[0-7])*"
},
{
"type": "PATTERN",
"value": "0b[01](_?[01])*"
}
]
},
"float": {
"type": "CHOICE",
"members": [
{
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[+-]?(0|[1-9](_?[0-9])*)"
},
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[.][0-9](_?[0-9])*"
},
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "[.][0-9](_?[0-9])*"
},
{
"type": "BLANK"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[eE]"
},
{
"type": "PATTERN",
"value": "[+-]?[0-9](_?[0-9])*"
}
]
}
]
}
]
}
]
}
},
{
"type": "PATTERN",
"value": "[+-]?(inf|nan)"
}
]
},
"boolean": {
"type": "PATTERN",
"value": "true|false"
},
"offset_date_time": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])"
},
{
"type": "PATTERN",
"value": "[ tT]"
},
{
"type": "PATTERN",
"value": "([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)([.][0-9]+)?"
},
{
"type": "PATTERN",
"value": "([zZ])|([+-]([01][0-9]|2[0-3]):[0-5][0-9])"
}
]
}
},
"local_date_time": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])"
},
{
"type": "PATTERN",
"value": "[ tT]"
},
{
"type": "PATTERN",
"value": "([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)([.][0-9]+)?"
}
]
}
},
"local_date": {
"type": "PATTERN",
"value": "([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])"
},
"local_time": {
"type": "PATTERN",
"value": "([01][0-9]|2[0-3]):([0-5][0-9]):([0-5][0-9]|60)([.][0-9]+)?"
},
"array": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "["
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "\\r?\\n"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_inline_value"
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "\\r?\\n"
}
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "\\r?\\n"
}
},
{
"type": "SYMBOL",
"name": "_inline_value"
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "\\r?\\n"
}
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "REPEAT",
"content": {
"type": "PATTERN",
"value": "\\r?\\n"
}
}
]
},
{
"type": "BLANK"
}
]
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "]"
}
]
},
"inline_table": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "{"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_inline_pair"
},
"named": true,
"value": "pair"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_inline_pair"
},
"named": true,
"value": "pair"
}
]
}
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "}"
}
]
}
},
"extras": [
{
"type": "SYMBOL",
"name": "comment"
},
{
"type": "PATTERN",
"value": "[ \\t]"
}
],
"conflicts": [],
"precedences": [],
"externals": [
{
"type": "SYMBOL",
"name": "_line_ending_or_eof"
},
{
"type": "SYMBOL",
"name": "_multiline_basic_string_content"
},
{
"type": "SYMBOL",
"name": "_multiline_basic_string_end"
},
{
"type": "SYMBOL",
"name": "_multiline_literal_string_content"
},
{
"type": "SYMBOL",
"name": "_multiline_literal_string_end"
}
],
"inline": [],
"supertypes": []
}

@ -1,355 +0,0 @@
[
{
"type": "array",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "array",
"named": true
},
{
"type": "boolean",
"named": true
},
{
"type": "float",
"named": true
},
{
"type": "inline_table",
"named": true
},
{
"type": "integer",
"named": true
},
{
"type": "local_date",
"named": true
},
{
"type": "local_date_time",
"named": true
},
{
"type": "local_time",
"named": true
},
{
"type": "offset_date_time",
"named": true
},
{
"type": "string",
"named": true
}
]
}
},
{
"type": "document",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "pair",
"named": true
},
{
"type": "table",
"named": true
},
{
"type": "table_array_element",
"named": true
}
]
}
},
{
"type": "dotted_key",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "bare_key",
"named": true
},
{
"type": "dotted_key",
"named": true
},
{
"type": "quoted_key",
"named": true
}
]
}
},
{
"type": "float",
"named": true,
"fields": {}
},
{
"type": "inline_table",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "pair",
"named": true
}
]
}
},
{
"type": "integer",
"named": true,
"fields": {}
},
{
"type": "pair",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "array",
"named": true
},
{
"type": "bare_key",
"named": true
},
{
"type": "boolean",
"named": true
},
{
"type": "dotted_key",
"named": true
},
{
"type": "float",
"named": true
},
{
"type": "inline_table",
"named": true
},
{
"type": "integer",
"named": true
},
{
"type": "local_date",
"named": true
},
{
"type": "local_date_time",
"named": true
},
{
"type": "local_time",
"named": true
},
{
"type": "offset_date_time",
"named": true
},
{
"type": "quoted_key",
"named": true
},
{
"type": "string",
"named": true
}
]
}
},
{
"type": "quoted_key",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "escape_sequence",
"named": true
}
]
}
},
{
"type": "string",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "escape_sequence",
"named": true
}
]
}
},
{
"type": "table",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "bare_key",
"named": true
},
{
"type": "dotted_key",
"named": true
},
{
"type": "pair",
"named": true
},
{
"type": "quoted_key",
"named": true
}
]
}
},
{
"type": "table_array_element",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "bare_key",
"named": true
},
{
"type": "dotted_key",
"named": true
},
{
"type": "pair",
"named": true
},
{
"type": "quoted_key",
"named": true
}
]
}
},
{
"type": "\"",
"named": false
},
{
"type": "\"\"\"",
"named": false
},
{
"type": "'",
"named": false
},
{
"type": "'''",
"named": false
},
{
"type": ",",
"named": false
},
{
"type": ".",
"named": false
},
{
"type": "=",
"named": false
},
{
"type": "[",
"named": false
},
{
"type": "[[",
"named": false
},
{
"type": "]",
"named": false
},
{
"type": "]]",
"named": false
},
{
"type": "bare_key",
"named": true
},
{
"type": "boolean",
"named": true
},
{
"type": "comment",
"named": true
},
{
"type": "escape_sequence",
"named": true
},
{
"type": "local_date",
"named": true
},
{
"type": "local_date_time",
"named": true
},
{
"type": "local_time",
"named": true
},
{
"type": "offset_date_time",
"named": true
},
{
"type": "{",
"named": false
},
{
"type": "}",
"named": false
}
]

File diff suppressed because it is too large Load Diff

@ -1,91 +0,0 @@
#include <tree_sitter/parser.h>
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
enum TokenType {
LINE_ENDING_OR_EOF,
MULTILINE_BASIC_STRING_CONTENT,
MULTILINE_BASIC_STRING_END,
MULTILINE_LITERAL_STRING_CONTENT,
MULTILINE_LITERAL_STRING_END,
};
void *tree_sitter_toml_external_scanner_create() { return NULL; }
void tree_sitter_toml_external_scanner_destroy(void *payload) {}
unsigned tree_sitter_toml_external_scanner_serialize(void *payload, char *buffer) { return 0; }
void tree_sitter_toml_external_scanner_deserialize(void *payload, const char *buffer, unsigned length) {}
bool tree_sitter_toml_external_scanner_scan_multiline_string_end(TSLexer *lexer, const bool *valid_symbols, int32_t delimiter, enum TokenType content_symbol, enum TokenType end_symbol) {
if (!valid_symbols[end_symbol] || lexer->lookahead != delimiter) {
return false;
}
lexer->advance(lexer, false);
lexer->mark_end(lexer);
if (lexer->lookahead != delimiter) {
lexer->result_symbol = content_symbol;
return true;
}
lexer->advance(lexer, false);
if (lexer->lookahead != delimiter) {
lexer->mark_end(lexer);
lexer->result_symbol = content_symbol;
return true;
}
lexer->advance(lexer, false);
if (lexer->lookahead != delimiter) {
lexer->mark_end(lexer);
lexer->result_symbol = end_symbol;
return true;
}
lexer->result_symbol = content_symbol;
return true;
}
bool tree_sitter_toml_external_scanner_scan(
void *payload,
TSLexer *lexer,
const bool *valid_symbols
) {
if (
tree_sitter_toml_external_scanner_scan_multiline_string_end(lexer, valid_symbols, '"', MULTILINE_BASIC_STRING_CONTENT, MULTILINE_BASIC_STRING_END)
|| tree_sitter_toml_external_scanner_scan_multiline_string_end(lexer, valid_symbols, '\'', MULTILINE_LITERAL_STRING_CONTENT, MULTILINE_LITERAL_STRING_END)
) {
return true;
}
if (valid_symbols[LINE_ENDING_OR_EOF]) {
lexer->result_symbol = LINE_ENDING_OR_EOF;
while (lexer->lookahead == ' ' || lexer->lookahead == '\t') {
lexer->advance(lexer, true);
}
if (lexer->lookahead == 0 || lexer->lookahead == '\n') {
return true;
}
if (lexer->lookahead == '\r') {
lexer->advance(lexer, true);
if (lexer->lookahead == '\n') {
return true;
}
}
}
return false;
}
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif

@ -1,223 +0,0 @@
#ifndef TREE_SITTER_PARSER_H_
#define TREE_SITTER_PARSER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#define ts_builtin_sym_error ((TSSymbol)-1)
#define ts_builtin_sym_end 0
#define TREE_SITTER_SERIALIZATION_BUFFER_SIZE 1024
typedef uint16_t TSStateId;
#ifndef TREE_SITTER_API_H_
typedef uint16_t TSSymbol;
typedef uint16_t TSFieldId;
typedef struct TSLanguage TSLanguage;
#endif
typedef struct {
TSFieldId field_id;
uint8_t child_index;
bool inherited;
} TSFieldMapEntry;
typedef struct {
uint16_t index;
uint16_t length;
} TSFieldMapSlice;
typedef struct {
bool visible;
bool named;
bool supertype;
} TSSymbolMetadata;
typedef struct TSLexer TSLexer;
struct TSLexer {
int32_t lookahead;
TSSymbol result_symbol;
void (*advance)(TSLexer *, bool);
void (*mark_end)(TSLexer *);
uint32_t (*get_column)(TSLexer *);
bool (*is_at_included_range_start)(const TSLexer *);
bool (*eof)(const TSLexer *);
};
typedef enum {
TSParseActionTypeShift,
TSParseActionTypeReduce,
TSParseActionTypeAccept,
TSParseActionTypeRecover,
} TSParseActionType;
typedef union {
struct {
uint8_t type;
TSStateId state;
bool extra;
bool repetition;
} shift;
struct {
uint8_t type;
uint8_t child_count;
TSSymbol symbol;
int16_t dynamic_precedence;
uint16_t production_id;
} reduce;
uint8_t type;
} TSParseAction;
typedef struct {
uint16_t lex_state;
uint16_t external_lex_state;
} TSLexMode;
typedef union {
TSParseAction action;
struct {
uint8_t count;
bool reusable;
} entry;
} TSParseActionEntry;
struct TSLanguage {
uint32_t version;
uint32_t symbol_count;
uint32_t alias_count;
uint32_t token_count;
uint32_t external_token_count;
uint32_t state_count;
uint32_t large_state_count;
uint32_t production_id_count;
uint32_t field_count;
uint16_t max_alias_sequence_length;
const uint16_t *parse_table;
const uint16_t *small_parse_table;
const uint32_t *small_parse_table_map;
const TSParseActionEntry *parse_actions;
const char **symbol_names;
const char **field_names;
const TSFieldMapSlice *field_map_slices;
const TSFieldMapEntry *field_map_entries;
const TSSymbolMetadata *symbol_metadata;
const TSSymbol *public_symbol_map;
const uint16_t *alias_map;
const TSSymbol *alias_sequences;
const TSLexMode *lex_modes;
bool (*lex_fn)(TSLexer *, TSStateId);
bool (*keyword_lex_fn)(TSLexer *, TSStateId);
TSSymbol keyword_capture_token;
struct {
const bool *states;
const TSSymbol *symbol_map;
void *(*create)(void);
void (*destroy)(void *);
bool (*scan)(void *, TSLexer *, const bool *symbol_whitelist);
unsigned (*serialize)(void *, char *);
void (*deserialize)(void *, const char *, unsigned);
} external_scanner;
};
/*
* Lexer Macros
*/
#define START_LEXER() \
bool result = false; \
bool skip = false; \
bool eof = false; \
int32_t lookahead; \
goto start; \
next_state: \
lexer->advance(lexer, skip); \
start: \
skip = false; \
lookahead = lexer->lookahead;
#define ADVANCE(state_value) \
{ \
state = state_value; \
goto next_state; \
}
#define SKIP(state_value) \
{ \
skip = true; \
state = state_value; \
goto next_state; \
}
#define ACCEPT_TOKEN(symbol_value) \
result = true; \
lexer->result_symbol = symbol_value; \
lexer->mark_end(lexer);
#define END_STATE() return result;
/*
* Parse Table Macros
*/
#define SMALL_STATE(id) id - LARGE_STATE_COUNT
#define STATE(id) id
#define ACTIONS(id) id
#define SHIFT(state_value) \
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = state_value \
} \
}}
#define SHIFT_REPEAT(state_value) \
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.state = state_value, \
.repetition = true \
} \
}}
#define SHIFT_EXTRA() \
{{ \
.shift = { \
.type = TSParseActionTypeShift, \
.extra = true \
} \
}}
#define REDUCE(symbol_val, child_count_val, ...) \
{{ \
.reduce = { \
.type = TSParseActionTypeReduce, \
.symbol = symbol_val, \
.child_count = child_count_val, \
__VA_ARGS__ \
}, \
}}
#define RECOVER() \
{{ \
.type = TSParseActionTypeRecover \
}}
#define ACCEPT_INPUT() \
{{ \
.type = TSParseActionTypeAccept \
}}
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_PARSER_H_

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff