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
b
a <- b -- b
foo: Hello world {
shape: oval
}
hello world- -- foo

View File

@ -21,9 +21,17 @@ module.exports = grammar({
$._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,
@ -35,6 +43,8 @@ module.exports = grammar({
seq(repeat("-"), "->")
),
_unquoted_string: ($) => /[^\n;{]+/,
string: ($) =>
choice(
seq("'", repeat(token(/[^'\n]+/)), "'"),

View File

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

View File

@ -55,6 +55,10 @@
"multiple": true,
"required": true,
"types": [
{
"type": "dot",
"named": true
},
{
"type": "identifier",
"named": true
@ -133,5 +137,9 @@
{
"type": "`",
"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 '\n':
case '\0':
return has_content;

View File

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