parent
a1a2091ebf
commit
c8de4f83f0
6 changed files with 80 additions and 0 deletions
|
@ -19,11 +19,13 @@ module.exports = grammar({
|
|||
$._text_block_start,
|
||||
$._text_block_end,
|
||||
$._text_block_raw_text,
|
||||
$.block_comment,
|
||||
],
|
||||
|
||||
extras: ($) => [
|
||||
/[ \f\t\v\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]/,
|
||||
$.line_comment,
|
||||
$.block_comment,
|
||||
],
|
||||
|
||||
conflicts: ($) => [[$._connection_path, $.container]],
|
||||
|
|
|
@ -1393,6 +1393,10 @@
|
|||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "line_comment"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "block_comment"
|
||||
}
|
||||
],
|
||||
"conflicts": [
|
||||
|
@ -1414,6 +1418,10 @@
|
|||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_text_block_raw_text"
|
||||
},
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "block_comment"
|
||||
}
|
||||
],
|
||||
"inline": [],
|
||||
|
|
|
@ -360,6 +360,10 @@
|
|||
"type": "arrow",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "block_comment",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "border-radius",
|
||||
"named": false
|
||||
|
|
BIN
src/parser.c
BIN
src/parser.c
Binary file not shown.
|
@ -10,6 +10,7 @@ namespace {
|
|||
TEXT_BLOCK_START,
|
||||
TEXT_BLOCK_END,
|
||||
TEXT_BLOCK_RAW_TEXT,
|
||||
BLOCK_COMMENT,
|
||||
};
|
||||
|
||||
struct Scanner {
|
||||
|
@ -68,6 +69,17 @@ namespace {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool is_triple_double_quote(TSLexer *lexer) {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (lexer->lookahead != '"') {
|
||||
return false;
|
||||
}
|
||||
advance(lexer);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool scan(TSLexer *lexer, const bool *valid_symbols) {
|
||||
if (valid_symbols[TEXT_BLOCK_START] && escape_char_stack.empty()) {
|
||||
lexer->result_symbol = TEXT_BLOCK_START;
|
||||
|
@ -120,6 +132,25 @@ namespace {
|
|||
lexer->mark_end(lexer);
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (valid_symbols[BLOCK_COMMENT]) {
|
||||
lexer->result_symbol = BLOCK_COMMENT;
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
// Check start of block comment
|
||||
if (!is_triple_double_quote(lexer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Search end of block comment
|
||||
while (!is_triple_double_quote(lexer)) {
|
||||
// d2 expects closed tag for block comment
|
||||
if (lexer->lookahead == 0) return false;
|
||||
advance(lexer);
|
||||
}
|
||||
|
||||
lexer->mark_end(lexer);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -228,3 +228,38 @@ bar: |##md ## hello world ##|
|
|||
)
|
||||
)
|
||||
)
|
||||
|
||||
================================================================================
|
||||
Shape with oneline comment
|
||||
================================================================================
|
||||
foo # hello
|
||||
# world
|
||||
bar
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(shape (shape_key))
|
||||
(line_comment)
|
||||
(line_comment)
|
||||
(shape (shape_key))
|
||||
)
|
||||
|
||||
================================================================================
|
||||
Shape with block comment
|
||||
================================================================================
|
||||
foo
|
||||
|
||||
"""
|
||||
hello world
|
||||
"""
|
||||
|
||||
bar
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(source_file
|
||||
(shape (shape_key))
|
||||
(block_comment)
|
||||
(shape (shape_key))
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue