parent
612b7fb871
commit
d230155d48
6 changed files with 226 additions and 4 deletions
20
grammar.js
20
grammar.js
|
@ -1,6 +1,7 @@
|
|||
const PREC = {
|
||||
COMMENT: -2,
|
||||
EOL: -1,
|
||||
TEXT_BLOCK_CONTENT: -1,
|
||||
UNQUOTED_STRING: 0,
|
||||
CONTAINER: 2,
|
||||
CONNECTION: 2,
|
||||
|
@ -107,7 +108,7 @@ module.exports = grammar({
|
|||
optional(
|
||||
choice(
|
||||
seq($.dot, alias($._style_attribute, $.attribute)),
|
||||
seq(optional(seq($._colon, optional($.label))))
|
||||
seq(optional(seq($._colon, choice($.label, $.text_block))))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -123,6 +124,21 @@ module.exports = grammar({
|
|||
)
|
||||
),
|
||||
|
||||
text_block: ($) =>
|
||||
choice(
|
||||
seq("|", $._text_block_definition, "|"),
|
||||
// References: https://github.com/terrastruct/d2-vim
|
||||
seq("|`", $._text_block_definition, "`|")
|
||||
),
|
||||
|
||||
_text_block_definition: ($) =>
|
||||
seq(optional($.language), $._eol, optional($.text_block_content)),
|
||||
|
||||
text_block_content: ($) =>
|
||||
repeat1(token(prec(PREC.TEXT_BLOCK_CONTENT, /.*?[^`|]/))),
|
||||
|
||||
language: ($) => /\w+/,
|
||||
|
||||
// attributes
|
||||
|
||||
_root_attribute: ($) =>
|
||||
|
@ -260,7 +276,7 @@ module.exports = grammar({
|
|||
dot: ($) => token("."),
|
||||
|
||||
_unquoted_string: ($) =>
|
||||
token(prec(PREC.UNQUOTED_STRING, /[^'"`\n\s;{}]([^\n;{}]*[^\n\s;{}])?/)),
|
||||
token(prec(PREC.UNQUOTED_STRING, /[^'"`|\n\s;{}]([^\n;{}]*[^\n\s;{}])?/)),
|
||||
|
||||
string: ($) =>
|
||||
choice(
|
||||
|
|
|
@ -442,7 +442,8 @@
|
|||
"name": "label"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
"type": "SYMBOL",
|
||||
"name": "text_block"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -506,6 +507,96 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"text_block": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "|"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_text_block_definition"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "|"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "|`"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_text_block_definition"
|
||||
},
|
||||
{
|
||||
"type": "STRING",
|
||||
"value": "`|"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"_text_block_definition": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "language"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_eol"
|
||||
},
|
||||
{
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "text_block_content"
|
||||
},
|
||||
{
|
||||
"type": "BLANK"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"text_block_content": {
|
||||
"type": "REPEAT1",
|
||||
"content": {
|
||||
"type": "TOKEN",
|
||||
"content": {
|
||||
"type": "PREC",
|
||||
"value": -1,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": ".*?[^`|]"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"language": {
|
||||
"type": "PATTERN",
|
||||
"value": "\\w+"
|
||||
},
|
||||
"_root_attribute": {
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
|
@ -1103,7 +1194,7 @@
|
|||
"value": 0,
|
||||
"content": {
|
||||
"type": "PATTERN",
|
||||
"value": "[^'\"`\\n\\s;{}]([^\\n;{}]*[^\\n\\s;{}])?"
|
||||
"value": "[^'\"`|\\n\\s;{}]([^\\n;{}]*[^\\n\\s;{}])?"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -219,6 +219,10 @@
|
|||
{
|
||||
"type": "shape_key",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "text_block",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -270,6 +274,30 @@
|
|||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "text_block",
|
||||
"named": true,
|
||||
"fields": {},
|
||||
"children": {
|
||||
"multiple": true,
|
||||
"required": false,
|
||||
"types": [
|
||||
{
|
||||
"type": "language",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "text_block_content",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "text_block_content",
|
||||
"named": true,
|
||||
"fields": {}
|
||||
},
|
||||
{
|
||||
"type": "\u0000",
|
||||
"named": false
|
||||
|
@ -298,6 +326,10 @@
|
|||
"type": "`",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "`|",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "animated",
|
||||
"named": false
|
||||
|
@ -342,6 +374,10 @@
|
|||
"type": "label",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "language",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "line_comment",
|
||||
"named": true
|
||||
|
@ -394,6 +430,14 @@
|
|||
"type": "{",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "|",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "|`",
|
||||
"named": false
|
||||
},
|
||||
{
|
||||
"type": "}",
|
||||
"named": false
|
||||
|
|
BIN
src/parser.c
BIN
src/parser.c
Binary file not shown.
|
@ -109,3 +109,74 @@ Use quoted string as shape key and label
|
|||
(shape (shape_key (string)) (label (string)))
|
||||
)
|
||||
|
||||
================================================================================
|
||||
Basic text block
|
||||
================================================================================
|
||||
foo: |
|
||||
- hello
|
||||
|
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(shape
|
||||
(shape_key)
|
||||
(text_block
|
||||
(text_block_content)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
================================================================================
|
||||
Text block with specific language
|
||||
================================================================================
|
||||
foo: |go
|
||||
|
||||
awsSession := From(c.Request.Context())
|
||||
|
||||
client := s3.New(awsSession)
|
||||
|
||||
|
||||
ctx, cancelFn := context.WithTimeout(c.Request.Context(), AWS_TIMEOUT)
|
||||
|
||||
defer cancelFn()
|
||||
|
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(shape
|
||||
(shape_key)
|
||||
(text_block
|
||||
(language)
|
||||
(text_block_content)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
================================================================================
|
||||
Text block with quotes (d2-vim style)
|
||||
================================================================================
|
||||
foo: |`go
|
||||
|
||||
awsSession := From(c.Request.Context())
|
||||
|
||||
client := s3.New(awsSession)
|
||||
|
||||
|
||||
ctx, cancelFn := context.WithTimeout(c.Request.Context(), AWS_TIMEOUT)
|
||||
|
||||
defer cancelFn()
|
||||
`|
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(shape
|
||||
(shape_key)
|
||||
(text_block
|
||||
(language)
|
||||
(text_block_content)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue