-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6efe4d4
Showing
36 changed files
with
13,593 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module.exports = { | ||
'env': { | ||
'commonjs': true, | ||
'es2021': true, | ||
'node': true, | ||
}, | ||
'extends': 'google', | ||
'overrides': [ | ||
{ | ||
'env': { | ||
'node': true, | ||
}, | ||
'files': [ | ||
'.eslintrc.{js,cjs}', | ||
], | ||
'parserOptions': { | ||
'sourceType': 'script', | ||
}, | ||
}, | ||
], | ||
'parserOptions': { | ||
'ecmaVersion': 'latest', | ||
'sourceType': 'module', | ||
}, | ||
'rules': { | ||
'indent': ['error', 2, {'SwitchCase': 1}], | ||
'max-len': [ | ||
'error', | ||
{'code': 120, 'ignoreComments': true, 'ignoreUrls': true, 'ignoreStrings': true}, | ||
], | ||
'arrow-parens': 'off', | ||
'camelcase': 'off', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/src/** linguist-vendored | ||
/examples/* linguist-vendored | ||
|
||
src/grammar.json linguist-generated | ||
src/node-types.json linguist-generated | ||
src/parser.c linguist-generated | ||
|
||
src/grammar.json -diff | ||
src/node-types.json -diff | ||
src/parser.c -diff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
github: amaanq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Test grammar | ||
|
||
on: | ||
push: | ||
branches: ["*"] | ||
paths: | ||
- grammar.js | ||
- src/** | ||
- bindings/** | ||
- binding.gyp | ||
pull_request: | ||
branches: ["*"] | ||
paths: | ||
- grammar.js | ||
- src/** | ||
- bindings/** | ||
- binding.gyp | ||
|
||
jobs: | ||
test: | ||
uses: tree-sitter-grammars/.github/.github/workflows/ci.yml@main | ||
with: | ||
test-library: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: Update dependencies | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * 0' | ||
|
||
jobs: | ||
test: | ||
uses: tree-sitter-grammars/.github/.github/workflows/dependencies.yml@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name: Fuzz scanner | ||
|
||
on: | ||
push: | ||
branches: ["*"] | ||
paths: | ||
- src/scanner.c | ||
pull_request: | ||
branches: ["*"] | ||
paths: | ||
- src/scanner.c | ||
|
||
jobs: | ||
test: | ||
uses: tree-sitter-grammars/.github/.github/workflows/fuzz.yml@main | ||
with: | ||
language: svelte |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: Lint grammar | ||
|
||
on: | ||
push: | ||
branches: ["*"] | ||
paths: | ||
- grammar.js | ||
pull_request: | ||
branches: ["*"] | ||
paths: | ||
- grammar.js | ||
|
||
jobs: | ||
test: | ||
uses: tree-sitter-grammars/.github/.github/workflows/lint.yml@main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Cargo.lock | ||
node_modules | ||
build | ||
package-lock.json | ||
/target/ | ||
.build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/test | ||
/examples | ||
/build | ||
/script | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[package] | ||
name = "tree-sitter-svelte" | ||
description = "Svelte grammar for tree-sitter" | ||
version = "0.0.1" | ||
authors = ["Amaan Qureshi <[email protected]>"] | ||
license = "MIT" | ||
readme = "bindings/rust/README.md" | ||
keywords = ["incremental", "parsing", "svelte"] | ||
categories = ["parsing", "text-editors"] | ||
repository = "https://github.com/tree-sitter-grammars/tree-sitter-svelte" | ||
edition = "2021" | ||
autoexamples = false | ||
|
||
build = "bindings/rust/build.rs" | ||
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"] | ||
|
||
[lib] | ||
path = "bindings/rust/lib.rs" | ||
|
||
[dependencies] | ||
tree-sitter = "~0.20.10" | ||
|
||
[build-dependencies] | ||
cc = "1.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 Amaan Qureshi <[email protected]> | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// swift-tools-version:5.3 | ||
import PackageDescription | ||
|
||
let package = Package( | ||
name: "TreeSitterSvelte", | ||
platforms: [.macOS(.v10_13), .iOS(.v11)], | ||
products: [ | ||
.library(name: "TreeSitterSvelte", targets: ["TreeSitterSvelte"]), | ||
], | ||
dependencies: [], | ||
targets: [ | ||
.target(name: "TreeSitterSvelte", | ||
path: ".", | ||
exclude: [ | ||
"binding.gyp", | ||
"bindings", | ||
"Cargo.toml", | ||
"test", | ||
"grammar.js", | ||
"LICENSE", | ||
"package.json", | ||
"README.md", | ||
"script", | ||
"src/grammar.json", | ||
"src/node-types.json", | ||
], | ||
sources: [ | ||
"src/parser.c", | ||
"src/scanner.c", | ||
], | ||
resources: [ | ||
.copy("queries") | ||
], | ||
publicHeadersPath: "bindings/swift", | ||
cSettings: [.headerSearchPath("src")]) | ||
] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# tree-sitter-svelte | ||
|
||
[![CI][ci]](https://github.com/tree-sitter-grammars/tree-sitter-svelte/actions/workflows/ci.yml) | ||
[![discord][discord]](https://discord.gg/w7nTvsVJhm) | ||
[![matrix][matrix]](https://matrix.to/#/#tree-sitter-chat:matrix.org) | ||
|
||
[Svelte](https://svelte.dev/) grammar for [tree-sitter](https://tree-sitter.github.io) | ||
|
||
[ci]: https://img.shields.io/github/actions/workflow/status/tree-sitter-grammars/tree-sitter-svelte/ci.yml?logo=github&label=CI | ||
[discord]: https://img.shields.io/discord/1063097320771698699?logo=discord&label=discord | ||
[matrix]: https://img.shields.io/matrix/tree-sitter-chat%3Amatrix.org?logo=matrix&label=matrix |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "tree_sitter_svelte_binding", | ||
"include_dirs": [ | ||
"<!(node -e \"require('nan')\")", | ||
"src" | ||
], | ||
"sources": [ | ||
"bindings/node/binding.cc", | ||
"src/parser.c", | ||
"src/scanner.c", | ||
], | ||
"cflags_c": [ | ||
"-std=c99", | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "tree_sitter/parser.h" | ||
#include <node.h> | ||
#include "nan.h" | ||
|
||
using namespace v8; | ||
|
||
extern "C" TSLanguage * tree_sitter_svelte(); | ||
|
||
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_svelte()); | ||
|
||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("svelte").ToLocalChecked()); | ||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); | ||
} | ||
|
||
NODE_MODULE(tree_sitter_svelte_binding, Init) | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
try { | ||
module.exports = require("../../build/Release/tree_sitter_svelte_binding"); | ||
} catch (error1) { | ||
if (error1.code !== 'MODULE_NOT_FOUND') { | ||
throw error1; | ||
} | ||
try { | ||
module.exports = require("../../build/Debug/tree_sitter_svelte_binding"); | ||
} catch (error2) { | ||
if (error2.code !== 'MODULE_NOT_FOUND') { | ||
throw error2; | ||
} | ||
throw error1 | ||
} | ||
} | ||
|
||
try { | ||
module.exports.nodeTypeInfo = require("../../src/node-types.json"); | ||
} catch (_) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# tree-sitter-svelte | ||
|
||
This crate provides an Svelte grammar for the [tree-sitter][] parsing library. To | ||
use this crate, add it to the `[dependencies]` section of your `Cargo.toml` | ||
file. (Note that you will probably also need to depend on the | ||
[`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful | ||
way.) | ||
|
||
```toml | ||
[dependencies] | ||
tree-sitter = "~0.20.10" | ||
tree-sitter-svelte = "0.0.1" | ||
``` | ||
|
||
Typically, you will use the [language][language func] function to add this | ||
grammar to a tree-sitter [Parser][], and then use the parser to parse some code: | ||
|
||
```rust | ||
let code = r#" | ||
<script> | ||
let count = 0; | ||
function handleClick() { | ||
count += 1; | ||
} | ||
</script> | ||
"#; | ||
let mut parser = Parser::new(); | ||
parser.set_language(tree_sitter_svelte::language()).expect("Error loading Svelte grammar"); | ||
let parsed = parser.parse(code, None); | ||
``` | ||
|
||
If you have any questions, please reach out to us in the [tree-sitter | ||
discussions] page. | ||
|
||
[language func]: https://docs.rs/tree-sitter-svelte/*/tree_sitter_svelte/fn.language.html | ||
[parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html | ||
[tree-sitter]: https://tree-sitter.github.io/ | ||
[tree-sitter crate]: https://crates.io/crates/tree-sitter | ||
[tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
fn main() { | ||
let src_dir = std::path::Path::new("src"); | ||
|
||
let mut c_config = cc::Build::new(); | ||
c_config.include(src_dir); | ||
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.join("parser.c"); | ||
c_config.file(&parser_path); | ||
|
||
let scanner_path = src_dir.join("scanner.c"); | ||
c_config.file(&scanner_path); | ||
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); | ||
|
||
c_config.compile("parser"); | ||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); | ||
} |
Oops, something went wrong.