Skip to content

Commit 7e4bfb9

Browse files
Run workflow
1 parent d3aea43 commit 7e4bfb9

16 files changed

Lines changed: 37614 additions & 350 deletions

File tree

Cargo.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "tree-sitter-multilingual"
3+
description = "multilingual grammar for the tree-sitter parsing library"
4+
version = "0.0.1"
5+
keywords = ["incremental", "parsing", "multilingual"]
6+
categories = ["parsing", "text-editors"]
7+
repository = "https://github.com/tree-sitter/tree-sitter-multilingual"
8+
edition = "2018"
9+
license = "MIT"
10+
11+
build = "bindings/rust/build.rs"
12+
include = [
13+
"bindings/rust/*",
14+
"grammar.js",
15+
"queries/*",
16+
"src/*",
17+
]
18+
19+
[lib]
20+
path = "bindings/rust/lib.rs"
21+
22+
[dependencies]
23+
tree-sitter = "~0.20.10"
24+
25+
[build-dependencies]
26+
cc = "1.0"

Makefile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
.PHONY: all generate build test inject tmgrammar monarch validate clean help
22

33
# Variables
4-
PYTHON := python3
5-
TREE_SITTER := npx tree-sitter
6-
SHELL := /bin/bash
4+
PYTHON := python -X utf8
5+
TREE_SITTER := node_modules/tree-sitter-cli/tree-sitter.exe
76

87
help:
98
@echo "Tree-sitter Multilingual Grammar - Available Targets"
@@ -34,7 +33,7 @@ generate: inject
3433
# Build the native module
3534
build: generate
3635
@echo "Building native module..."
37-
@node-gyp build
36+
@npx node-gyp rebuild
3837
@echo "✓ Native module built"
3938

4039
# Run tests

binding.gyp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
{
44
"target_name": "tree_sitter_multilingual_binding",
55
"include_dirs": [
6-
"<!(node -e \"const binding = require('@mapbox/node-pre-gyp'); const obj = JSON.parse(require('fs').readFileSync('package.json')); process.stdout.write(require('path').join(binding.find(obj.binary.module_path, obj.binary)))\") ",
7-
"<!(node -e \"const ts = require('tree-sitter'); process.stdout.write(ts.includePath)\")"
6+
"src"
87
],
98
"sources": [
9+
"bindings/node/binding.cc",
1010
"src/parser.c",
1111
"src/scanner.c"
1212
],

bindings/node/binding.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "tree_sitter/parser.h"
2+
#include <node.h>
3+
4+
using namespace v8;
5+
6+
extern "C" TSLanguage *tree_sitter_multilingual();
7+
8+
namespace {
9+
10+
void Language(const FunctionCallbackInfo<Value> &info) {
11+
info.GetReturnValue().Set(
12+
External::New(info.GetIsolate(), tree_sitter_multilingual()));
13+
}
14+
15+
void Init(Local<Object> exports, Local<Object> module) {
16+
Isolate *isolate = exports->GetIsolate();
17+
Local<Context> context = exports->GetCreationContext().ToLocalChecked();
18+
19+
Local<FunctionTemplate> language = FunctionTemplate::New(isolate, Language);
20+
Local<Function> language_fn = language->GetFunction(context).ToLocalChecked();
21+
Local<String> name =
22+
String::NewFromUtf8(isolate, "language", NewStringType::kNormal)
23+
.ToLocalChecked();
24+
25+
language_fn->SetName(name);
26+
exports->Set(context, name, language_fn).FromJust();
27+
}
28+
29+
NODE_MODULE(tree_sitter_multilingual_binding, Init)
30+
31+
} // namespace

bindings/node/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
try {
2+
module.exports = require("../../build/Release/tree_sitter_multilingual_binding");
3+
} catch (error1) {
4+
if (error1.code !== 'MODULE_NOT_FOUND') {
5+
throw error1;
6+
}
7+
try {
8+
module.exports = require("../../build/Debug/tree_sitter_multilingual_binding");
9+
} catch (error2) {
10+
if (error2.code !== 'MODULE_NOT_FOUND') {
11+
throw error2;
12+
}
13+
throw error1
14+
}
15+
}
16+
17+
try {
18+
module.exports.nodeTypeInfo = require("../../src/node-types.json");
19+
} catch (_) {}

bindings/rust/build.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
fn main() {
2+
let src_dir = std::path::Path::new("src");
3+
4+
let mut c_config = cc::Build::new();
5+
c_config.include(&src_dir);
6+
c_config
7+
.flag_if_supported("-Wno-unused-parameter")
8+
.flag_if_supported("-Wno-unused-but-set-variable")
9+
.flag_if_supported("-Wno-trigraphs");
10+
let parser_path = src_dir.join("parser.c");
11+
c_config.file(&parser_path);
12+
13+
// If your language uses an external scanner written in C,
14+
// then include this block of code:
15+
16+
/*
17+
let scanner_path = src_dir.join("scanner.c");
18+
c_config.file(&scanner_path);
19+
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
20+
*/
21+
22+
c_config.compile("parser");
23+
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());
24+
25+
// If your language uses an external scanner written in C++,
26+
// then include this block of code:
27+
28+
/*
29+
let mut cpp_config = cc::Build::new();
30+
cpp_config.cpp(true);
31+
cpp_config.include(&src_dir);
32+
cpp_config
33+
.flag_if_supported("-Wno-unused-parameter")
34+
.flag_if_supported("-Wno-unused-but-set-variable");
35+
let scanner_path = src_dir.join("scanner.cc");
36+
cpp_config.file(&scanner_path);
37+
cpp_config.compile("scanner");
38+
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
39+
*/
40+
}

