Skip to content

Commit c8aeb94

Browse files
committed
fix: taglink special-cases |(| |{| …
1 parent 30cd470 commit c8aeb94

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,10 @@ Known issues
4646
`:help lcs-tab`.
4747
- `url` doesn't handle _surrounding_ parens. E.g. `(https://example.com/#yay)` yields `word`
4848
- `url` doesn't handle _nested_ parens. E.g. `(https://example.com/(foo)#yay)`
49-
- `column_heading` currently only recognizes tilde "~" preceded by space (i.e.
50-
"foo ~" not "foo~"). This covers 99% of :help files, but the grammar should
49+
- `column_heading` currently only recognizes tilde `~` preceded by space (i.e.
50+
`foo ~` not `foo~`). This covers 99% of :help files, but the grammar should
5151
probably support "foo~" also.
52+
- `column_heading` children should be plaintext. Currently its children are parsed as `$._atom`.
5253

5354
TODO
5455
----

corpus/arguments.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ EXTERNAL *netrw-externapp* {{{2
9292
(help_file
9393
(block
9494
(line
95-
(word)
96-
(ERROR
97-
(word))
9895
(argument
99-
(word))
96+
(word)
97+
(ERROR
98+
(word)
99+
(word)))
100100
(word)
101101
(codespan
102102
(word))

corpus/optionlink.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ number: '04' 'ISO-10646-1' 'python3'
107107
(MISSING "*"))
108108
(word)
109109
(word)
110-
(word)
111-
(ERROR
112-
(word))
113110
(argument
114-
(word))
111+
(word)
112+
(ERROR
113+
(word)
114+
(word)))
115115
(word)
116116
(word))
117117
(line

corpus/taglink.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ taglink alone
1515
================================================================================
1616
taglink in text
1717
================================================================================
18+
|(|, |)|, |`|, |{|, |}|.
19+
1820
Hello |world| hello
1921

2022
|-+| +[num] line
@@ -26,6 +28,23 @@ Hello |world| hello
2628
--------------------------------------------------------------------------------
2729

2830
(help_file
31+
(block
32+
(line
33+
(taglink
34+
(word))
35+
(word)
36+
(taglink
37+
(word))
38+
(word)
39+
(taglink
40+
(word))
41+
(word)
42+
(taglink
43+
(word))
44+
(word)
45+
(taglink
46+
(word))
47+
(word)))
2948
(block
3049
(line
3150
(word)

grammar.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,15 @@ module.exports = grammar({
199199
// Link to option: 'foo'. Lowercase non-digit ASCII, minimum 2 chars. #14
200200
optionlink: ($) => _word($, /[a-z][a-z]+/, "'", "'"),
201201
// Link to tag: |foo|
202-
taglink: ($) => _word($, /[^|\n\t ]+/, '|', '|'),
202+
taglink: ($) => _word($, choice(
203+
token.immediate(/[^|\n\t ]+/),
204+
// Special cases: |(| |{| …
205+
token.immediate('{'),
206+
token.immediate('}'),
207+
token.immediate('('),
208+
token.immediate(')'),
209+
token.immediate('`'),
210+
), '|', '|'),
203211
// Inline code (may contain whitespace!): `foo bar`
204212
codespan: ($) => _word($, /[^``\n]+/, '`', '`'),
205213
// Argument: {arg}
@@ -208,9 +216,10 @@ module.exports = grammar({
208216
});
209217

210218
// Word delimited by special chars.
211-
// The word_regex capture is aliased to "word" because they are semantically
212-
// the same: atoms of captured plain text.
213-
function _word($, word_regex, c1, c2, fname) {
219+
// `rule` can be a rule function or regex. It is aliased to "word" because they are
220+
// semantically the same: atoms of captured plain text.
221+
function _word($, rule, c1, c2, fname) {
222+
rule = rule.test !== undefined ? token.immediate(rule) : rule
214223
fname = fname ?? 'text';
215-
return seq(c1, field(fname, alias(token.immediate(word_regex), $.word)), token.immediate(c2));
224+
return seq(c1, field(fname, alias(rule, $.word)), token.immediate(c2));
216225
}

0 commit comments

Comments
 (0)