Skip to content

Commit

Permalink
Add 'vendor/tree-sitter-markdown/' from commit 'e375ba95ff9a12418f9b9…
Browse files Browse the repository at this point in the history
…e7c190f549d08b5380a'

git-subtree-dir: vendor/tree-sitter-markdown
git-subtree-mainline: 662b837
git-subtree-split: e375ba9
  • Loading branch information
gurjeet committed Sep 20, 2022
2 parents 662b837 + e375ba9 commit 9cacf84
Show file tree
Hide file tree
Showing 45 changed files with 158,939 additions and 0 deletions.
20 changes: 20 additions & 0 deletions vendor/tree-sitter-markdown/.github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: bug
assignees: ''

---

**Describe the bug**

**Code example**
```markdown
Your example here
```

**Expected behavior**
<!-- consider linking to a relevant section in a spec like https://github.github.com/gfm/ -->

**Actual behavior**
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement
assignees: ''

---

<!-- consider linking a relevant section from a spec -->
<!-- extensions from any spec (rmarkdown, pandoc, ...) are welcome -->
28 changes: 28 additions & 0 deletions vendor/tree-sitter-markdown/.github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ "split_parser" ]
pull_request:
branches: [ "split_parser" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Use Node.js 14
uses: actions/setup-node@v3
with:
node-version: 14
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- name: Check grammar is compiled correctly
run: git diff --exit-code
- run: npm test
3 changes: 3 additions & 0 deletions vendor/tree-sitter-markdown/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
build
target
70 changes: 70 additions & 0 deletions vendor/tree-sitter-markdown/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# Contributing

All contributions are welcome. Specifically, if you found a bug or have a
suggestion for a new feature or markdown extension, you can always open an
[issue] or [pull request].

## Issues

If you open an issue please give a short description of your bug or feature
along with a code example. If there is a relevant spec like the [CommonMark
Spec][commonmark] or the [GitHub Flavored Markdown Spec][gfm] please link it in
the issue.

Any feature suggestions are welcome. The grammar should by default only support
very common syntax, but any extension can be implemented behind a compile time
flag. (See below)

Some bug reports belong in other repositories if they only concern the
implementation of the grammar in a specific context like `nvim-treesitter`, but
you can always open an issue here and I will point you in the right direction.

## Code Overview

Please refer to the [tree-sitter spec] for more details on how to write a tree-
sitter grammar.

This parse is split into two grammars. One for block structure, which can be
found in the `tree-sitter-markdown` folder, and one for inline structure, which
can be found in the `tree-sitter-markdown-inline` folder. Components that are
parts of either grammar can be found in the `common` folder.

For either of the grammar the most important files are the `grammar.js` which
defines most nodes and the `src/scanner.cc` which defines nodes that cannot
be parsed with normal tree-sitter rules. All other files in the `src` subfolder
are auto-generated by running `tree-sitter generate --no-bindings`. (You need to
install the [tree-sitter cli tool][tree-sitter-cli] first.)

Some syntactical components can be enabled or disabled by environment variables
at compile time. The logic for this can be found in the `common/grammar.js`
file.

Tests are located in the `corpus` subfolder:
* `spec.txt` is taken from the examples in the [GFM spec][gfm].
* `failing.txt` are those examples from the spec that do not pass yet.
* `issues.txt` are test cases covering solved issues.
* `extension_<>.txt` are covering specific extensions. Some of these are also
taken from the GFM spec.

## Pull Requests

I will happily accept any pull requests.

Before submitting any code please check the following:

* You ran `tree-sitter generate --no-bindings` in the `tree-sitter-markdown` or
`tree-sitter-markdown-inline` directories respecively after modifying any
`grammar.js` file.
* When running `tree-sitter test` only the cases defined in `failing.txt` or
`extension_<>.txt` for not activated extensions fail for **both** gramars.
* If you implemented new behavior please add tests. (In most cases these belong
in a `extension_<>.txt`.)
* You deleted any auto-generated bindings and files for debugging purposes
like `log.html`

[issue]: https://github.com/MDeiml/tree-sitter-markdown/issues/new
[pull request]: https://github.com/MDeiml/tree-sitter-markdown/compare
[gfm]: https://github.github.com/gfm/
[commonmark]: https://spec.commonmark.org/
[tree-sitter spec]: https://tree-sitter.github.io/tree-sitter/
[tree-sitter-cli]: https://github.com/tree-sitter/tree-sitter/blob/master/cli/README.md
35 changes: 35 additions & 0 deletions vendor/tree-sitter-markdown/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
[package]
name = "tree-sitter-md"
description = "markdown grammar for the tree-sitter parsing library"
version = "0.1.1"
keywords = ["incremental", "parsing", "markdown"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/MDeiml/tree-sitter-markdown"
edition = "2018"
license = "MIT"

build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"tree-sitter-markdown/src/*",
"tree-sitter-markdown-inline/src/*",
"tree-sitter-markdown/queries/*",
"tree-sitter-markdown-inline/queries/*",
"benchmark/main.rs",
]

[lib]
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = "~0.20"

[build-dependencies]
cc = "1.0"

[[bin]]
name = "benchmark"
path = "benchmark/main.rs"

[profile.release]
debug = true
21 changes: 21 additions & 0 deletions vendor/tree-sitter-markdown/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Matthias Deiml

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.
16 changes: 16 additions & 0 deletions vendor/tree-sitter-markdown/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# tree-sitter-markdown
A markdown parser for tree-sitter

For now this implements the [CommonMark Spec](https://spec.commonmark.org/). Maybe it will be extended to support [Github flavored markdown](https://github.github.com/gfm/)

## Structure

The parser is spit into two grammars. One for the [block structure](https://spec.commonmark.org/0.30/#blocks-and-inlines) which can be found in `/tree-sitter-markdown` and one for the [inline structure](https://spec.commonmark.org/0.30/#inlines) which is in `/tree-sitter-markdown-inline`.
Because of this the entire document has to be scanned twice in order to be fully parsed.
This is motivated by the [parsing strategy section](https://spec.commonmark.org/0.30/#appendix-a-parsing-strategy) of the CommonMark Spec which suggests doing exactly this: Parsing the document twice, first determining the block structure and then parsing any inline content.

It also helps managing complexity, which was a problem with earlier versions of this parser, by allowing block and inline structure to be considered seperately. This was not the case as tree-sitters dynamic precedence can create hard to predict effects.

## Usage

To use the two grammars, first parse the document with the block grammar. Then perform a second parse with the inline grammar using `ts_parser_set_included_ranges` to specify which parts are inline content. These parts are marked as `inline` nodes. Children of those inline nodes should be excluded from these ranges. For an example implementation see `lib.rs` in the `bindings` folder.
21 changes: 21 additions & 0 deletions vendor/tree-sitter-markdown/benchmark/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use tree_sitter_md::*;

fn main() {
let mut parser = MarkdownParser::default();
let filename = std::env::args().nth(1).unwrap();
let source = std::fs::read(filename).unwrap();
let mut tree = parser.parse(&source, None).unwrap();
tree.edit(&tree_sitter::InputEdit {
start_byte: 0,
old_end_byte: 1,
new_end_byte: 0,
start_position: tree_sitter::Point::new(0, 0),
old_end_position: tree_sitter::Point::new(0, 1),
new_end_position: tree_sitter::Point::new(0, 0),
});
reparse(&mut parser, &source[1..], tree);
}

fn reparse(parser: &mut MarkdownParser, source: &[u8], old_tree: MarkdownTree) {
parser.parse(source, Some(&old_tree));
}
23 changes: 23 additions & 0 deletions vendor/tree-sitter-markdown/binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"targets": [
{
"target_name": "tree_sitter_markdown_binding",
"include_dirs": [
"<!(node -e \"require('nan')\")",
"tree-sitter-markdown/src",
"tree-sitter-markdown-inline/src",
],
"sources": [
"tree-sitter-markdown/src/parser.c",
"tree-sitter-markdown/src/scanner.cc",
"tree-sitter-markdown-inline/src/parser.c",
"tree-sitter-markdown-inline/src/scanner.cc",
"bindings/node/binding.cc"
],
"cflags_c": [
"-std=c99"
]
}
]
}

35 changes: 35 additions & 0 deletions vendor/tree-sitter-markdown/bindings/node/binding.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"

using namespace v8;

extern "C" TSLanguage * tree_sitter_markdown();
extern "C" TSLanguage * tree_sitter_markdown_inline();

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_block = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance_block, 0, tree_sitter_markdown());
Nan::Set(instance_block, Nan::New("name").ToLocalChecked(), Nan::New("markdown").ToLocalChecked());
Nan::Set(exports, Nan::New("markdown").ToLocalChecked(), instance_block);

Local<Object> instance_inline = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance_inline, 0, tree_sitter_markdown_inline());
Nan::Set(instance_inline, Nan::New("name").ToLocalChecked(), Nan::New("markdown_inline").ToLocalChecked());
Nan::Set(exports, Nan::New("markdown_inline").ToLocalChecked(), instance_inline);
}

