diff --git a/grammar.js b/grammar.js index c3b1737..a93f834 100644 --- a/grammar.js +++ b/grammar.js @@ -22,8 +22,6 @@ module.exports = grammar({ $.line_comment, ], - word: ($) => $._identifier, - conflicts: ($) => [[$._connection_path, $.container]], rules: { @@ -116,14 +114,17 @@ module.exports = grammar({ ) ), - shape_key: ($) => choice($.string, seq($._identifier, optional($._dash))), + shape_key: ($) => choice($.string, $._identifier), _identifier: ($) => - token( - prec( - PREC.IDENTIFIER, - /\-?([\w\d]+([\w\d`'"]+)?|([\w\d]+([\w\d `'"]+)?( +|\-)[\w\d]+([\w\d `'"]+)?)+)/ - ) + seq( + optional("-"), + /[\w\d$]/, + repeat( + token(prec(PREC.IDENTIFIER, /([\w\d'"$(),]+)?( +|-)[\w\d'"$()]+/)) + ), + optional(/[\w\d'"$()]+/), + optional($._dash) ), text_block: ($) => diff --git a/src/grammar.json b/src/grammar.json index 7854d60..51a09fd 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -1,6 +1,5 @@ { "name": "d2", - "word": "_identifier", "rules": { "source_file": { "type": "REPEAT", @@ -474,38 +473,69 @@ "name": "string" }, { - "type": "SEQ", - "members": [ - { - "type": "SYMBOL", - "name": "_identifier" - }, - { - "type": "CHOICE", - "members": [ - { - "type": "SYMBOL", - "name": "_dash" - }, - { - "type": "BLANK" - } - ] - } - ] + "type": "SYMBOL", + "name": "_identifier" } ] }, "_identifier": { - "type": "TOKEN", - "content": { - "type": "PREC", - "value": 0, - "content": { + "type": "SEQ", + "members": [ + { + "type": "CHOICE", + "members": [ + { + "type": "STRING", + "value": "-" + }, + { + "type": "BLANK" + } + ] + }, + { "type": "PATTERN", - "value": "\\-?([\\w\\d]+([\\w\\d`'\"]+)?|([\\w\\d]+([\\w\\d `'\"]+)?( +|\\-)[\\w\\d]+([\\w\\d `'\"]+)?)+)" + "value": "[\\w\\d$]" + }, + { + "type": "REPEAT", + "content": { + "type": "TOKEN", + "content": { + "type": "PREC", + "value": 0, + "content": { + "type": "PATTERN", + "value": "([\\w\\d'\"$(),]+)?( +|-)[\\w\\d'\"$()]+" + } + } + } + }, + { + "type": "CHOICE", + "members": [ + { + "type": "PATTERN", + "value": "[\\w\\d'\"$()]+" + }, + { + "type": "BLANK" + } + ] + }, + { + "type": "CHOICE", + "members": [ + { + "type": "SYMBOL", + "name": "_dash" + }, + { + "type": "BLANK" + } + ] } - } + ] }, "text_block": { "type": "CHOICE", @@ -1249,29 +1279,6 @@ "value": "\"" } ] - }, - { - "type": "SEQ", - "members": [ - { - "type": "STRING", - "value": "`" - }, - { - "type": "REPEAT", - "content": { - "type": "IMMEDIATE_TOKEN", - "content": { - "type": "PATTERN", - "value": "[^`\\n]+" - } - } - }, - { - "type": "STRING", - "value": "`" - } - ] } ] }, diff --git a/src/node-types.json b/src/node-types.json index 1512154..61493c8 100644 --- a/src/node-types.json +++ b/src/node-types.json @@ -322,6 +322,10 @@ "type": "'", "named": false }, + { + "type": "-", + "named": false + }, { "type": "3d", "named": false @@ -334,10 +338,6 @@ "type": ";", "named": false }, - { - "type": "`", - "named": false - }, { "type": "`|", "named": false diff --git a/src/parser.c b/src/parser.c index 81824c5..cde28cf 100644 Binary files a/src/parser.c and b/src/parser.c differ diff --git a/test/corpus/connection.txt b/test/corpus/connection.txt index 50ef980..e5c6df2 100644 --- a/test/corpus/connection.txt +++ b/test/corpus/connection.txt @@ -103,20 +103,24 @@ Complex identifier connection ================================================================================ Foo Bar -- Biz Baz -Bar-Foo- <- -Baz-Biz- +imAShape -- im_a_shape +im_a_shape -- im$AShape +im a shape -- i'm $a shape +i'm a shape -- a-sh$ape +a-shape -- im a sh$ape +foo' 'bar -- baz -------------------------------------------------------------------------------- (source_file - (connection - (shape_key) - (arrow) - (shape_key) - ) - (connection - (shape_key) - (arrow) - (shape_key) - ) + (connection (shape_key) (arrow) (shape_key)) + (connection (shape_key) (arrow) (shape_key)) + (connection (shape_key) (arrow) (shape_key)) + (connection (shape_key) (arrow) (shape_key)) + (connection (shape_key) (arrow) (shape_key)) + (connection (shape_key) (arrow) (shape_key)) + (connection (shape_key) (arrow) (shape_key)) + (connection (shape_key) (arrow) (shape_key)) ) ================================================================================ diff --git a/test/corpus/shape.txt b/test/corpus/shape.txt index 7413d6d..f1f6bb1 100644 --- a/test/corpus/shape.txt +++ b/test/corpus/shape.txt @@ -27,10 +27,11 @@ Complex shape key Foo bar -Biz-baz- imAShape -im_a_shape +im_a$_shape im a shape i'm a shape a-shape +changeTeam(member, props, ctx) -------------------------------------------------------------------------------- @@ -42,6 +43,7 @@ a-shape (shape (shape_key)) (shape (shape_key)) (shape (shape_key)) + (shape (shape_key)) ) ================================================================================ diff --git a/tree-sitter-d2.wasm b/tree-sitter-d2.wasm index 410e154..cd7e07b 100755 Binary files a/tree-sitter-d2.wasm and b/tree-sitter-d2.wasm differ