tree-sitter-aspx 0.0.0-stage → 0.1.3
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/LICENSE +21 -0
- package/NOTICE +7 -0
- package/README.md +56 -2
- package/binding.gyp +30 -0
- package/bindings/node/binding.cc +20 -0
- package/bindings/node/binding_test.js +31 -0
- package/bindings/node/index.d.ts +57 -0
- package/bindings/node/index.js +41 -0
- package/grammar.js +296 -0
- package/package.json +68 -4
- package/prebuilds/linux-x64/tree-sitter-aspx.node +0 -0
- package/prebuilds/win32-x64/tree-sitter-aspx.node +0 -0
- package/queries/highlights.scm +22 -0
- package/queries/injections.scm +70 -0
- package/src/grammar.json +1484 -0
- package/src/node-types.json +840 -0
- package/src/parser.c +6573 -0
- package/src/scanner.c +266 -0
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +336 -0
- package/src/tree_sitter/parser.h +286 -0
- package/tree-sitter.json +47 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 M. Reifschneider
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/NOTICE
ADDED
package/README.md
CHANGED
|
@@ -1,3 +1,57 @@
|
|
|
1
|
-
#
|
|
1
|
+
# tree-sitter-aspx
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/alfpricot/tree-sitter-aspx/actions/workflows/verify.yml)
|
|
4
|
+
[](https://crates.io/crates/tree-sitter-aspx)
|
|
5
|
+
|
|
6
|
+
A [tree-sitter](https://tree-sitter.github.io/tree-sitter/) grammar for ASP.NET Web Forms markup: `.aspx` pages, `.ascx` user controls, `.master` master pages, and the directive headers of `.asax`, `.asmx`, and `.ashx` files, with Node and Rust bindings. Classic ASP (`.asp` with VBScript) and Razor (`.cshtml`, `.vbhtml`) are different languages and are out of scope, and code-behind files (`.aspx.cs`, `.aspx.vb`) are ordinary C# or VB.NET that this grammar does not parse.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```sh
|
|
11
|
+
npm install tree-sitter-aspx # Node
|
|
12
|
+
cargo add tree-sitter-aspx # Rust
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Requirements
|
|
16
|
+
|
|
17
|
+
- **Node:** the `tree-sitter` package, version `^0.25.0`, is an optional peer dependency. The binding is a Node-API addon with prebuilt copies for Linux and Windows; on any other platform the install compiles it from source and needs a C/C++ toolchain that `node-gyp` can use.
|
|
18
|
+
- **Rust:** 1.85 or newer. The crate depends only on `tree-sitter-language`, so the `tree-sitter` version your own crate uses is the one that parses.
|
|
19
|
+
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
The grammar parses directives, server comments, HTML comments, code nuggets, `<script>` and `<style>` elements, and tags with attributes. It does not validate HTML. Void tags (`br`, `img`, `meta`, and the other HTML void elements) do not swallow the following markup. An end tag closes the nearest open element; the names are not required to match. `<script>` and `<style>` bodies are raw text, so `<` inside JavaScript or CSS is not a tag.
|
|
23
|
+
|
|
24
|
+
The C# and VB.NET inside a page are exposed as `c_sharp_code` and `vb_code` nodes, with injection queries for editors. See [docs/EMBEDDED_CODE.md](docs/EMBEDDED_CODE.md).
|
|
25
|
+
|
|
26
|
+
### Node
|
|
27
|
+
|
|
28
|
+
The default export exposes `name`, `language`, and `nodeTypeInfo` (the entries from `src/node-types.json`) on every platform, plus the `HIGHLIGHTS_QUERY` and `INJECTIONS_QUERY` strings.
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import Parser from 'tree-sitter';
|
|
32
|
+
import Aspx from 'tree-sitter-aspx';
|
|
33
|
+
|
|
34
|
+
const parser = new Parser();
|
|
35
|
+
parser.setLanguage(Aspx);
|
|
36
|
+
const tree = parser.parse('<%@ Page Language="C#" %>');
|
|
37
|
+
console.log(tree.rootNode.toString());
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Rust
|
|
41
|
+
|
|
42
|
+
```rust
|
|
43
|
+
let mut parser = tree_sitter::Parser::new();
|
|
44
|
+
parser
|
|
45
|
+
.set_language(&tree_sitter_aspx::LANGUAGE.into())
|
|
46
|
+
.expect("Error loading ASPX parser");
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
`LANGUAGE` is a `tree_sitter_language::LanguageFn`. The crate also exports `NODE_TYPES`, `HIGHLIGHTS_QUERY`, and `INJECTIONS_QUERY`.
|
|
50
|
+
|
|
51
|
+
## How to contribute
|
|
52
|
+
|
|
53
|
+
Branch from `dev` and open pull requests against it. [CONTRIBUTING.md](CONTRIBUTING.md) covers building the parser, running the checks CI runs, and the pull request rules; [ARCHITECTURE.md](ARCHITECTURE.md) explains how the pieces fit together.
|
|
54
|
+
|
|
55
|
+
## License
|
|
56
|
+
|
|
57
|
+
MIT. See [LICENSE](LICENSE).
|
package/binding.gyp
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"targets": [
|
|
3
|
+
{
|
|
4
|
+
"target_name": "tree_sitter_aspx_binding",
|
|
5
|
+
"dependencies": [
|
|
6
|
+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
|
|
7
|
+
],
|
|
8
|
+
"include_dirs": [
|
|
9
|
+
"src",
|
|
10
|
+
],
|
|
11
|
+
"sources": [
|
|
12
|
+
"bindings/node/binding.cc",
|
|
13
|
+
"src/parser.c",
|
|
14
|
+
"src/scanner.c",
|
|
15
|
+
],
|
|
16
|
+
"conditions": [
|
|
17
|
+
["OS!='win'", {
|
|
18
|
+
"cflags_c": [
|
|
19
|
+
"-std=c11",
|
|
20
|
+
],
|
|
21
|
+
}, {
|
|
22
|
+
"cflags_c": [
|
|
23
|
+
"/std:c11",
|
|
24
|
+
"/utf-8",
|
|
25
|
+
],
|
|
26
|
+
}],
|
|
27
|
+
],
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#include <napi.h>
|
|
2
|
+
|
|
3
|
+
typedef struct TSLanguage TSLanguage;
|
|
4
|
+
|
|
5
|
+
extern "C" TSLanguage *tree_sitter_aspx();
|
|
6
|
+
|
|
7
|
+
// "tree-sitter", "language" hashed with BLAKE2
|
|
8
|
+
const napi_type_tag LANGUAGE_TYPE_TAG = {
|
|
9
|
+
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
13
|
+
exports["name"] = Napi::String::New(env, "aspx");
|
|
14
|
+
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_aspx());
|
|
15
|
+
language.TypeTag(&LANGUAGE_TYPE_TAG);
|
|
16
|
+
exports["language"] = language;
|
|
17
|
+
return exports;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
NODE_API_MODULE(tree_sitter_aspx_binding, Init)
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import assert from 'node:assert';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
import Parser from 'tree-sitter';
|
|
4
|
+
|
|
5
|
+
test('can load grammar', async () => {
|
|
6
|
+
const parser = new Parser();
|
|
7
|
+
await assert.doesNotReject(async () => {
|
|
8
|
+
const { default: language } = await import('./index.js');
|
|
9
|
+
parser.setLanguage(language);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('exports node type metadata', async () => {
|
|
14
|
+
const { default: language } = await import('./index.js');
|
|
15
|
+
assert(Array.isArray(language.nodeTypeInfo));
|
|
16
|
+
assert(language.nodeTypeInfo.some((node) => node.type === 'document'));
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('exports the aspx language name', async () => {
|
|
20
|
+
const { default: language } = await import('./index.js');
|
|
21
|
+
assert.equal(language.name, 'aspx');
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('parses a page directive without error', async () => {
|
|
25
|
+
const { default: language } = await import('./index.js');
|
|
26
|
+
const parser = new Parser();
|
|
27
|
+
parser.setLanguage(language);
|
|
28
|
+
const tree = parser.parse('<%@ Page Language="C#" Inherits="Example.Page" %>');
|
|
29
|
+
assert.equal(tree.rootNode.hasError, false);
|
|
30
|
+
assert.equal(tree.rootNode.type, 'source_file');
|
|
31
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
type BaseNode = {
|
|
2
|
+
type: string;
|
|
3
|
+
named: boolean;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
type ChildNode = {
|
|
7
|
+
multiple: boolean;
|
|
8
|
+
required: boolean;
|
|
9
|
+
types: BaseNode[];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type NodeInfo =
|
|
13
|
+
| (BaseNode & {
|
|
14
|
+
subtypes: BaseNode[];
|
|
15
|
+
})
|
|
16
|
+
| (BaseNode & {
|
|
17
|
+
fields?: { [name: string]: ChildNode };
|
|
18
|
+
children?: ChildNode;
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The tree-sitter language object for this grammar.
|
|
23
|
+
*
|
|
24
|
+
* @see {@linkcode https://tree-sitter.github.io/node-tree-sitter/interfaces/Parser.Language.html Parser.Language}
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* import Parser from "tree-sitter";
|
|
28
|
+
* import Aspx from "tree-sitter-aspx";
|
|
29
|
+
*
|
|
30
|
+
* const parser = new Parser();
|
|
31
|
+
* parser.setLanguage(Aspx);
|
|
32
|
+
*/
|
|
33
|
+
declare const binding: {
|
|
34
|
+
/** The language name. */
|
|
35
|
+
name: "aspx";
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The inner language object.
|
|
39
|
+
* @private
|
|
40
|
+
*/
|
|
41
|
+
language: unknown;
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The content of the `node-types.json` file for this grammar.
|
|
45
|
+
*
|
|
46
|
+
* @see {@linkplain https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types Static Node Types}
|
|
47
|
+
*/
|
|
48
|
+
nodeTypeInfo: NodeInfo[];
|
|
49
|
+
|
|
50
|
+
/** The syntax highlighting query for this grammar. */
|
|
51
|
+
HIGHLIGHTS_QUERY?: string;
|
|
52
|
+
|
|
53
|
+
/** The language injection query for this grammar. */
|
|
54
|
+
INJECTIONS_QUERY?: string;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default binding;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
const root = fileURLToPath(new URL('../..', import.meta.url));
|
|
5
|
+
|
|
6
|
+
const binding =
|
|
7
|
+
typeof process.versions.bun === 'string'
|
|
8
|
+
? // Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time
|
|
9
|
+
await import(`${root}/prebuilds/${process.platform}-${process.arch}/tree-sitter-aspx.node`)
|
|
10
|
+
: (await import('node-gyp-build')).default(root);
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
binding.nodeTypeInfo = JSON.parse(
|
|
14
|
+
readFileSync(new URL('../../src/node-types.json', import.meta.url), 'utf8'),
|
|
15
|
+
);
|
|
16
|
+
} catch {
|
|
17
|
+
// node-types.json is optional metadata; the binding still works without it.
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const queries = [
|
|
21
|
+
['HIGHLIGHTS_QUERY', `${root}/queries/highlights.scm`],
|
|
22
|
+
['INJECTIONS_QUERY', `${root}/queries/injections.scm`],
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
for (const [prop, path] of queries) {
|
|
26
|
+
Object.defineProperty(binding, prop, {
|
|
27
|
+
configurable: true,
|
|
28
|
+
enumerable: true,
|
|
29
|
+
get() {
|
|
30
|
+
delete binding[prop];
|
|
31
|
+
try {
|
|
32
|
+
binding[prop] = readFileSync(path, 'utf8');
|
|
33
|
+
} catch {
|
|
34
|
+
// A missing query file leaves the property undefined.
|
|
35
|
+
}
|
|
36
|
+
return binding[prop];
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default binding;
|
package/grammar.js
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/// <reference types="tree-sitter-cli/dsl" />
|
|
2
|
+
// @ts-check
|
|
3
|
+
|
|
4
|
+
// Lexical precedence above the general tag/attribute names, so `script`,
|
|
5
|
+
// `br`, and `Language` win when they are the same length as the general
|
|
6
|
+
// pattern. Longer names (`scriptmanager`, `break`) still take the general
|
|
7
|
+
// pattern because the lexer prefers the longest match.
|
|
8
|
+
const RESERVED = 1;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @param {string} word
|
|
12
|
+
*/
|
|
13
|
+
function reserved(word) {
|
|
14
|
+
return token(
|
|
15
|
+
prec(
|
|
16
|
+
RESERVED,
|
|
17
|
+
new RegExp(
|
|
18
|
+
word
|
|
19
|
+
.split('')
|
|
20
|
+
.map((ch) => {
|
|
21
|
+
const lower = ch.toLowerCase();
|
|
22
|
+
const upper = ch.toUpperCase();
|
|
23
|
+
return lower === upper
|
|
24
|
+
? ch.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
25
|
+
: `[${upper}${lower}]`;
|
|
26
|
+
})
|
|
27
|
+
.join(''),
|
|
28
|
+
),
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const VOID_TAGS = [
|
|
34
|
+
'area',
|
|
35
|
+
'base',
|
|
36
|
+
'br',
|
|
37
|
+
'col',
|
|
38
|
+
'embed',
|
|
39
|
+
'hr',
|
|
40
|
+
'img',
|
|
41
|
+
'input',
|
|
42
|
+
'link',
|
|
43
|
+
'meta',
|
|
44
|
+
'param',
|
|
45
|
+
'source',
|
|
46
|
+
'track',
|
|
47
|
+
'wbr',
|
|
48
|
+
];
|
|
49
|
+
|
|
50
|
+
export default grammar({
|
|
51
|
+
name: 'aspx',
|
|
52
|
+
|
|
53
|
+
// A UTF-8 BOM is whitespace as far as the page parser is concerned. UTF-16
|
|
54
|
+
// files are decoded to UTF-8 before parsing; see tools/corpus-check.mjs.
|
|
55
|
+
extras: (_) => [/\s/, /\uFEFF/],
|
|
56
|
+
|
|
57
|
+
// Reserved names (`col`, `script`, `Language`, `WebHandler`) must not match
|
|
58
|
+
// a prefix of a longer name (`Columns`, `asp:ScriptManager`). Keywords are
|
|
59
|
+
// recognized only against this word token, so directive names and tag names
|
|
60
|
+
// both alias it.
|
|
61
|
+
word: ($) => $._name,
|
|
62
|
+
|
|
63
|
+
externals: ($) => [
|
|
64
|
+
$._lang_csharp,
|
|
65
|
+
$._lang_vb,
|
|
66
|
+
$._lang_other,
|
|
67
|
+
$._code_csharp,
|
|
68
|
+
$._code_vb,
|
|
69
|
+
$.server_comment_text,
|
|
70
|
+
$._script_csharp,
|
|
71
|
+
$._script_vb,
|
|
72
|
+
$.style_text,
|
|
73
|
+
$.expression_text,
|
|
74
|
+
$.handler_text,
|
|
75
|
+
],
|
|
76
|
+
|
|
77
|
+
rules: {
|
|
78
|
+
// WebHandler / WebService files are a directive plus code, not markup.
|
|
79
|
+
// The reserved directive name is what selects that alternative. An empty
|
|
80
|
+
// file is the start rule matching nothing; `document` itself cannot be
|
|
81
|
+
// empty because tree-sitter rejects a non-start rule that matches "".
|
|
82
|
+
source_file: ($) => optional(choice($.handler_file, $.document)),
|
|
83
|
+
|
|
84
|
+
document: ($) => repeat1($._top),
|
|
85
|
+
|
|
86
|
+
handler_file: ($) =>
|
|
87
|
+
seq(
|
|
88
|
+
$.handler_directive,
|
|
89
|
+
repeat(choice($.server_comment, $.script_element, alias($.handler_text, $.handler_code))),
|
|
90
|
+
),
|
|
91
|
+
|
|
92
|
+
_top: ($) => choice($._content, $.end_tag),
|
|
93
|
+
|
|
94
|
+
_content: ($) =>
|
|
95
|
+
choice(
|
|
96
|
+
$.directive,
|
|
97
|
+
$.server_comment,
|
|
98
|
+
$.html_comment,
|
|
99
|
+
$._nugget,
|
|
100
|
+
$.script_element,
|
|
101
|
+
$.style_element,
|
|
102
|
+
$.void_element,
|
|
103
|
+
$.self_closing_element,
|
|
104
|
+
$.element,
|
|
105
|
+
$.doctype,
|
|
106
|
+
$.text,
|
|
107
|
+
),
|
|
108
|
+
|
|
109
|
+
directive: ($) => seq('<%@', field('name', $.directive_name), repeat($._attribute), '%>'),
|
|
110
|
+
|
|
111
|
+
handler_directive: ($) =>
|
|
112
|
+
seq(
|
|
113
|
+
'<%@',
|
|
114
|
+
field('name', alias(choice($.web_handler_name, $.web_service_name), $.directive_name)),
|
|
115
|
+
repeat($._attribute),
|
|
116
|
+
'%>',
|
|
117
|
+
),
|
|
118
|
+
|
|
119
|
+
_name: (_) => /[A-Za-z_][A-Za-z0-9_.:-]*/,
|
|
120
|
+
directive_name: ($) => $._name,
|
|
121
|
+
web_handler_name: (_) => choice('WebHandler', 'webhandler', 'WEBHANDLER'),
|
|
122
|
+
web_service_name: (_) => choice('WebService', 'webservice', 'WEBSERVICE'),
|
|
123
|
+
|
|
124
|
+
// `Language` is its own attribute so the value is a language_value node
|
|
125
|
+
// and the scanner can record C# vs VB for later code tokens.
|
|
126
|
+
language_attribute: ($) =>
|
|
127
|
+
seq(
|
|
128
|
+
field('name', alias($.language_name, $.attribute_name)),
|
|
129
|
+
'=',
|
|
130
|
+
choice(
|
|
131
|
+
seq('"', field('value', $._language_value), '"'),
|
|
132
|
+
seq("'", field('value', $._language_value), "'"),
|
|
133
|
+
),
|
|
134
|
+
),
|
|
135
|
+
|
|
136
|
+
language_name: (_) => reserved('Language'),
|
|
137
|
+
|
|
138
|
+
_language_value: ($) =>
|
|
139
|
+
alias(choice($._lang_csharp, $._lang_vb, $._lang_other), $.language_value),
|
|
140
|
+
|
|
141
|
+
_attribute: ($) => choice($.language_attribute, $.attribute),
|
|
142
|
+
|
|
143
|
+
attribute: ($) =>
|
|
144
|
+
seq(
|
|
145
|
+
field('name', $.attribute_name),
|
|
146
|
+
optional(
|
|
147
|
+
seq(
|
|
148
|
+
'=',
|
|
149
|
+
field(
|
|
150
|
+
'value',
|
|
151
|
+
choice(
|
|
152
|
+
$.quoted_attribute_value,
|
|
153
|
+
alias($.unquoted_attribute_value, $.attribute_value),
|
|
154
|
+
),
|
|
155
|
+
),
|
|
156
|
+
),
|
|
157
|
+
),
|
|
158
|
+
),
|
|
159
|
+
|
|
160
|
+
attribute_name: (_) => /[A-Za-z_:][A-Za-z0-9_.:-]*/,
|
|
161
|
+
|
|
162
|
+
quoted_attribute_value: ($) =>
|
|
163
|
+
choice(
|
|
164
|
+
seq('"', repeat($._double_quoted_chunk), '"'),
|
|
165
|
+
seq("'", repeat($._single_quoted_chunk), "'"),
|
|
166
|
+
),
|
|
167
|
+
|
|
168
|
+
_double_quoted_chunk: ($) =>
|
|
169
|
+
choice(
|
|
170
|
+
$._nugget,
|
|
171
|
+
$.server_comment,
|
|
172
|
+
alias(/[^"<%]+/, $.attribute_value),
|
|
173
|
+
alias('%', $.attribute_value),
|
|
174
|
+
alias('<', $.attribute_value),
|
|
175
|
+
),
|
|
176
|
+
|
|
177
|
+
_single_quoted_chunk: ($) =>
|
|
178
|
+
choice(
|
|
179
|
+
$._nugget,
|
|
180
|
+
$.server_comment,
|
|
181
|
+
alias(/[^'<%]+/, $.attribute_value),
|
|
182
|
+
alias('%', $.attribute_value),
|
|
183
|
+
alias('<', $.attribute_value),
|
|
184
|
+
),
|
|
185
|
+
|
|
186
|
+
unquoted_attribute_value: (_) => /[^"'=<>\s`]+/,
|
|
187
|
+
|
|
188
|
+
server_comment: ($) => seq('<%--', optional($.server_comment_text), '--%>'),
|
|
189
|
+
|
|
190
|
+
// Nuggets inside an HTML comment still execute, so they stay real nodes.
|
|
191
|
+
html_comment: ($) =>
|
|
192
|
+
seq(
|
|
193
|
+
'<!--',
|
|
194
|
+
repeat(
|
|
195
|
+
choice(
|
|
196
|
+
$._nugget,
|
|
197
|
+
$.server_comment,
|
|
198
|
+
$.directive,
|
|
199
|
+
alias(/[^-<>]+/, $.comment_text),
|
|
200
|
+
alias('-', $.comment_text),
|
|
201
|
+
alias('<', $.comment_text),
|
|
202
|
+
alias('>', $.comment_text),
|
|
203
|
+
),
|
|
204
|
+
),
|
|
205
|
+
'-->',
|
|
206
|
+
),
|
|
207
|
+
|
|
208
|
+
_nugget: ($) =>
|
|
209
|
+
choice(
|
|
210
|
+
$.encoded_expression,
|
|
211
|
+
$.output_expression,
|
|
212
|
+
$.binding_expression,
|
|
213
|
+
$.expression_builder,
|
|
214
|
+
$.statement_block,
|
|
215
|
+
),
|
|
216
|
+
|
|
217
|
+
_embedded_code: ($) =>
|
|
218
|
+
choice(alias($._code_csharp, $.c_sharp_code), alias($._code_vb, $.vb_code)),
|
|
219
|
+
|
|
220
|
+
encoded_expression: ($) => seq('<%:', optional($._embedded_code), '%>'),
|
|
221
|
+
output_expression: ($) => seq('<%=', optional($._embedded_code), '%>'),
|
|
222
|
+
binding_expression: ($) => seq('<%#', optional($._embedded_code), '%>'),
|
|
223
|
+
statement_block: ($) => seq('<%', optional($._embedded_code), '%>'),
|
|
224
|
+
|
|
225
|
+
// Expression builders (`<%$ AppSettings:Key %>`) are not C# or VB.
|
|
226
|
+
expression_builder: ($) =>
|
|
227
|
+
seq('<%$', optional(alias($.expression_text, $.expression_value)), '%>'),
|
|
228
|
+
|
|
229
|
+
script_element: ($) =>
|
|
230
|
+
seq(
|
|
231
|
+
alias($.script_start_tag, $.start_tag),
|
|
232
|
+
optional(choice(alias($._script_csharp, $.c_sharp_code), alias($._script_vb, $.vb_code))),
|
|
233
|
+
alias($.script_end_tag, $.end_tag),
|
|
234
|
+
),
|
|
235
|
+
|
|
236
|
+
script_start_tag: ($) =>
|
|
237
|
+
seq('<', field('name', alias($.script_tag_name, $.tag_name)), repeat($._attribute), '>'),
|
|
238
|
+
|
|
239
|
+
script_end_tag: ($) => seq('</', field('name', alias($.script_tag_name, $.tag_name)), '>'),
|
|
240
|
+
|
|
241
|
+
script_tag_name: (_) => reserved('script'),
|
|
242
|
+
|
|
243
|
+
style_element: ($) =>
|
|
244
|
+
seq(
|
|
245
|
+
alias($.style_start_tag, $.start_tag),
|
|
246
|
+
optional($.style_text),
|
|
247
|
+
alias($.style_end_tag, $.end_tag),
|
|
248
|
+
),
|
|
249
|
+
|
|
250
|
+
style_start_tag: ($) =>
|
|
251
|
+
seq('<', field('name', alias($.style_tag_name, $.tag_name)), repeat($._attribute), '>'),
|
|
252
|
+
|
|
253
|
+
style_end_tag: ($) => seq('</', field('name', alias($.style_tag_name, $.tag_name)), '>'),
|
|
254
|
+
|
|
255
|
+
style_tag_name: (_) => reserved('style'),
|
|
256
|
+
|
|
257
|
+
void_element: ($) =>
|
|
258
|
+
seq(
|
|
259
|
+
'<',
|
|
260
|
+
field('name', alias($.void_tag_name, $.tag_name)),
|
|
261
|
+
repeat($._attribute),
|
|
262
|
+
choice('/>', '>'),
|
|
263
|
+
),
|
|
264
|
+
|
|
265
|
+
void_tag_name: (_) => choice(...VOID_TAGS.map((name) => reserved(name))),
|
|
266
|
+
|
|
267
|
+
self_closing_element: ($) => seq('<', field('name', $.tag_name), repeat($._attribute), '/>'),
|
|
268
|
+
|
|
269
|
+
element: ($) => seq($.start_tag, repeat($._content), $.end_tag),
|
|
270
|
+
|
|
271
|
+
start_tag: ($) => seq('<', field('name', $.tag_name), repeat($._attribute), '>'),
|
|
272
|
+
|
|
273
|
+
end_tag: ($) =>
|
|
274
|
+
seq(
|
|
275
|
+
'</',
|
|
276
|
+
field(
|
|
277
|
+
'name',
|
|
278
|
+
choice(
|
|
279
|
+
alias($.script_tag_name, $.tag_name),
|
|
280
|
+
alias($.style_tag_name, $.tag_name),
|
|
281
|
+
alias($.void_tag_name, $.tag_name),
|
|
282
|
+
$.tag_name,
|
|
283
|
+
),
|
|
284
|
+
),
|
|
285
|
+
'>',
|
|
286
|
+
),
|
|
287
|
+
|
|
288
|
+
tag_name: ($) => $._name,
|
|
289
|
+
|
|
290
|
+
doctype: ($) => seq($.doctype_token, optional(alias(/[^>]+/, $.doctype_declaration)), '>'),
|
|
291
|
+
|
|
292
|
+
doctype_token: (_) => token(prec(RESERVED, /<![Dd][Oo][Cc][Tt][Yy][Pp][Ee]/)),
|
|
293
|
+
|
|
294
|
+
text: (_) => /[^<\s][^<]*/,
|
|
295
|
+
},
|
|
296
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,70 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tree-sitter-aspx",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "Tree-sitter grammar for ASP.NET Web Forms markup",
|
|
5
|
+
"main": "bindings/node",
|
|
6
|
+
"types": "bindings/node",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"install": "node-gyp-build",
|
|
9
|
+
"prestart": "npx --yes --package=tree-sitter-cli@0.27.1 -- tree-sitter build --wasm",
|
|
10
|
+
"start": "npx --yes --package=tree-sitter-cli@0.27.1 -- tree-sitter playground",
|
|
11
|
+
"test": "node --test bindings/node/*_test.js",
|
|
12
|
+
"lint": "oxlint grammar.js tools bindings/node",
|
|
13
|
+
"format": "oxfmt \"grammar.js\" \"tools/*.mjs\" \"bindings/node/*.js\"",
|
|
14
|
+
"format:check": "oxfmt --check \"grammar.js\" \"tools/*.mjs\" \"bindings/node/*.js\""
|
|
15
|
+
},
|
|
16
|
+
"author": "M. Reifschneider",
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"node-addon-api": "8.9.2",
|
|
20
|
+
"node-gyp-build": "4.8.4"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"node-gyp": "13.1.0",
|
|
24
|
+
"oxfmt": "0.74.0",
|
|
25
|
+
"oxlint": "1.89.0",
|
|
26
|
+
"tree-sitter": "0.25.1",
|
|
27
|
+
"tree-sitter-cli": "0.27.1"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"tree-sitter": "^0.25.0"
|
|
31
|
+
},
|
|
32
|
+
"peerDependenciesMeta": {
|
|
33
|
+
"tree-sitter": {
|
|
34
|
+
"optional": true
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"gypfile": true,
|
|
38
|
+
"directories": {
|
|
39
|
+
"test": "test"
|
|
40
|
+
},
|
|
41
|
+
"type": "module",
|
|
42
|
+
"repository": {
|
|
43
|
+
"type": "git",
|
|
44
|
+
"url": "git+https://github.com/alfpricot/tree-sitter-aspx.git"
|
|
45
|
+
},
|
|
46
|
+
"bugs": {
|
|
47
|
+
"url": "https://github.com/alfpricot/tree-sitter-aspx/issues"
|
|
48
|
+
},
|
|
49
|
+
"homepage": "https://github.com/alfpricot/tree-sitter-aspx#readme",
|
|
50
|
+
"keywords": [
|
|
51
|
+
"parser",
|
|
52
|
+
"aspx",
|
|
53
|
+
"aspnet",
|
|
54
|
+
"tree-sitter"
|
|
55
|
+
],
|
|
56
|
+
"files": [
|
|
57
|
+
"grammar.js",
|
|
58
|
+
"binding.gyp",
|
|
59
|
+
"bindings/node/*",
|
|
60
|
+
"queries/*",
|
|
61
|
+
"src/**",
|
|
62
|
+
"prebuilds/**",
|
|
63
|
+
"tree-sitter.json",
|
|
64
|
+
"NOTICE"
|
|
65
|
+
],
|
|
66
|
+
"allowScripts": {
|
|
67
|
+
"tree-sitter-cli@0.27.1": true,
|
|
68
|
+
"tree-sitter@0.25.1": true
|
|
69
|
+
}
|
|
70
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
; Syntax highlighting for ASP.NET Web Forms markup.
|
|
2
|
+
|
|
3
|
+
(directive_name) @keyword
|
|
4
|
+
(tag_name) @tag
|
|
5
|
+
(attribute_name) @attribute
|
|
6
|
+
(attribute_value) @string
|
|
7
|
+
(language_value) @type
|
|
8
|
+
(doctype_token) @keyword
|
|
9
|
+
(doctype_declaration) @string
|
|
10
|
+
|
|
11
|
+
(server_comment) @comment
|
|
12
|
+
(server_comment_text) @comment
|
|
13
|
+
(html_comment) @comment
|
|
14
|
+
(comment_text) @comment
|
|
15
|
+
|
|
16
|
+
(text) @text
|
|
17
|
+
(style_text) @string
|
|
18
|
+
(expression_value) @string
|
|
19
|
+
|
|
20
|
+
["<%" "<%=" "<%:" "<%#" "<%$" "%>" "<%@" "<%--" "--%>"] @punctuation.special
|
|
21
|
+
["<" ">" "</" "/>"] @punctuation.bracket
|
|
22
|
+
["="] @operator
|