Skip to content

Commit

Permalink
refactor: key value
Browse files Browse the repository at this point in the history
  • Loading branch information
polarmutex committed Jan 28, 2023
1 parent 2940879 commit 8ee962c
Show file tree
Hide file tree
Showing 7 changed files with 3,794 additions and 3,766 deletions.
38 changes: 22 additions & 16 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ module.exports = grammar({
number: $ => token(/([0-9]+|[0-9][0-9,]+[0-9])(\.[0-9]*)?/),
tag: $ => token(/#[A-Za-z0-9\-_/.]+/),
link: $ => token(/\^[A-Za-z0-9\-_/.]+/),
key: $ => token(/[a-z][a-zA-Z0-9\-_]+/),

/* Operator precedence.
* This is pulled straight out of the textbook example:
Expand Down Expand Up @@ -208,7 +207,7 @@ module.exports = grammar({
$.tags_links,
$._eol
),
$.key_value_line,
$._key_value_line,
$.posting,
seq(
$._indent,
Expand Down Expand Up @@ -284,20 +283,9 @@ module.exports = grammar({
)
),

key_value: $ =>
prec.left(seq(
$.key,
":",
$._key_value_value,
)),

key_value_line: $ => seq(
$._indent,
$.key_value,
$._eol
),
key: $ => token(/[a-z][a-zA-Z0-9\-_]+/),

_key_value_value: $ =>
value: $ =>
choice(
$.string,
$.account,
Expand All @@ -310,6 +298,24 @@ module.exports = grammar({
$.amount
),

key_value: $ =>
prec.left(seq(
$.key,
":",
$.value,
)),

_key_value_line: $ => seq(
$._indent,
/*prec.left(seq(
$.key,
":",
$.value,
)),*/
$.key_value,
$._eol
),

// OPTIONAL
_key_value_list: $ =>
repeat1(
Expand All @@ -319,7 +325,7 @@ module.exports = grammar({
$._eol
),
seq(
$.key_value_line
$._key_value_line
)
)
),
Expand Down
90 changes: 45 additions & 45 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,6 @@
"value": "\\^[A-Za-z0-9\\-_/.]+"
}
},
"key": {
"type": "TOKEN",
"content": {
"type": "PATTERN",
"value": "[a-z][a-zA-Z0-9\\-_]+"
}
},
"txn": {
"type": "CHOICE",
"members": [
Expand Down Expand Up @@ -634,7 +627,7 @@
},
{
"type": "SYMBOL",
"name": "key_value_line"
"name": "_key_value_line"
},
{
"type": "SYMBOL",
Expand Down Expand Up @@ -1057,45 +1050,14 @@
}
]
},
"key_value": {
"type": "PREC_LEFT",
"value": 0,
"key": {
"type": "TOKEN",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "key"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "_key_value_value"
}
]
"type": "PATTERN",
"value": "[a-z][a-zA-Z0-9\\-_]+"
}
},
"key_value_line": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_indent"
},
{
"type": "SYMBOL",
"name": "key_value"
},
{
"type": "SYMBOL",
"name": "_eol"
}
]
},
"_key_value_value": {
"value": {
"type": "CHOICE",
"members": [
{
Expand Down Expand Up @@ -1136,6 +1098,44 @@
}
]
},
"key_value": {
"type": "PREC_LEFT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "key"
},
{
"type": "STRING",
"value": ":"
},
{
"type": "SYMBOL",
"name": "value"
}
]
}
},
"_key_value_line": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_indent"
},
{
"type": "SYMBOL",
"name": "key_value"
},
{
"type": "SYMBOL",
"name": "_eol"
}
]
},
"_key_value_list": {
"type": "REPEAT1",
"content": {
Expand All @@ -1159,7 +1159,7 @@
"members": [
{
"type": "SYMBOL",
"name": "key_value_line"
"name": "_key_value_line"
}
]
}
Expand Down
Loading

0 comments on commit 8ee962c

Please sign in to comment.