NODE_MODULE(tree_sitter_markdown_binding, Init)

} // namespace

21 changes: 21 additions & 0 deletions vendor/tree-sitter-markdown/bindings/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
try {
module.exports = require("../../build/Release/tree_sitter_markdown_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_markdown_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
}

try {
module.exports.nodeTypeInfo = require("../../tree-sitter-markdown/src/node-types.json");
module.exports.nodeTypeInfoInline = require("../../tree-sitter-markdown-inline/src/node-types.json");
} catch (_) {}

48 changes: 48 additions & 0 deletions vendor/tree-sitter-markdown/bindings/rust/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
fn main() {
let src_dir_block = std::path::Path::new("tree-sitter-markdown/src");
let src_dir_inline = std::path::Path::new("tree-sitter-markdown-inline/src");

let mut c_config = cc::Build::new();
c_config.include(&src_dir_block);
c_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
let parser_path = src_dir_block.join("parser.c");
c_config.file(&parser_path);
c_config.compile("parser_block");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());

let mut c_config = cc::Build::new();
c_config.include(&src_dir_inline);
c_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable")
.flag_if_supported("-Wno-trigraphs");
let parser_path = src_dir_inline.join("parser.c");
c_config.file(&parser_path);
c_config.compile("parser_inline");
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());

let mut cpp_config = cc::Build::new();
cpp_config.cpp(true);
cpp_config.include(&src_dir_block);
cpp_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir_block.join("scanner.cc");
cpp_config.file(&scanner_path);
cpp_config.compile("scanner_block");
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());

let mut cpp_config = cc::Build::new();
cpp_config.cpp(true);
cpp_config.include(&src_dir_inline);
cpp_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir_inline.join("scanner.cc");
cpp_config.file(&scanner_path);
cpp_config.compile("scanner_inline");
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
}
Loading

0 comments on commit 9cacf84

Please sign in to comment.