Skip to content

Commit 9a595e5

Browse files
committed
feat!: match elements in list items, remove (itemtext)
BREAKING CHANGE: (itemtext) removed, typically in favor of (paragraph) as the listitem should now be parsed via (body) logic.
1 parent 7f9a7e5 commit 9a595e5

File tree

8 files changed

+40109
-18217
lines changed

8 files changed

+40109
-18217
lines changed

corpus/basic.tst

Lines changed: 50 additions & 227 deletions
Large diffs are not rendered by default.

grammar.js

Lines changed: 16 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ org_grammar = {
2222
$._eol,
2323
$._ts_contents,
2424
$._directive_list,
25+
$._body_contents,
2526
],
2627

2728
precedences: _ => [
@@ -44,7 +45,7 @@ org_grammar = {
4445
[$.expr, $.drawer],
4546

4647
// headline 'entry_token1' ':' • '<' …
47-
[$.entry, $.expr]
48+
[$.entry, $.expr],
4849

4950
],
5051

@@ -53,7 +54,9 @@ org_grammar = {
5354
document: $ => seq(optional($.body), repeat($.section)),
5455

5556
// Set up to prevent lexing conflicts of having two paragraphs in a row
56-
body: $ => choice(
57+
body: $ => $._body_contents,
58+
59+
_body_contents: $ => choice(
5760
repeat1($._nl),
5861
seq(repeat($._nl), $._multis),
5962
seq(
@@ -229,38 +232,24 @@ org_grammar = {
229232
list: $ => seq(
230233
optional($._directive_list),
231234
$._liststart, // captures indent length and bullet type
232-
repeat(seq($.listitem, $._listitemend, repeat1($._nl))),
235+
repeat(seq($.listitem, $._listitemend, repeat($._nl))),
233236
seq($.listitem, $._listend)
234237
),
235238

236239
listitem: $ => seq(
237240
$.bullet,
238-
optional(field('checkbox', $.checkbox)),
239-
optional(seq(alias(optional($._expr_line), $.description), '::')),
240-
optional($.itemtext),
241-
),
242-
243-
checkbox: _ => seq(
244-
token(prec('non-immediate', '[')), // ]
245-
field(
246-
'status',
247-
choice(
248-
token.immediate(' '),
249-
token.immediate('-'),
250-
token.immediate('x'),
251-
token.immediate('X'),
252-
token.immediate(/./),
253-
)),
254-
token(prec('special', ']')), // [.] could be an (expr)
241+
choice(
242+
$._eof,
243+
alias($.body, "item_body"),
244+
)
255245
),
256246

257-
itemtext: $ => seq(
258-
$._expr_line,
259-
repeat(seq(
260-
$._nl,
261-
optional($._nl),
262-
choice($._expr_line, $.list)
263-
)),
247+
listitem: $ => seq(
248+
field('bullet', $.bullet),
249+
choice(
250+
$._eof,
251+
field('contents', $._body_contents),
252+
),
264253
),
265254

266255
table: $ => prec.right(seq(

queries/highlights.scm

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
; Match cookies in a headline or listitem. If you want the numbers
2121
; differently highlighted from the borders, add a capture name to "num".
22-
([ (item) (itemtext) ] (expr "[" "num"? @OrgCookieNum "/" "num"? @OrgCookieNum "]" ) @OrgProgressCookie (#match? @OrgProgressCookie "^\[\d*/\d*\]$"))
23-
([ (item) (itemtext) ] (expr "[" "num"? @OrgCookieNum "%" "]" ) @OrgPercentCookie (#match? @OrgPercentCookie "^\[\d*%\]$"))
22+
; ([ (item) (itemtext) ] (expr "[" "num"? @OrgCookieNum "/" "num"? @OrgCookieNum "]" ) @OrgProgressCookie (#match? @OrgProgressCookie "^\[\d*/\d*\]$"))
23+
; ([ (item) (itemtext) ] (expr "[" "num"? @OrgCookieNum "%" "]" ) @OrgPercentCookie (#match? @OrgPercentCookie "^\[\d*%\]$"))
2424

2525
(tag_list (tag) @OrgTag) @OrgTagList
2626

@@ -59,12 +59,12 @@
5959

6060
; Can match different styles with a (#match?) or (#eq?) predicate if desired
6161
(bullet) @OrgListBullet
62-
(listitem (description) @OrgListDescription)
6362

6463
; Get different colors for different statuses as follows
65-
(checkbox) @OrgCheckbox
66-
(checkbox status: [ "x" "X" ] @OrgCheckDone)
67-
(checkbox status: "-" @OrgCheckInProgress)
64+
(listitem . (bullet) . (paragraph . (expr "[" "str" @OrgCheckDone "]") @OrgCheckbox (#match? @OrgCheckbox "^\[[xX]\]$")))
65+
(listitem . (bullet) . (paragraph . (expr "[" "-" @OrgCheckInProgress "]") @OrgCheckbox (#eq? @OrgCheckbox "[-]")))
66+
(listitem . (bullet) . (paragraph . (expr "[") @OrgCheckbox.left (#eq? @OrgCheckbox.left "[") . (expr "]") @OrgCheckbox.right (#eq? @OrgCheckbox.right "]")))
67+
; (listitem . (bullet) . (paragraph (expr ":" ":") @OrgListDescriptionSeparator (#eq? @OrgListDescriptionSeparator "::"))) -- matches multiple, requires a special search.
6868

6969
; If you want the ruler one color and the separators a different color,
7070
; something like this would do it:

queries/markup.scm

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,6 @@
1313
(expr "+" @strikethrough.start "+" @strikethrough.end)
1414
])
1515

16-
; listitem text
17-
(itemtext [
18-
((expr "*" @bold.start) (expr "*" @bold.end))
19-
(expr "*" @bold.start "*" @bold.end)
20-
((expr "~" @code.start) (expr "~" @code.end))
21-
(expr "~" @code.start "~" @code.end)
22-
((expr "/" @italic.start) (expr "/" @italic.end))
23-
(expr "/" @italic.start "/" @italic.end)
24-
((expr "_" @underline.start) (expr "_" @underline.end))
25-
(expr "_" @underline.start "_" @underline.end)
26-
((expr "=" @verbatim.start) (expr "=" @verbatim.end))
27-
(expr "=" @verbatim.start "=" @verbatim.end)
28-
((expr "+" @strikethrough.start) (expr "+" @strikethrough.end))
29-
(expr "+" @strikethrough.start "+" @strikethrough.end)
30-
])
31-
3216
; headline item
3317
(item [
3418
((expr "*" @bold.start) (expr "*" @bold.end))

src/grammar.json

Lines changed: 19 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
]
2727
},
2828
"body": {
29+
"type": "SYMBOL",
30+
"name": "_body_contents"
31+
},
32+
"_body_contents": {
2933
"type": "CHOICE",
3034
"members": [
3135
{
@@ -1306,7 +1310,7 @@
13061310
"name": "_listitemend"
13071311
},
13081312
{
1309-
"type": "REPEAT1",
1313+
"type": "REPEAT",
13101314
"content": {
13111315
"type": "SYMBOL",
13121316
"name": "_nl"
@@ -1334,187 +1338,29 @@
13341338
"type": "SEQ",
13351339
"members": [
13361340
{
1337-
"type": "SYMBOL",
1338-
"name": "bullet"
1341+
"type": "FIELD",
1342+
"name": "bullet",
1343+
"content": {
1344+
"type": "SYMBOL",
1345+
"name": "bullet"
1346+
}
13391347
},
13401348
{
13411349
"type": "CHOICE",
13421350
"members": [
1351+
{
1352+
"type": "SYMBOL",
1353+
"name": "_eof"
1354+
},
13431355
{
13441356
"type": "FIELD",
1345-
"name": "checkbox",
1357+
"name": "contents",
13461358
"content": {
13471359
"type": "SYMBOL",
1348-
"name": "checkbox"
1360+
"name": "_body_contents"
13491361
}
1350-
},
1351-
{
1352-
"type": "BLANK"
13531362
}
13541363
]
1355-
},
1356-
{
1357-
"type": "CHOICE",
1358-
"members": [
1359-
{
1360-
"type": "SEQ",
1361-
"members": [
1362-
{
1363-
"type": "ALIAS",
1364-
"content": {
1365-
"type": "CHOICE",
1366-
"members": [
1367-
{
1368-
"type": "SYMBOL",
1369-
"name": "_expr_line"
1370-
},
1371-
{
1372-
"type": "BLANK"
1373-
}
1374-
]
1375-
},
1376-
"named": true,
1377-
"value": "description"
1378-
},
1379-
{
1380-
"type": "STRING",
1381-
"value": "::"
1382-
}
1383-
]
1384-
},
1385-
{
1386-
"type": "BLANK"
1387-
}
1388-
]
1389-
},
1390-
{
1391-
"type": "CHOICE",
1392-
"members": [
1393-
{
1394-
"type": "SYMBOL",
1395-
"name": "itemtext"
1396-
},
1397-
{
1398-
"type": "BLANK"
1399-
}
1400-
]
1401-
}
1402-
]
1403-
},
1404-
"checkbox": {
1405-
"type": "SEQ",
1406-
"members": [
1407-
{
1408-
"type": "TOKEN",
1409-
"content": {
1410-
"type": "PREC",
1411-
"value": "non-immediate",
1412-
"content": {
1413-
"type": "STRING",
1414-
"value": "["
1415-
}
1416-
}
1417-
},
1418-
{
1419-
"type": "FIELD",
1420-
"name": "status",
1421-
"content": {
1422-
"type": "CHOICE",
1423-
"members": [
1424-
{
1425-
"type": "IMMEDIATE_TOKEN",
1426-
"content": {
1427-
"type": "STRING",
1428-
"value": " "
1429-
}
1430-
},
1431-
{
1432-
"type": "IMMEDIATE_TOKEN",
1433-
"content": {
1434-
"type": "STRING",
1435-
"value": "-"
1436-
}
1437-
},
1438-
{
1439-
"type": "IMMEDIATE_TOKEN",
1440-
"content": {
1441-
"type": "STRING",
1442-
"value": "x"
1443-
}
1444-
},
1445-
{
1446-
"type": "IMMEDIATE_TOKEN",
1447-
"content": {
1448-
"type": "STRING",
1449-
"value": "X"
1450-
}
1451-
},
1452-
{
1453-
"type": "IMMEDIATE_TOKEN",
1454-
"content": {
1455-
"type": "PATTERN",
1456-
"value": "."
1457-
}
1458-
}
1459-
]
1460-
}
1461-
},
1462-
{
1463-
"type": "TOKEN",
1464-
"content": {
1465-
"type": "PREC",
1466-
"value": "special",
1467-
"content": {
1468-
"type": "STRING",
1469-
"value": "]"
1470-
}
1471-
}
1472-
}
1473-
]
1474-
},
1475-
"itemtext": {
1476-
"type": "SEQ",
1477-
"members": [
1478-
{
1479-
"type": "SYMBOL",
1480-
"name": "_expr_line"
1481-
},
1482-
{
1483-
"type": "REPEAT",
1484-
"content": {
1485-
"type": "SEQ",
1486-
"members": [
1487-
{
1488-
"type": "SYMBOL",
1489-
"name": "_nl"
1490-
},
1491-
{
1492-
"type": "CHOICE",
1493-
"members": [
1494-
{
1495-
"type": "SYMBOL",
1496-
"name": "_nl"
1497-
},
1498-
{
1499-
"type": "BLANK"
1500-
}
1501-
]
1502-
},
1503-
{
1504-
"type": "CHOICE",
1505-
"members": [
1506-
{
1507-
"type": "SYMBOL",
1508-
"name": "_expr_line"
1509-
},
1510-
{
1511-
"type": "SYMBOL",
1512-
"name": "list"
1513-
}
1514-
]
1515-
}
1516-
]
1517-
}
15181364
}
15191365
]
15201366
},
@@ -4400,7 +4246,8 @@
44004246
"_nl",
44014247
"_eol",
44024248
"_ts_contents",
4403-
"_directive_list"
4249+
"_directive_list",
4250+
"_body_contents"
44044251
],
44054252
"supertypes": []
44064253
}

0 commit comments

Comments
 (0)