Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add raw string parsing to external scanner #10

Merged
merged 2 commits into from
Feb 1, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: 16
node-version: 18
- run: npm install
- run: npm test

Expand All @@ -29,6 +29,6 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v2
with:
node-version: 16
node-version: 18
- run: npm install
- run: npm run-script test-windows
4 changes: 2 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- run: npm install
- run: npm test

Expand Down Expand Up @@ -54,7 +54,7 @@ jobs:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
registry-url: https://registry.npmjs.org/
- run: npm publish
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- run: npm install
- run: npm test

Expand Down
23 changes: 5 additions & 18 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ module.exports = grammar({
[$.node_children],
],

externals: $ => [$._eof, $.multi_line_comment],
externals: $ => [
$._eof,
$.multi_line_comment,
$._raw_string,
],

extras: $ => [$.multi_line_comment],

Expand Down Expand Up @@ -182,23 +186,6 @@ module.exports = grammar({
// hex-digit := [0-9a-fA-F]
_hex_digit: _ => /[0-9a-fA-F]/,

// // raw-string := 'r' raw-string-hash
// raw_string: $ => seq('r', $._raw_string_hash),
// // raw-string-hash := '#' raw-string-hash '#' | raw-string-quotes
// _raw_string_hash: $ => choice(seq('#', $._raw_string_hash, '#'), $._raw_string_quotes),
// // raw-string-quotes := '"' .* '"'
// _raw_string_quotes: _ => seq('"', /.*/, '"'),
_raw_string: _ =>
seq(
choice(
// raw-string-hash := '#' raw-string-hash '#' | raw-string-quotes
// yes this isn't perfect but it works, ideally this should be handled in an external scanner
seq(token.immediate(seq('r', repeat1('#'))), /[^#]*/, repeat1('#')),
// raw-string-quotes := '"' . '"'
seq(token.immediate(seq('r', '"')), /[^"]*/, '"'),
),
),

// number := decimal | hex | octal | binary
number: $ => choice($._decimal, $._hex, $._octal, $._binary),

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
},
"homepage": "https://github.com/amaanq/tree-sitter-kdl#readme",
"dependencies": {
"nan": "^2.17.0"
"nan": "^2.18.0"
},
"devDependencies": {
"eslint": "^8.40.0",
"eslint": "^8.56.0",
"eslint-config-google": "^0.14.0",
"tree-sitter-cli": "^0.20.8"
"tree-sitter-cli": "^0.20.8",
"node-gyp": "^10.0.1"
},
"repository": "https://github.com/amaanq/tree-sitter-kdl",
"scripts": {
Expand Down
78 changes: 4 additions & 74 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -786,80 +786,6 @@
"type": "PATTERN",
"value": "[0-9a-fA-F]"
},
"_raw_string": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "r"
},
{
"type": "REPEAT1",
"content": {
"type": "STRING",
"value": "#"
}
}
]
}
},
{
"type": "PATTERN",
"value": "[^#]*"
},
{
"type": "REPEAT1",
"content": {
"type": "STRING",
"value": "#"
}
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "r"
},
{
"type": "STRING",
"value": "\""
}
]
}
},
{
"type": "PATTERN",
"value": "[^\"]*"
},
{
"type": "STRING",
"value": "\""
}
]
}
]
}
]
},
"number": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -1330,6 +1256,10 @@
{
"type": "SYMBOL",
"name": "multi_line_comment"
},
{
"type": "SYMBOL",
"name": "_raw_string"
}
],
"inline": [],
Expand Down
4 changes: 0 additions & 4 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,6 @@
"type": "\"",
"named": false
},
{
"type": "#",
"named": false
},
{
"type": "(",
"named": false
Expand Down
Loading
Loading