From 74dbaffae846a774f414b4257e2e5066a396dbb2 Mon Sep 17 00:00:00 2001 From: Amaan Qureshi Date: Mon, 2 Oct 2023 22:50:48 -0400 Subject: [PATCH] chore: tidy up for release --- Cargo.toml | 22 +++++++++++--------- README.md | 10 +++------ bindings/node/index.js | 8 ++++---- bindings/rust/README.md | 35 ++++++++++++++++++++++++++++++++ bindings/rust/lib.rs | 14 ++++++------- package.json | 19 +++++++++++++---- src/scanner.c | 1 + {corpus => test/corpus}/main.txt | 0 8 files changed, 76 insertions(+), 33 deletions(-) create mode 100644 bindings/rust/README.md rename {corpus => test/corpus}/main.txt (100%) diff --git a/Cargo.toml b/Cargo.toml index e65e954..2424917 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,25 +1,27 @@ [package] name = "tree-sitter-html" -description = "html grammar for the tree-sitter parsing library" +description = "HTML grammar for tree-sitter" version = "0.19.0" +authors = [ + "Max Brunsfeld ", + "Amaan Qureshi ", +] +license = "MIT" +readme = "bindings/rust/README.md" keywords = ["incremental", "parsing", "html"] categories = ["parsing", "text-editors"] repository = "https://github.com/tree-sitter/tree-sitter-html" -edition = "2018" +edition = "2021" +autoexamples = false 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.19" +tree-sitter = "~0.20.10" [build-dependencies] -cc = "1.0" +cc = "~1.0.83" diff --git a/README.md b/README.md index d06f73a..c2981f4 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,8 @@ -tree-sitter-html -================ +# tree-sitter-html -[![Build Status](https://travis-ci.org/tree-sitter/tree-sitter-html.svg?branch=master)](https://travis-ci.org/tree-sitter/tree-sitter-html) -[![Build status](https://ci.appveyor.com/api/projects/status/bv1i8f3yi2aoyonx/branch/master?svg=true)](https://ci.appveyor.com/project/maxbrunsfeld/tree-sitter-html/branch/master) +[![build](https://github.com/tree-sitter/tree-sitter-html/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-html/actions/workflows/ci.yml) -HTML grammar for [tree-sitter][]. - -[tree-sitter]: https://github.com/tree-sitter/tree-sitter +HTML grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter). References diff --git a/bindings/node/index.js b/bindings/node/index.js index 801b0d0..35d48f5 100644 --- a/bindings/node/index.js +++ b/bindings/node/index.js @@ -1,19 +1,19 @@ try { - module.exports = require("../../build/Release/tree_sitter_html_binding"); + module.exports = require('../../build/Release/tree_sitter_html_binding'); } catch (error1) { if (error1.code !== 'MODULE_NOT_FOUND') { throw error1; } try { - module.exports = require("../../build/Debug/tree_sitter_html_binding"); + module.exports = require('../../build/Debug/tree_sitter_html_binding'); } catch (error2) { if (error2.code !== 'MODULE_NOT_FOUND') { throw error2; } - throw error1 + throw error1; } } try { - module.exports.nodeTypeInfo = require("../../src/node-types.json"); + module.exports.nodeTypeInfo = require('../../src/node-types.json'); } catch (_) {} diff --git a/bindings/rust/README.md b/bindings/rust/README.md new file mode 100644 index 0000000..7b10b01 --- /dev/null +++ b/bindings/rust/README.md @@ -0,0 +1,35 @@ +# tree-sitter-html + +This crate provides a HTML 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-html = "0.19.0" +``` + +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#" + def double(x): + return x * 2 +"#; +let mut parser = Parser::new(); +parser.set_language(tree_sitter_html::language()).expect("Error loading HTML 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-html/*/tree_sitter_html/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 diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index 88b6abd..25c69f9 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -1,4 +1,4 @@ -//! This crate provides html language support for the [tree-sitter][] parsing library. +//! This crate provides HTML 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: @@ -6,7 +6,7 @@ //! ``` //! let code = ""; //! let mut parser = tree_sitter::Parser::new(); -//! parser.set_language(tree_sitter_html::language()).expect("Error loading html grammar"); +//! parser.set_language(tree_sitter_html::language()).expect("Error loading HTML grammar"); //! let tree = parser.parse(code, None).unwrap(); //! ``` //! @@ -31,12 +31,10 @@ pub fn language() -> Language { /// 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 - -// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); -// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); +pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm"); +pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm"); // pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); // pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm"); @@ -47,6 +45,6 @@ mod tests { let mut parser = tree_sitter::Parser::new(); parser .set_language(super::language()) - .expect("Error loading html language"); + .expect("Error loading HTML grammar"); } } diff --git a/package.json b/package.json index f48f6b3..6b979da 100644 --- a/package.json +++ b/package.json @@ -7,20 +7,25 @@ "parser", "lexer" ], + "homepage": "https://github.com/tree-sitter/tree-sitter-html", "repository": { "type": "git", "url": "https://github.com/tree-sitter/tree-sitter-html.git" }, + "bugs": { + "url": "https://github.com/tree-sitter/tree-sitter-html/issues" + }, "authors": [ "Max Brunsfeld ", - "Ashi Krishnan " + "Ashi Krishnan ", + "Amaan Qureshi " ], "license": "MIT", "dependencies": { - "nan": "^2.14.0" + "nan": "^2.18.0" }, "devDependencies": { - "eslint": "^8.43.0", + "eslint": "^8.50.0", "eslint-config-google": "^0.14.0", "tree-sitter-cli": "^0.20.8" }, @@ -36,7 +41,13 @@ "file-types": [ "html" ], - "injection-regex": "html" + "injection-regex": "html", + "highlights": [ + "queries/highlights.scm" + ], + "injections": [ + "queries/injections.scm" + ] } ] } diff --git a/src/scanner.c b/src/scanner.c index 88da273..9ec2915 100644 --- a/src/scanner.c +++ b/src/scanner.c @@ -1,4 +1,5 @@ #include "tag.h" + #include enum TokenType { diff --git a/corpus/main.txt b/test/corpus/main.txt similarity index 100% rename from corpus/main.txt rename to test/corpus/main.txt