add inline identifiers

This commit is contained in:
Dmitriy Pleshevskiy 2022-12-04 03:36:46 +03:00
parent 5184b74138
commit 8fcd012702
Signed by: pleshevskiy
GPG key ID: 1B59187B161C0215
7 changed files with 668 additions and 481 deletions

View file

@ -1,2 +1,7 @@
a a <- b -- b
b
foo: Hello world {
shape: oval
}
hello world- -- foo

View file

@ -21,9 +21,17 @@ module.exports = grammar({
$._end $._end
), ),
shape: ($) => seq($.identifier, optional(seq(":", $.label)), $._end), shape: ($) =>
seq(
$.identifier,
repeat(seq($.dot, $.identifier)),
optional(seq(":", $.label)),
$._end
),
label: ($) => choice($.string, /[^\n;{]+/), dot: ($) => ".",
label: ($) => choice($.string, $._unquoted_string),
identifier: ($) => $._identifier, identifier: ($) => $._identifier,
@ -35,6 +43,8 @@ module.exports = grammar({
seq(repeat("-"), "->") seq(repeat("-"), "->")
), ),
_unquoted_string: ($) => /[^\n;{]+/,
string: ($) => string: ($) =>
choice( choice(
seq("'", repeat(token(/[^'\n]+/)), "'"), seq("'", repeat(token(/[^'\n]+/)), "'"),

View file

@ -106,6 +106,22 @@
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "identifier"
}, },
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "dot"
},
{
"type": "SYMBOL",
"name": "identifier"
}
]
}
},
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -133,6 +149,10 @@
} }
] ]
}, },
"dot": {
"type": "STRING",
"value": "."
},
"label": { "label": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -141,8 +161,8 @@
"name": "string" "name": "string"
}, },
{ {
"type": "PATTERN", "type": "SYMBOL",
"value": "[^\\n;{]+" "name": "_unquoted_string"
} }
] ]
}, },
@ -223,6 +243,10 @@
} }
] ]
}, },
"_unquoted_string": {
"type": "PATTERN",
"value": "[^\\n;{]+"
},
"string": { "string": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [

View file

@ -55,6 +55,10 @@
"multiple": true, "multiple": true,
"required": true, "required": true,
"types": [ "types": [
{
"type": "dot",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -133,5 +137,9 @@
{ {
"type": "`", "type": "`",
"named": false "named": false
},
{
"type": "dot",
"named": true
} }
] ]

File diff suppressed because it is too large Load diff

View file

@ -28,6 +28,7 @@ static bool scan_identifier(TSLexer *lexer) {
case ':': case ':':
case ';': case ';':
case '<': case '<':
case '.':
case '\n': case '\n':
case '\0': case '\0':
return has_content; return has_content;

View file

@ -26,6 +26,22 @@ Complex identifier
(shape (identifier)) (shape (identifier))
) )
==================
Inline shapes
==================
foo.baz
---
(source_file
(shape
(identifier)
(dot)
(identifier)
)
)
================== ==================
Many shapes inline Many shapes inline