forked from vhyrro/tree-sitter-luap
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
6 changed files
with
158 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
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,30 @@ | ||
#include "nan.h" | ||
#include "tree_sitter/parser.h" | ||
#include <node.h> | ||
|
||
using namespace v8; | ||
|
||
extern "C" TSLanguage *tree_sitter_luap(); | ||
|
||
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_luap()); | ||
|
||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), | ||
Nan::New("luap").ToLocalChecked()); | ||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); | ||
} | ||
|
||
NODE_MODULE(tree_sitter_luap_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_luap_binding'); | ||
} catch (error1) { | ||
if (error1.code !== 'MODULE_NOT_FOUND') { | ||
throw error1; | ||
} | ||
try { | ||
module.exports = require('../../build/Debug/tree_sitter_luap_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,37 @@ | ||
# tree-sitter-luap | ||
|
||
This crate provides a Lua Patterns 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.3" | ||
tree-sitter-luap = "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#" | ||
circuit Adder : | ||
module Adder : | ||
input clock: Clock | ||
skip | ||
"#; | ||
let mut parser = Parser::new(); | ||
parser.set_language(tree_sitter_luap::language()).expect("Error loading Lua Patterns 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-luap/*/tree_sitter_luap/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,15 @@ | ||
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); | ||
|
||
c_config.compile("parser"); | ||
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); | ||
} |
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,56 @@ | ||
// ------------------------------------------------------------------------------------------------ | ||
// Copyright © 2023 Vhyrro <[email protected]>, Amaan Qureshi <[email protected]>, | ||
// See the LICENSE file in this repo for license details. | ||
// ------------------------------------------------------------------------------------------------ | ||
|
||
//! This crate provides Lua Patterns 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_luap::language()).expect("Error loading Lua Patterns grammar"); | ||
//! let tree = parser.parse(code, None).unwrap(); | ||
//! ``` | ||
//! | ||
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html | ||
//! [language func]: fn.language.html | ||
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html | ||
//! [tree-sitter]: https://tree-sitter.github.io/ | ||
|
||
use tree_sitter::Language; | ||
|
||
extern "C" { | ||
fn tree_sitter_luap() -> 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_luap() } | ||
} | ||
|
||
/// The source of the Rust tree-sitter grammar description. | ||
pub const GRAMMAR: &str = include_str!("../../grammar.js"); | ||
|
||
/// The syntax highlighting query for this language. | ||
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); | ||
|
||
/// 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: &str = include_str!("../../src/node-types.json"); | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
#[test] | ||
fn test_can_load_grammar() { | ||
let mut parser = tree_sitter::Parser::new(); | ||
parser | ||
.set_language(super::language()) | ||
.expect("Error loading Lua Patterns grammar"); | ||
} | ||
} |