add inline identifiers
This commit is contained in:
parent
5184b74138
commit
8fcd012702
7 changed files with 668 additions and 481 deletions
|
@ -1,2 +1,7 @@
|
|||
a
|
||||
b
|
||||
a <- b -- b
|
||||
|
||||
foo: Hello world {
|
||||
shape: oval
|
||||
}
|
||||
|
||||
hello world- -- foo
|
||||
|
|
14
grammar.js
14
grammar.js
|
@ -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]+/)), "'"),
|
||||
|
|
|
@ -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": [
|
||||
|
|
|
@ -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
|
||||
}
|
||||
]
|
1073
src/parser.c
1073
src/parser.c
File diff suppressed because it is too large
Load diff
|
@ -28,6 +28,7 @@ static bool scan_identifier(TSLexer *lexer) {
|
|||
case ':':
|
||||
case ';':
|
||||
case '<':
|
||||
case '.':
|
||||
case '\n':
|
||||
case '\0':
|
||||
return has_content;
|
||||
|
|
|
@ -26,6 +26,22 @@ Complex identifier
|
|||
(shape (identifier))
|
||||
)
|
||||
|
||||
==================
|
||||
Inline shapes
|
||||
==================
|
||||
|
||||
foo.baz
|
||||
|
||||
---
|
||||
|
||||
(source_file
|
||||
(shape
|
||||
(identifier)
|
||||
(dot)
|
||||
(identifier)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
==================
|
||||
Many shapes inline
|
||||
|
|
Loading…
Reference in a new issue