bindings/rust/lib.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//! This crate provides multilingual language support for the [tree-sitter][] parsing library.
2+
//!
3+
//! Typically, you will use the [language][language func] function to add this language to a
4+
//! tree-sitter [Parser][], and then use the parser to parse some code:
5+
//!
6+
//! ```
7+
//! let code = "";
8+
//! let mut parser = tree_sitter::Parser::new();
9+
//! parser.set_language(tree_sitter_multilingual::language()).expect("Error loading multilingual grammar");
10+
//! let tree = parser.parse(code, None).unwrap();
11+
//! ```
12+
//!
13+
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
14+
//! [language func]: fn.language.html
15+
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
16+
//! [tree-sitter]: https://tree-sitter.github.io/
17+
18+
use tree_sitter::Language;
19+
20+
extern "C" {
21+
fn tree_sitter_multilingual() -> Language;
22+
}
23+
24+
/// Get the tree-sitter [Language][] for this grammar.
25+
///
26+
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
27+
pub fn language() -> Language {
28+
unsafe { tree_sitter_multilingual() }
29+
}
30+
31+
/// The content of the [`node-types.json`][] file for this grammar.
32+
///
33+
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
34+
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
35+
36+
// Uncomment these to include any queries that this grammar contains
37+
38+
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
39+
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
40+
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
41+
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
42+
43+
#[cfg(test)]
44+
mod tests {
45+
#[test]
46+
fn test_can_load_grammar() {
47+
let mut parser = tree_sitter::Parser::new();
48+
parser
49+
.set_language(super::language())
50+
.expect("Error loading multilingual language");
51+
}
52+
}

data/keywords.yaml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,3 +1563,69 @@ constructs:
15631563
sv: delegera
15641564
da: delegere
15651565
fi: valtuuta
1566+
1567+
range:
1568+
en: range
1569+
fr: gamme
1570+
de: bereich
1571+
ja: 範囲
1572+
ar: نطاق
1573+
hi: श्रृंखला
1574+
es: rango
1575+
pt: intervalo
1576+
zh: 范围
1577+
ko: 범위
1578+
it: intervallo
1579+
nl: bereik
1580+
pl: zakres
1581+
ru: диапазон
1582+
tr: aralık
1583+
bn: পরিসীমা
1584+
ta: வரம்பு
1585+
sv: omfång
1586+
da: område
1587+
fi: alue
1588+
1589+
len:
1590+
en: len
1591+
fr: longueur
1592+
de: länge
1593+
ja: 長さ
1594+
ar: طول
1595+
hi: लंबाई
1596+
es: longitud
1597+
pt: comprimento
1598+
zh: 长度
1599+
ko: 길이
1600+
it: lunghezza
1601+
nl: lengte
1602+
pl: długość
1603+
ru: длина
1604+
tr: uzunluk
1605+
bn: দৈর্ঘ্য
1606+
ta: நீளம்
1607+
sv: längd
1608+
da: længde
1609+
fi: pituus
1610+
1611+
type:
1612+
en: type
1613+
fr: type
1614+
de: typ
1615+
ja:
1616+
ar: نوع
1617+
hi: प्रकार
1618+
es: tipo
1619+
pt: tipo
1620+
zh: 类型
1621+
ko: 타입
1622+
it: tipo
1623+
nl: type
1624+
pl: typ
1625+
ru: тип
1626+
tr: tür
1627+
bn: ধরন
1628+
ta: வகை
1629+
sv: typ
1630+
da: type
1631+
fi: tyyppi

0 commit comments

Comments
 (0)