Skip to content

Commit

Permalink
feat: veeery crude named delimiter support
Browse files Browse the repository at this point in the history
  • Loading branch information
mrossinek committed Nov 9, 2021
1 parent 7268ed1 commit 17741af
Show file tree
Hide file tree
Showing 5 changed files with 496 additions and 190 deletions.
24 changes: 21 additions & 3 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ module.exports = grammar({

statement: $ => seq(
$.keyword,
$._separator,
$._space,
$.value
),

keyword: $ => /[^\s:]+/,
keyword: $ => seq(
/[^\s:]+/,
$._separator
),

value: $ => seq(
optional(
Expand All @@ -25,7 +27,23 @@ module.exports = grammar({
$._text_till_eol
),

delimiter: $ => /---+\n/,
delimiter: $ => choice(
$._delimiter,
$.named_delimiter
),

_delimiter: $ => /---+\n/,

named_delimiter: $ => prec(3, seq(
/---+\s*/,
prec.left(2,
seq(
field("title", /[^-]+/),
/\s*/
)
),
$._delimiter,
)),

_separator: $ => ":",

Expand Down
68 changes: 62 additions & 6 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
"type": "SYMBOL",
"name": "keyword"
},
{
"type": "SYMBOL",
"name": "_separator"
},
{
"type": "SYMBOL",
"name": "_space"
Expand All @@ -39,8 +35,17 @@
]
},
"keyword": {
"type": "PATTERN",
"value": "[^\\s:]+"
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[^\\s:]+"
},
{
"type": "SYMBOL",
"name": "_separator"
}
]
},
"value": {
"type": "SEQ",
Expand All @@ -67,9 +72,60 @@
]
},
"delimiter": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "_delimiter"
},
{
"type": "SYMBOL",
"name": "named_delimiter"
}
]
},
"_delimiter": {
"type": "PATTERN",
"value": "---+\\n"
},
"named_delimiter": {
"type": "PREC",
"value": 3,
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "---+\\s*"
},
{
"type": "PREC_LEFT",
"value": 2,
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "title",
"content": {
"type": "PATTERN",
"value": "[^-]+"
}
},
{
"type": "PATTERN",
"value": "\\s*"
}
]
}
},
{
"type": "SYMBOL",
"name": "_delimiter"
}
]
}
},
"_separator": {
"type": "STRING",
"value": ":"
Expand Down
33 changes: 25 additions & 8 deletions src/node-types.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
[
{
"type": "delimiter",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "named_delimiter",
"named": true
}
]
}
},
{
"type": "keyword",
"named": true,
"fields": {}
},
{
"type": "metadata",
"named": true,
Expand All @@ -18,6 +38,11 @@
]
}
},
{
"type": "named_delimiter",
"named": true,
"fields": {}
},
{
"type": "statement",
"named": true,
Expand All @@ -42,14 +67,6 @@
"named": true,
"fields": {}
},
{
"type": "delimiter",
"named": true
},
{
"type": "keyword",
"named": true
},
{
"type": "~\n",
"named": false
Expand Down
Loading

0 comments on commit 17741af

Please sign in to comment.