Skip to content

Commit

Permalink
fix(ast): don't make the separator a part of key
Browse files Browse the repository at this point in the history
  • Loading branch information
vhyrro committed Nov 11, 2021
1 parent 7c9057c commit bf5a57d
Show file tree
Hide file tree
Showing 4 changed files with 517 additions and 460 deletions.
20 changes: 11 additions & 9 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,28 @@ module.exports = grammar({
),

pair: $ => seq(
$.key,
$._key,
token.immediate(/[ \t\v]*/),
choice(
$.value,
$.object,
$.array,
token.immediate('\n'),
),
),

key: $ => seq(
/[^\s:]+/,
key: $ => /[^\s:]+/,

_key: $ => seq(
$.key,
$._separator
),

value: $ => choice(
seq(
optional(
repeat($._text_with_trailing_modifier)
),
$._text_till_eol
value: $ => seq(
optional(
repeat($._text_with_trailing_modifier)
),
$._text_till_eol
),

object: $ => seq(
Expand Down
53 changes: 33 additions & 20 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
"members": [
{
"type": "SYMBOL",
"name": "key"
"name": "_key"
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[ \\t\\v]*"
}
},
{
"type": "CHOICE",
Expand All @@ -38,17 +45,28 @@
{
"type": "SYMBOL",
"name": "array"
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "STRING",
"value": "\n"
}
}
]
}
]
},
"key": {
"type": "PATTERN",
"value": "[^\\s:]+"
},
"_key": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "[^\\s:]+"
"type": "SYMBOL",
"name": "key"
},
{
"type": "SYMBOL",
Expand All @@ -57,31 +75,26 @@
]
},
"value": {
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "SEQ",
"type": "CHOICE",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_text_with_trailing_modifier"
}
},
{
"type": "BLANK"
}
]
"type": "REPEAT",
"content": {
"type": "SYMBOL",
"name": "_text_with_trailing_modifier"
}
},
{
"type": "SYMBOL",
"name": "_text_till_eol"
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "_text_till_eol"
}
]
},
Expand Down
13 changes: 8 additions & 5 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
]
}
},
{
"type": "key",
"named": true,
"fields": {}
},
{
"type": "metadata",
"named": true,
Expand Down Expand Up @@ -106,6 +101,10 @@
"named": true,
"fields": {}
},
{
"type": "\n",
"named": false
},
{
"type": "[",
"named": false
Expand All @@ -114,6 +113,10 @@
"type": "]",
"named": false
},
{
"type": "key",
"named": true
},
{
"type": "{",
"named": false
Expand Down
Loading

0 comments on commit bf5a57d

Please sign in to comment.