Skip to content

Commit 63c9563

Browse files
committed
feat: add fields to (document)
1 parent 447fedf commit 63c9563

File tree

6 files changed

+18104
-18075
lines changed

6 files changed

+18104
-18075
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Text
4545
Parses as:
4646
```
4747
(document [0, 0] - [16, 0]
48-
(body [0, 0] - [4, 0]
48+
body: (body [0, 0] - [4, 0]
4949
directive: (directive [0, 0] - [1, 0]
5050
name: (expr [0, 2] - [0, 7])
5151
value: (value [0, 9] - [0, 16]
@@ -55,7 +55,7 @@ Parses as:
5555
(expr [2, 5] - [2, 12])
5656
(expr [2, 13] - [2, 16])
5757
(expr [2, 17] - [2, 22])))
58-
(section [4, 0] - [16, 0]
58+
subsection: (section [4, 0] - [16, 0]
5959
headline: (headline [4, 0] - [5, 0]
6060
stars: (stars [4, 0] - [4, 1])
6161
item: (item [4, 2] - [4, 12]
@@ -110,7 +110,6 @@ Parses as:
110110
body: (body [14, 0] - [16, 0]
111111
(paragraph [15, 0] - [16, 0]
112112
(expr [15, 0] - [15, 4]))))))
113-
114113
```
115114

116115
## Install

corpus/basic.tst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ DynamicBlock.1 - Empty
412412
--------------------------------------------------------------------------------
413413

414414
(document
415-
(body
415+
body: (body
416416
(dynamic_block
417417
name: (expr)
418418
parameter: (expr))))
@@ -426,7 +426,7 @@ c
426426
--------------------------------------------------------------------------------
427427

428428
(document
429-
(body
429+
body: (body
430430
(dynamic_block
431431
name: (expr)
432432
contents: (contents

grammar.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ org_grammar = {
5353

5454
rules: {
5555

56-
document: $ => seq(optional($.body), repeat($.section)),
56+
document: $ => seq(
57+
optional(field('body', $.body)),
58+
repeat(field('subsection', $.section)),
59+
),
5760

5861
// Set up to prevent lexing conflicts of having two paragraphs in a row
5962
body: $ => $._body_contents,

src/grammar.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,12 @@
88
"type": "CHOICE",
99
"members": [
1010
{
11-
"type": "SYMBOL",
12-
"name": "body"
11+
"type": "FIELD",
12+
"name": "body",
13+
"content": {
14+
"type": "SYMBOL",
15+
"name": "body"
16+
}
1317
},
1418
{
1519
"type": "BLANK"
@@ -19,8 +23,12 @@
1923
{
2024
"type": "REPEAT",
2125
"content": {
22-
"type": "SYMBOL",
23-
"name": "section"
26+
"type": "FIELD",
27+
"name": "subsection",
28+
"content": {
29+
"type": "SYMBOL",
30+
"name": "section"
31+
}
2432
}
2533
}
2634
]

src/node-types.json

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -193,20 +193,27 @@
193193
{
194194
"type": "document",
195195
"named": true,
196-
"fields": {},
197-
"children": {
198-
"multiple": true,
199-
"required": false,
200-
"types": [
201-
{
202-
"type": "body",
203-
"named": true
204-
},
205-
{
206-
"type": "section",
207-
"named": true
208-
}
209-
]
196+
"fields": {
197+
"body": {
198+
"multiple": false,
199+
"required": false,
200+
"types": [
201+
{
202+
"type": "body",
203+
"named": true
204+
}
205+
]
206+
},
207+
"subsection": {
208+
"multiple": true,
209+
"required": false,
210+
"types": [
211+
{
212+
"type": "section",
213+
"named": true
214+
}
215+
]
216+
}
210217
}
211218
},
212219
{

0 commit comments

Comments
 (0)