@willbooster/tree-sitter-embedded-template 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # @willbooster/tree-sitter-embedded-template
2
2
 
3
+ [![npm version](https://img.shields.io/npm/v/@willbooster/tree-sitter-embedded-template.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-embedded-template)
4
+ [![license](https://img.shields.io/npm/l/@willbooster/tree-sitter-embedded-template.svg)](https://www.npmjs.com/package/@willbooster/tree-sitter-embedded-template)
3
5
  [![Test](https://github.com/WillBooster/tree-sitter-embedded-template/actions/workflows/test.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-embedded-template/actions/workflows/test.yml)
4
6
  [![Test rust](https://github.com/WillBooster/tree-sitter-embedded-template/actions/workflows/test-rust.yml/badge.svg)](https://github.com/WillBooster/tree-sitter-embedded-template/actions/workflows/test-rust.yml)
5
7
  [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
6
- [![wbfy](https://img.shields.io/badge/wbfy-20.36.11-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
8
+ [![wbfy](https://img.shields.io/badge/wbfy-20.41.8-1e90ff.svg)](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
7
9
  [![crates.io](https://img.shields.io/crates/v/willbooster-tree-sitter-embedded-template.svg)](https://crates.io/crates/willbooster-tree-sitter-embedded-template)
8
10
 
9
11
  Embedded template grammar for [tree-sitter](https://github.com/tree-sitter/tree-sitter), forked from
@@ -11,7 +13,9 @@ Embedded template grammar for [tree-sitter](https://github.com/tree-sitter/tree-
11
13
  to its authors and contributors. This is not an official release of that project.
12
14
 
13
15
  It parses templating languages such as ERB and EJS, in which scripting code is embedded in text with the delimiters
14
- `<%` and `%>`. This fork keeps the grammar of upstream's version 0.25.0 and generates the parser with the
16
+ `<%` and `%>`. This fork extends upstream's version 0.25.0 grammar with EJS output-tag whitespace slurping
17
+ and HTML/Perl injections for angle-delimited Embedded Perl tags.
18
+ It generates the parser with the
15
19
  [WillBooster/tree-sitter](https://github.com/WillBooster/tree-sitter) generator. The parser loads only with that fork's runtime, version 2.0.0 or later
16
20
  ([willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter),
17
21
  [@willbooster/web-tree-sitter](https://www.npmjs.com/package/@willbooster/web-tree-sitter)); upstream's runtime rejects it.
@@ -61,6 +65,24 @@ parser.setLanguage(await Language.load(grammar));
61
65
 
62
66
  The package also ships `grammar.js`, the queries in `queries/`, and the node types in `src/node-types.json`.
63
67
 
68
+ For HTML Embedded Perl templates, select `queries/injections-ep.scm` (or `INJECTIONS_EP_QUERY` in Rust).
69
+ CLI language discovery associates every `.ep` file with the `text.html.ep` scope, including non-HTML templates
70
+ such as `mail.txt.ep`. The query always treats template content as HTML; configure a different content injection
71
+ for non-HTML formats. The host must process combined injections and provide HTML and Perl parsers generated
72
+ with WillBooster/tree-sitter, matching this runtime's ABI. The `tree-sitter highlight` command of WillBooster/tree-sitter
73
+ orders highlights from these combined injections correctly from version 2.0.29; earlier versions can drop the
74
+ highlights of the first region.
75
+ Use `@willbooster/tree-sitter-html` or `willbooster-tree-sitter-html` for HTML. For Perl, check out this repository
76
+ and [tree-sitter-perl/tree-sitter-perl](https://github.com/tree-sitter-perl/tree-sitter-perl). From the Perl checkout
77
+ as the working directory, run `<embedded-template-checkout>/script/tree-sitter generate grammar.js`, replacing
78
+ `<embedded-template-checkout>` with this repository's absolute checkout path. Then build the generated parser for
79
+ your host and register it as `perl`. The npm package and Rust crate include neither this script nor a Perl parser.
80
+ Upstream-generated parsers cannot load in this runtime.
81
+ With these parsers configured, the query supports the existing angle-delimited tags, such as
82
+ `<% my $name = "World"; %><p><%= $name %></p>`; it is not a full Mojo::Template parser.
83
+ Perl lines beginning with `%`, template capture markers (`begin`/`end`), custom delimiters, and whitespace-trimming
84
+ `=%>` on non-output directives are not supported.
85
+
64
86
  In Rust, depend on the [crate](https://crates.io/crates/willbooster-tree-sitter-embedded-template) and on
65
87
  [willbooster-tree-sitter](https://crates.io/crates/willbooster-tree-sitter), the runtime this package is tested and
66
88
  fuzzed with:
@@ -133,3 +155,4 @@ with libFuzzer and sanitizers (`.github/workflows/robustness.yml`).
133
155
  - [EJS Documentation](https://ejs.co/#docs)
134
156
  - [etlua Documentation](https://github.com/leafo/etlua)
135
157
  - [Eta Documentation](https://eta.js.org/docs)
158
+ - [EP Documentation](https://docs.mojolicious.org/Mojo/Template)
package/grammar.js CHANGED
@@ -34,7 +34,7 @@ module.exports = grammar({
34
34
  output_directive: $ => seq(
35
35
  choice('<%=', '<%==', '<%|=', '<%|==', '<%-'),
36
36
  optional($.code),
37
- choice('%>', '-%>', '=%>'),
37
+ choice('%>', '-%>', '=%>', '_%>'),
38
38
  ),
39
39
 
40
40
  comment_directive: $ => seq(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-embedded-template",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "Embedded template (ERB, EJS) grammar for tree-sitter",
5
5
  "keywords": [
6
6
  "incremental",
@@ -46,17 +46,16 @@
46
46
  "@vitest/browser-playwright": "5.0.3",
47
47
  "@willbooster/oxfmt-config": "1.2.2",
48
48
  "@willbooster/oxlint-config": "1.4.8",
49
- "@willbooster/wb": "22.24.0",
50
- "@willbooster/web-tree-sitter": "2.0.1",
49
+ "@willbooster/wb": "22.26.1",
50
+ "@willbooster/web-tree-sitter": "2.0.29",
51
51
  "conventional-changelog-conventionalcommits": "10.4.0",
52
- "lefthook": "2.1.16",
53
- "oxfmt": "0.71.0",
54
- "oxlint": "1.86.0",
55
- "oxlint-tsgolint": "7.0.2003",
52
+ "lefthook": "2.2.1",
53
+ "oxfmt": "0.72.0",
54
+ "oxlint": "1.87.0",
55
+ "oxlint-tsgolint": "7.0.2004",
56
56
  "playwright": "1.63.0",
57
57
  "semantic-release": "25.0.9",
58
58
  "sort-package-json": "4.0.0",
59
- "typescript": "7.0.2",
60
59
  "vitest": "5.0.3",
61
60
  "wrangler": "4.147.0"
62
61
  },
@@ -0,0 +1,7 @@
1
+ ((content) @injection.content
2
+ (#set! injection.language "html")
3
+ (#set! injection.combined))
4
+
5
+ ((code) @injection.content
6
+ (#set! injection.language "perl")
7
+ (#set! injection.combined))
Binary file
package/tree-sitter.json CHANGED
@@ -33,10 +33,21 @@
33
33
  ],
34
34
  "injections": "queries/injections-etlua.scm",
35
35
  "injection-regex": "etlua"
36
+ },
37
+ {
38
+ "name": "embedded-template",
39
+ "camelcase": "EmbeddedTemplate",
40
+ "scope": "text.html.ep",
41
+ "path": ".",
42
+ "file-types": [
43
+ "ep"
44
+ ],
45
+ "injections": "queries/injections-ep.scm",
46
+ "injection-regex": "ep"
36
47
  }
37
48
  ],
38
49
  "metadata": {
39
- "version": "1.0.0",
50
+ "version": "1.1.0",
40
51
  "license": "MIT",
41
52
  "description": "Embedded template (ERB, EJS) grammar for tree-sitter",
42
53
  "authors": [