Compare commits
No commits in common. "07bd2dbdfa7f5d140e7b54cd9f5484220eaa2d40" and "fbbeaf4a9e5b7d415abb167edb76e1607c4f4185" have entirely different histories.
07bd2dbdfa
...
fbbeaf4a9e
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,2 @@
|
|||||||
build/
|
|
||||||
node_modules/
|
node_modules/
|
||||||
target/
|
target/
|
||||||
|
4968
Cargo.lock
generated
4968
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
11
Cargo.toml
11
Cargo.toml
@ -8,7 +8,7 @@ repository = "https://github.com/tree-sitter/tree-sitter-dust"
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
||||||
build = "runtime/build.rs"
|
build = "bindings/rust/build.rs"
|
||||||
include = [
|
include = [
|
||||||
"bindings/rust/*",
|
"bindings/rust/*",
|
||||||
"grammar.js",
|
"grammar.js",
|
||||||
@ -16,17 +16,10 @@ include = [
|
|||||||
"src/*",
|
"src/*",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "main"
|
|
||||||
path = "runtime/main.rs"
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "runtime/lib.rs"
|
path = "bindings/rust/lib.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
clap = "4.4.4"
|
|
||||||
dust-lang = "0.1.2"
|
|
||||||
rustyline = "12.0.0"
|
|
||||||
tree-sitter = "~0.20.10"
|
tree-sitter = "~0.20.10"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
28
bindings/node/binding.cc
Normal file
28
bindings/node/binding.cc
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "tree_sitter/parser.h"
|
||||||
|
#include <node.h>
|
||||||
|
#include "nan.h"
|
||||||
|
|
||||||
|
using namespace v8;
|
||||||
|
|
||||||
|
extern "C" TSLanguage * tree_sitter_Dust();
|
||||||
|
|
||||||
|
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_Dust());
|
||||||
|
|
||||||
|
Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("Dust").ToLocalChecked());
|
||||||
|
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
NODE_MODULE(tree_sitter_Dust_binding, Init)
|
||||||
|
|
||||||
|
} // namespace
|
19
bindings/node/index.js
Normal file
19
bindings/node/index.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
try {
|
||||||
|
module.exports = require("../../build/Release/tree_sitter_Dust_binding");
|
||||||
|
} catch (error1) {
|
||||||
|
if (error1.code !== 'MODULE_NOT_FOUND') {
|
||||||
|
throw error1;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
module.exports = require("../../build/Debug/tree_sitter_Dust_binding");
|
||||||
|
} catch (error2) {
|
||||||
|
if (error2.code !== 'MODULE_NOT_FOUND') {
|
||||||
|
throw error2;
|
||||||
|
}
|
||||||
|
throw error1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
module.exports.nodeTypeInfo = require("../../src/node-types.json");
|
||||||
|
} catch (_) {}
|
@ -15,39 +15,23 @@
|
|||||||
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
||||||
//! [tree-sitter]: https://tree-sitter.github.io/
|
//! [tree-sitter]: https://tree-sitter.github.io/
|
||||||
|
|
||||||
use tree_sitter::{Language, Node};
|
use tree_sitter::Language;
|
||||||
use dust_lib::Value;
|
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
fn tree_sitter_dust() -> Language;
|
fn tree_sitter_Dust() -> Language;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the tree-sitter [Language][] for this grammar.
|
/// Get the tree-sitter [Language][] for this grammar.
|
||||||
///
|
///
|
||||||
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
||||||
pub fn language() -> Language {
|
pub fn language() -> Language {
|
||||||
unsafe { tree_sitter_dust() }
|
unsafe { tree_sitter_Dust() }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The content of the [`node-types.json`][] file for this grammar.
|
/// The content of the [`node-types.json`][] file for this grammar.
|
||||||
///
|
///
|
||||||
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
||||||
pub const NODE_TYPES: &'static str = include_str!("../src/node-types.json");
|
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
|
||||||
|
|
||||||
pub fn evaluate(root: Node) -> Value {
|
|
||||||
let cursor = root.walk();
|
|
||||||
|
|
||||||
|
|
||||||
if let Some(name) = cursor.field_name() {
|
|
||||||
match name {
|
|
||||||
"source" => Value::Empty,
|
|
||||||
_ => Value::Empty,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Uncomment these to include any queries that this grammar contains
|
// Uncomment these to include any queries that this grammar contains
|
||||||
|
|
8
package-lock.json
generated
8
package-lock.json
generated
@ -9,16 +9,16 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nan": "^2.18.0"
|
"nan": "^2.17.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tree-sitter-cli": "^0.20.8"
|
"tree-sitter-cli": "^0.20.8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/nan": {
|
"node_modules/nan": {
|
||||||
"version": "2.18.0",
|
"version": "2.17.0",
|
||||||
"resolved": "https://registry.npmjs.org/nan/-/nan-2.18.0.tgz",
|
"resolved": "https://registry.npmjs.org/nan/-/nan-2.17.0.tgz",
|
||||||
"integrity": "sha512-W7tfG7vMOGtD30sHoZSSc/JVYiyDPEyQVso/Zz+/uQd0B0L46gtC+pHha5FFMRpil6fm/AoEcRWyOVi4+E/f8w=="
|
"integrity": "sha512-2ZTgtl0nJsO0KQCjEpxcIr5D+Yv90plTitZt9JBfQvVJDS5seMl3FOvsh3+9CoYWXf/1l5OaZzzF6nDm4cagaQ=="
|
||||||
},
|
},
|
||||||
"node_modules/tree-sitter-cli": {
|
"node_modules/tree-sitter-cli": {
|
||||||
"version": "0.20.8",
|
"version": "0.20.8",
|
||||||
|
@ -19,7 +19,7 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"nan": "^2.18.0"
|
"nan": "^2.17.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"tree-sitter-cli": "^0.20.8"
|
"tree-sitter-cli": "^0.20.8"
|
||||||
|
@ -1,38 +0,0 @@
|
|||||||
//! Command line interface for the dust programming language.
|
|
||||||
use clap::Parser;
|
|
||||||
use std::fs::read_to_string;
|
|
||||||
use tree_sitter::{Parser as TSParser, Language};
|
|
||||||
|
|
||||||
/// Command-line arguments to be parsed.
|
|
||||||
#[derive(Parser, Debug)]
|
|
||||||
#[command(author, version, about, long_about = None)]
|
|
||||||
struct Args {
|
|
||||||
/// Whale source code to evaluate.
|
|
||||||
#[arg(short, long)]
|
|
||||||
command: Option<String>,
|
|
||||||
|
|
||||||
/// Location of the file to run.
|
|
||||||
path: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let args = Args::parse();
|
|
||||||
|
|
||||||
if args.path.is_none() && args.command.is_none() {
|
|
||||||
todo!();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(path) = args.path {
|
|
||||||
let file_contents = read_to_string(path).unwrap();
|
|
||||||
|
|
||||||
let mut parser = TSParser::new();
|
|
||||||
parser.set_language(tree_sitter_dust::language()).unwrap();
|
|
||||||
let tree = parser.parse(&file_contents, None).unwrap();
|
|
||||||
let root = tree.root_node();
|
|
||||||
|
|
||||||
tree_sitter_dust::evaluate(root);
|
|
||||||
|
|
||||||
println!("{tree:?}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user