feat!: add (checkbox) in list

This commit is contained in:
Emilia Simmons 2022-06-27 10:47:50 -04:00
parent 4d2b327744
commit 53a61b6b62
7 changed files with 61010 additions and 59140 deletions

View file

@ -32,9 +32,9 @@ Some *marked up* words
<2020-06-07 Sun>
- list a
- [ ] list a
- [ ] list b
- [-] list a
- [ ] list b
- [x] list b
- list a
** Subsection :tag:
@ -75,24 +75,23 @@ Parses as:
(expr [7, 9] - [7, 10])))
(listitem [8, 2] - [11, 0]
bullet: (bullet [8, 2] - [8, 3])
contents: (paragraph [8, 4] - [9, 0]
(expr [8, 4] - [8, 5])
(expr [8, 6] - [8, 7])
checkbox: (checkbox [8, 4] - [8, 7]
status: (expr [8, 5] - [8, 6]))
contents: (paragraph [8, 8] - [9, 0]
(expr [8, 8] - [8, 12])
(expr [8, 13] - [8, 14]))
contents: (list [9, 0] - [11, 0]
(listitem [9, 4] - [10, 0]
bullet: (bullet [9, 4] - [9, 5])
contents: (paragraph [9, 6] - [10, 0]
(expr [9, 6] - [9, 7])
(expr [9, 8] - [9, 9])
checkbox: (checkbox [9, 6] - [9, 9])
contents: (paragraph [9, 10] - [10, 0]
(expr [9, 10] - [9, 14])
(expr [9, 15] - [9, 16])))
(listitem [10, 4] - [11, 0]
bullet: (bullet [10, 4] - [10, 5])
contents: (paragraph [10, 6] - [11, 0]
(expr [10, 6] - [10, 7])
(expr [10, 8] - [10, 9])
checkbox: (checkbox [10, 6] - [10, 9]
status: (expr [10, 7] - [10, 8]))
contents: (paragraph [10, 10] - [11, 0]
(expr [10, 10] - [10, 14])
(expr [10, 15] - [10, 16])))))
(listitem [11, 2] - [12, 0]

View file

@ -815,7 +815,7 @@ List.8b - Whitespace after text
(expr))))))
================================================================================
List.9 - newline before sub listitem
List.9 - newline before sub listitem
================================================================================
- a
@ -835,6 +835,175 @@ List.9 - newline before sub listitem
(paragraph
(expr))))))))
================================================================================
List.10a - Checkbox [ ]
================================================================================
- [ ] a
--------------------------------------------------------------------------------
(document
(body
(list
(listitem
(bullet)
(checkbox)
(paragraph
(expr))))))
================================================================================
List.10b - Checkbox [x]
================================================================================
- [x] a
--------------------------------------------------------------------------------
(document
(body
(list
(listitem
(bullet)
(checkbox
(expr))
(paragraph
(expr))))))
================================================================================
List.10c - Checkbox [X]
================================================================================
- [X] a
--------------------------------------------------------------------------------
(document
(body
(list
(listitem
(bullet)
(checkbox
(expr))
(paragraph
(expr))))))
================================================================================
List.10d - Checkbox [-]
================================================================================
- [-] a
--------------------------------------------------------------------------------
(document
(body
(list
(listitem
(bullet)
(checkbox
(expr))
(paragraph
(expr))))))
================================================================================
List.10e - Checkbox [done]
================================================================================
- [done] a
--------------------------------------------------------------------------------
(document
(body
(list
(listitem
(bullet)
(checkbox
(expr))
(paragraph
(expr))))))
================================================================================
List.11a - No Checkbox markup
================================================================================
- +[ ] a+
--------------------------------------------------------------------------------
(document
(body
(list
(listitem
(bullet)
(paragraph
(expr)
(expr)
(expr))))))
================================================================================
List.11b - No Checkbox [ a
================================================================================
- [ a
--------------------------------------------------------------------------------
(document
(body
(list
(listitem
(bullet)
(paragraph
(expr)
(expr))))))
================================================================================
List.11c - No Checkbox [ ]
================================================================================
- [ ]
--------------------------------------------------------------------------------
(document
(body
(list
(listitem
(bullet)
(paragraph
(expr)
(expr))))))
================================================================================
List.11d - No Checkbox [-
================================================================================
- [- a]
--------------------------------------------------------------------------------
(document
(body
(list
(listitem
(bullet)
(paragraph
(expr)
(expr))))))
================================================================================
List.11e - No Checkbox [x
================================================================================
- [x b]
--------------------------------------------------------------------------------
(document
(body
(list
(listitem
(bullet)
(paragraph
(expr)
(expr))))))
================================================================================
List.11f - No Checkbox [x1]
================================================================================
- [x1]
--------------------------------------------------------------------------------
(document
(body
(list
(listitem
(bullet)
(paragraph
(expr))))))
================================================================================
Directive.1 - Document
================================================================================

View file

@ -246,12 +246,22 @@ org_grammar = {
listitem: $ => seq(
field('bullet', $.bullet),
optional(field('checkbox', $.checkbox)),
choice(
$._eof,
field('contents', $._body_contents),
),
),
checkbox: $ => choice(
'[ ]',
seq(
token(prec('non-immediate', '[')),
field('status', alias($._checkbox_status_expr, $.expr)),
token.immediate(prec('special', ']')),
),
),
table: $ => prec.right(seq(
optional($._directive_list),
repeat1(choice($.row, $.hr)),
@ -324,6 +334,8 @@ org_grammar = {
_immediate_expr: $ => repeat1(expr('immediate', token.immediate)),
_noc_expr: $ => repeat1(expr('immediate', token.immediate, ':')),
_checkbox_status_expr: $ => expr('immediate', token.immediate, ']'),
_ts_expr: $ => seq(
expr('non-immediate', token, '>]'),
repeat(expr('immediate', token.immediate, '>]'))
@ -344,6 +356,9 @@ function expr(pr, tfunc, skip = '') {
alias(tfunc(prec(pr, /\p{L}+/)), 'str'),
alias(tfunc(prec(pr, /\p{N}+/)), 'num'),
alias(tfunc(prec(pr, /[^\p{Z}\p{L}\p{N}\n\r]/)), 'sym'),
// for checkboxes: ugly, but makes them work..
// alias(tfunc(prec(pr, 'x')), 'str'),
// alias(tfunc(prec(pr, 'X')), 'str'),
)
}

View file

@ -61,10 +61,10 @@
(bullet) @OrgListBullet
; Get different colors for different statuses as follows
(listitem . (bullet) . (paragraph . (expr "[" "str" @OrgCheckDone "]") @OrgCheckbox (#match? @OrgCheckbox "^\[[xX]\]$")))
(listitem . (bullet) . (paragraph . (expr "[" "-" @OrgCheckInProgress "]") @OrgCheckbox (#eq? @OrgCheckbox "[-]")))
(listitem . (bullet) . (paragraph . (expr "[") @OrgCheckbox.left (#eq? @OrgCheckbox.left "[") . (expr "]") @OrgCheckbox.right (#eq? @OrgCheckbox.right "]")))
; (listitem . (bullet) . (paragraph (expr ":" ":") @OrgListDescriptionSeparator (#eq? @OrgListDescriptionSeparator "::"))) -- matches multiple, requires a special search.
(checkbox) @OrgCheckbox
(checkbox status: (expr "-") @OrgCheckInProgress)
(checkbox status: (expr "str") @OrgCheckDone (#any-of? @OrgCheckDone "x" "X"))
(checkbox status: (expr) @Error (#not-any-of? @Error "x" "X" "-"))
; If you want the ruler one color and the separators a different color,
; something like this would do it:

View file

@ -1405,6 +1405,22 @@
"name": "bullet"
}
},
{
"type": "CHOICE",
"members": [
{
"type": "FIELD",
"name": "checkbox",
"content": {
"type": "SYMBOL",
"name": "checkbox"
}
},
{
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
@ -1424,6 +1440,55 @@
}
]
},
"checkbox": {
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "[ ]"
},
{
"type": "SEQ",
"members": [
{
"type": "TOKEN",
"content": {
"type": "PREC",
"value": "non-immediate",
"content": {
"type": "STRING",
"value": "["
}
}
},
{
"type": "FIELD",
"name": "status",
"content": {
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "_checkbox_status_expr"
},
"named": true,
"value": "expr"
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "special",
"content": {
"type": "STRING",
"value": "]"
}
}
}
]
}
]
},
"table": {
"type": "PREC_RIGHT",
"value": 0,
@ -2724,6 +2789,400 @@
]
}
},
"_checkbox_status_expr": {
"type": "CHOICE",
"members": [
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "!"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "\""
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "#"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "$"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "%"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "&"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "'"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "("
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": ")"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "*"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "+"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": ","
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "-"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "."
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "/"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": ":"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": ";"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "<"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "="
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": ">"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "?"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "@"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "["
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "\\"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "^"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "_"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "`"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "{"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "|"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "}"
}
}
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "STRING",
"value": "~"
}
}
},
{
"type": "ALIAS",
"content": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "PATTERN",
"value": "\\p{L}+"
}
}
},
"named": false,
"value": "str"
},
{
"type": "ALIAS",
"content": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "PATTERN",
"value": "\\p{N}+"
}
}
},
"named": false,
"value": "num"
},
{
"type": "ALIAS",
"content": {
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PREC",
"value": "immediate",
"content": {
"type": "PATTERN",
"value": "[^\\p{Z}\\p{L}\\p{N}\\n\\r]"
}
}
},
"named": false,
"value": "sym"
}
]
},
"_ts_expr": {
"type": "SEQ",
"members": [

View file

@ -119,6 +119,22 @@
}
}
},
{
"type": "checkbox",
"named": true,
"fields": {
"status": {
"multiple": false,
"required": false,
"types": [
{
"type": "expr",
"named": true
}
]
}
}
},
{
"type": "comment",
"named": true,
@ -523,6 +539,16 @@
}
]
},
"checkbox": {
"multiple": false,
"required": false,
"types": [
{
"type": "checkbox",
"named": true
}
]
},
"contents": {
"multiple": true,
"required": false,
@ -1052,6 +1078,10 @@
"type": "[",
"named": false
},
{
"type": "[ ]",
"named": false
},
{
"type": "[%%",
"named": false

119446
src/parser.c

File diff suppressed because it is too large Load diff