Skip to content

Commit b5fe5bc

Browse files
feat: add support for links and timestamps
1 parent 219c0b2 commit b5fe5bc

File tree

7 files changed

+51803
-31455
lines changed

7 files changed

+51803
-31455
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ end_of_line = lf
66
insert_final_newline = true
77
trim_trailing_whitespace = true
88

9+
[*.tst]
10+
trim_trailing_whitespace = false
11+
912
[*.{json,toml,yml,gyp}]
1013
indent_style = space
1114
indent_size = 2

grammar.js

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ org_grammar = {
4848

4949
// headline 'entry_token1' ':' • '<' …
5050
[$.entry, $.expr],
51-
51+
[$.entry, $._markup],
5252
],
5353

5454
rules: {
@@ -77,6 +77,20 @@ org_grammar = {
7777
),
7878
),
7979

80+
link: $ => seq(
81+
token('[['),
82+
field('url', repeat(alias($._expr_with_space, $.expr))),
83+
token(']]')
84+
),
85+
86+
link_desc: $ => seq(
87+
token('[['),
88+
field('url', repeat(alias($._expr_with_space, $.expr))),
89+
token(']['),
90+
field('desc', repeat(alias($._expr_with_space, $.expr))),
91+
token(']]')
92+
),
93+
8094
// Can't have multiple in a row
8195
_multis: $ => choice(
8296
$.paragraph,
@@ -114,7 +128,7 @@ org_grammar = {
114128
$._eol,
115129
),
116130

117-
item: $ => repeat1($.expr),
131+
item: $ => repeat1($._markup),
118132

119133
tag_list: $ => prec.dynamic(1, seq(
120134
$._tag_expr_start,
@@ -327,8 +341,18 @@ org_grammar = {
327341
_nl: _ => choice('\n', '\r'),
328342
_eol: $ => choice('\n', '\r', $._eof),
329343

330-
_expr_line: $ => repeat1($.expr),
331-
_multiline_text: $ => repeat1(seq(repeat1($.expr), $._eol)),
344+
_expr_line: $ => repeat1($._markup),
345+
_multiline_text: $ => repeat1(seq(
346+
repeat1($._markup),
347+
$._eol
348+
)),
349+
350+
_markup: $ => choice(
351+
$.expr,
352+
$.link,
353+
$.link_desc,
354+
$.timestamp,
355+
),
332356

333357
_immediate_expr: $ => repeat1(expr('immediate', token.immediate)),
334358
_noc_expr: $ => repeat1(expr('immediate', token.immediate, ':')),
@@ -345,13 +369,20 @@ org_grammar = {
345369
repeat(expr('immediate', token.immediate))
346370
),
347371

372+
_expr_with_space: $ => seq(
373+
expr('non-immediate', token, '', ' '),
374+
repeat(expr('immediate', token.immediate, '', ' '))
375+
),
376+
348377
}
349378
};
350379

351-
function expr(pr, tfunc, skip = '') {
380+
function expr(pr, tfunc, skip = '', extra = '') {
352381
skip = skip.split("")
382+
extra = extra.split("")
353383
return choice(
354384
...asciiSymbols.filter(c => !skip.includes(c)).map(c => tfunc(prec(pr, c))),
385+
...extra.map(c => tfunc(prec(pr, c))),
355386
alias(tfunc(prec(pr, /\p{L}+/)), 'str'),
356387
alias(tfunc(prec(pr, /\p{N}+/)), 'num'),
357388
alias(tfunc(prec(pr, /[^\p{Z}\p{L}\p{N}\t\n\r]/)), 'sym'),

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
"install": "node-gyp-build",
4040
"pre-build": "prebuild --all --strip --verbose",
4141
"pre-build:upload": "prebuild --upload-all",
42+
"generate": "tree-sitter generate",
43+
"parse": "tree-sitter parse",
4244
"test": "tree-sitter test",
4345
"test-windows": "tree-sitter test",
4446
"prebuildify": "prebuildify --napi --strip"

0 commit comments

Comments
 (0)