Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
[package]
name = "tree-sitter-YOUR-LANGUAGE-NAME"
description = "YOUR-LANGUAGE-NAME grammar for the tree-sitter parsing library"
name = "tree-sitter-cooklang"
description = "Cooklang grammar for tree-sitter"
version = "0.0.1"
keywords = ["incremental", "parsing", "YOUR-LANGUAGE-NAME"]
keywords = ["incremental", "parsing", "cooklang"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter/tree-sitter-YOUR-LANGUAGE-NAME"
edition = "2018"
repository = "https://github.com/addcninblue/tree-sitter-cooklang"
edition = "2021"
license = "MIT"

build = "bindings/rust/build.rs"
include = [
"bindings/rust/*",
"grammar.js",
"queries/*",
"src/*",
]
include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]

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

[dependencies]
tree-sitter = "~0.20.0"
tree-sitter = "~0.20.10"

[build-dependencies]
cc = "1.0"
3 changes: 1 addition & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"targets": [
{
"target_name": "tree_sitter_YOUR_LANGUAGE_NAME_binding",
"target_name": "tree_sitter_cooklang_binding",
"include_dirs": [
"<!(node -e \"require('nan')\")",
"src"
],
"sources": [
"bindings/node/binding.cc",
"src/parser.c",
# If your language uses an external scanner, add it here.
"src/scanner.c"
],
"cflags_c": [
Expand Down
30 changes: 16 additions & 14 deletions bindings/node/binding.cc
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
#include "nan.h"
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"

using namespace v8;

extern "C" TSLanguage * tree_sitter_YOUR_LANGUAGE_NAME();
extern "C" TSLanguage *tree_sitter_cooklang();

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_YOUR_LANGUAGE_NAME());

Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("YOUR_LANGUAGE_NAME").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
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_cooklang());

Nan::Set(instance, Nan::New("name").ToLocalChecked(),
Nan::New("cooklang").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}

NODE_MODULE(tree_sitter_YOUR_LANGUAGE_NAME_binding, Init)
NODE_MODULE(tree_sitter_cooklang_binding, Init)

} // namespace
} // namespace
28 changes: 14 additions & 14 deletions bindings/node/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
try {
module.exports = require("../../build/Release/tree_sitter_YOUR_LANGUAGE_NAME_binding");
module.exports = require("../../build/Release/tree_sitter_cooklang_binding");
} catch (error1) {
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_YOUR_LANGUAGE_NAME_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
if (error1.code !== 'MODULE_NOT_FOUND') {
throw error1;
}
try {
module.exports = require("../../build/Debug/tree_sitter_cooklang_binding");
} catch (error2) {
if (error2.code !== 'MODULE_NOT_FOUND') {
throw error2;
}
throw error1
}
}

try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) { }
23 changes: 1 addition & 22 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,18 @@ fn main() {
let src_dir = std::path::Path::new("src");

let mut c_config = cc::Build::new();
c_config.include(&src_dir);
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);

// If your language uses an external scanner written in C,
// then include this block of code:

/*
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());

// If your language uses an external scanner written in C++,
// then include this block of code:

/*
let mut cpp_config = cc::Build::new();
cpp_config.cpp(true);
cpp_config.include(&src_dir);
cpp_config
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wno-unused-but-set-variable");
let scanner_path = src_dir.join("scanner.cc");
cpp_config.file(&scanner_path);
cpp_config.compile("scanner");
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/
}
12 changes: 6 additions & 6 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! This crate provides YOUR_LANGUAGE_NAME language support for the [tree-sitter][] parsing library.
//! This crate provides Cooklang language support for the [tree-sitter][] parsing library.
//!
//! Typically, you will use the [language][language func] function to add this language to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//!
//! ```
//! let code = "";
//! let mut parser = tree_sitter::Parser::new();
//! parser.set_language(tree_sitter_YOUR_LANGUAGE_NAME::language()).expect("Error loading YOUR_LANGUAGE_NAME grammar");
//! parser.set_language(tree_sitter_cooklang::language()).expect("Error loading Cooklang grammar");
//! let tree = parser.parse(code, None).unwrap();
//! ```
//!
Expand All @@ -18,20 +18,20 @@
use tree_sitter::Language;

extern "C" {
fn tree_sitter_YOUR_LANGUAGE_NAME() -> Language;
fn tree_sitter_cooklang() -> Language;
}

/// Get the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language() -> Language {
unsafe { tree_sitter_YOUR_LANGUAGE_NAME() }
unsafe { tree_sitter_cooklang() }
}

/// 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
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");

// Uncomment these to include any queries that this grammar contains

Expand All @@ -47,6 +47,6 @@ mod tests {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(super::language())
.expect("Error loading YOUR_LANGUAGE_NAME language");
.expect("Error loading Cooklang grammar");
}
}
26 changes: 13 additions & 13 deletions corpus/big
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ Bake for ~{20%minutes} until puffed and golden brown all over.
(metadata)
(metadata)
(step
(cookware)
(ingredient (amount (quantity) (units)))
(ingredient (amount (quantity) (units)))
(ingredient (amount (quantity) (units))))
(cookware (name))
(ingredient (name) (amount (quantity) (units)))
(ingredient (name) (amount (quantity) (units)))
(ingredient (name) (amount (quantity) (units))))
(step
(ingredient (amount (quantity) (units)))
(ingredient (amount (quantity) (units))))
(ingredient (name) (amount (quantity) (units)))
(ingredient (name) (amount (quantity) (units))))
(step
(cookware)
(ingredient (amount (quantity) (units)))
(ingredient)
(cookware (name))
(ingredient (name) (amount (quantity) (units)))
(ingredient (name))
(timer (amount (quantity) (units))))
(step)
(step
(cookware)
(ingredient (amount (quantity) (units)))
(cookware (name))
(ingredient (name) (amount (quantity) (units)))
(timer (amount (quantity) (units))))
(step
(ingredient (amount (quantity) (units)))
(ingredient))
(ingredient (name) (amount (quantity) (units)))
(ingredient (name)))
(step
(timer (amount (quantity) (units)))))
8 changes: 4 additions & 4 deletions corpus/step
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ I need @potato{1%gram}.

---

(recipe (step (ingredient (amount (quantity) (units)))))
(recipe (step (ingredient (name) (amount (quantity) (units)))))

====================
Multiword Ingredient
Expand All @@ -16,7 +16,7 @@ I need @sweet potato{}.

---

(recipe (step (ingredient)))
(recipe (step (ingredient (name))))

==============
Big Ingredient
Expand All @@ -26,7 +26,7 @@ Big Ingredient

---

(recipe (step (ingredient (amount (quantity) (units)))))
(recipe (step (ingredient (name) (amount (quantity) (units)))))

===============
Simple Cookware
Expand All @@ -36,7 +36,7 @@ I need #pot{1%lb}.

---

(recipe (step (cookware (amount (quantity) (units)))))
(recipe (step (cookware (name) (amount (quantity) (units)))))

============
Simple Timer
Expand Down
37 changes: 26 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
"author": "",
"license": "ISC",
"dependencies": {
"nan": "^2.15.0"
"nan": "^2.17.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.20.1"
"tree-sitter-cli": "^0.20.8"
},
"tree-sitter": {
"scope": "source.cook",
Expand Down
Loading