Skip to content

Commit

Permalink
constrain (argument) definition
Browse files Browse the repository at this point in the history
  • Loading branch information
justinmk committed Jun 21, 2023
1 parent afbca92 commit 65bcf74
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 53 deletions.
30 changes: 22 additions & 8 deletions corpus/arguments.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
argument
================================================================================
argument: {arg}
argument: {arg arg}
CTRL-R CTRL-R {register CTRL-F}
tuple: {arg,arg}
keycode: CTRL-R {CTRL-R} {register CTRL-F}
list of { uri:string, name: string } tables


Expand All @@ -23,7 +23,12 @@ list of { uri:string, name: string } tables
(word)
(keycode)
(argument
(word)))
(word))
(word)
(ERROR
(word))
(keycode)
(word))
(line
(word)
(word)
Expand Down Expand Up @@ -71,6 +76,7 @@ argument in parentheses
================================================================================
NOT an argument
================================================================================
a '{' '}' block
{foo "{bar}" `{baz}` |{baz| } {}
foo { bar
{ {} foo{{ foo{{{
Expand All @@ -92,11 +98,19 @@ EXTERNAL *netrw-externapp* {{{2
(help_file
(block
(line
(argument
(word)
(ERROR
(word)
(word)))
(word)
(word)
(word)
(ERROR
(word))
(word)
(word)
(word)
(word))
(line
(word)
(ERROR
(word))
(word)
(codespan
(word))
Expand Down
6 changes: 4 additions & 2 deletions corpus/heading3-column_heading.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,13 @@ buffer-diagram
(word))
(line
(word)
(word)
(ERROR
(word))
(word))
(line
(word)
(word)
(ERROR
(word))
(word))
(line
(taglink
Expand Down
8 changes: 6 additions & 2 deletions corpus/line_block.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ li continues
(line_li
(line
(word)
(word)
(word
(ERROR
(word)))
(word)
(word)
(word))
Expand All @@ -147,7 +149,9 @@ li continues
(block
(line_li
(line
(word)
(word
(ERROR
(word)))
(word)
(word))
(line))
Expand Down
27 changes: 9 additions & 18 deletions corpus/optionlink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ NOT optionlink: ' or 'x
================================================================================
'fillchars'
stl ' ' or '^' statusline
wbr ' ' windowbar
tricky: ' 'yes' 's foo


Expand All @@ -51,11 +50,6 @@ tricky: ' 'yes' 's foo
(word)
(word)
(word))
(line
(word)
(word)
(word)
(word))
(line
(word)
(word)
Expand All @@ -72,9 +66,8 @@ no! ','sqlKeyword'
single-char '-' 'g' '보'
non-ascii: '\"' '%)' '-bang' '.*\\.log' '.gitignore' '@{${\"foo\"}}'
number: '04' 'ISO-10646-1' 'python3'

Option ' :help 'textwidth'
Regular / :help /[
Option ' :help 'textwidth'
Regular / :help /[


--------------------------------------------------------------------------------
Expand All @@ -101,16 +94,13 @@ number: '04' 'ISO-10646-1' 'python3'
(word)
(word)
(word)
(tag
(word)
(MISSING "*"))
(word)
(ERROR
(word))
(word)
(word)
(argument
(word)
(ERROR
(word)
(word)))
(word))
(word)
(word))
(line
Expand All @@ -119,8 +109,9 @@ number: '04' 'ISO-10646-1' 'python3'
(word)
(word)
(word)
(word)))
(block
(word
(ERROR
(word))))
(line
(word)
(word)
Expand Down
3 changes: 2 additions & 1 deletion corpus/taglink.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ Note: ":autocmd" can...
(line
(word)
(word)
(word)
(ERROR
(word))
(word))
(line
(word)
Expand Down
18 changes: 9 additions & 9 deletions corpus/tags.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ NOT a tag
(word)
(word)
(word)
(tag
(word)
(MISSING "*")))
(word)
(ERROR
(word)))
(line
(word)
(word)
Expand All @@ -121,16 +121,16 @@ NOT a tag
(word))
(line
(word)
(tag
(word)
(MISSING "*"))
(word)
(ERROR
(word))
(word)))
(block
(line
(word)
(tag
(word)
(MISSING "*"))
(word)
(ERROR
(word))
(word)
(word)
(word))))
28 changes: 15 additions & 13 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = grammar({
// Explicit special cases: these are plaintext, not errors.
_word_common: () => choice(
// NOT tag: isolated "*".
/\*[\n\t ]/,
'*',
// NOT optionlink: '
"'",
// NOT optionlink: 'x
Expand Down Expand Up @@ -208,26 +208,28 @@ module.exports = grammar({
optionlink: ($) => _word($, /[a-z][a-z]+/, "'", "'"),
// Link to tag: |foo|
taglink: ($) => _word($, choice(
token.immediate(/[^|\n\t ]+/),
// Special cases: |(| |{| …
token.immediate('{'),
token.immediate('}'),
token.immediate('('),
token.immediate(')'),
token.immediate('`'),
), '|', '|'),
/[^|\n\t ]+/,
// Special cases: |(| |{| …
'{',
'}',
'(',
')',
'`',
),
'|', '|'),
// Inline code (may contain whitespace!): `foo bar`
codespan: ($) => _word($, /[^``\n]+/, '`', '`'),
// Argument: {arg}
argument: ($) => _word($, /[^{}\n\t ][^{}\n\t]*/, '{', '}'),
// Argument: {arg} (no whitespace allowed)
argument: ($) => _word($, /[^}\n\t ]+/, '{', '}'),
},
});

// Word delimited by special chars.
// `rule` can be a rule function or regex. It is aliased to "word" because they are
// semantically the same: atoms of captured plain text.
function _word($, rule, c1, c2, fname) {
rule = rule.test !== undefined ? token.immediate(rule) : rule
// rule = rule.test ? token.immediate(rule) : rule
// rule = token.immediate(rule)
fname = fname ?? 'text';
return seq(c1, field(fname, alias(rule, $.word)), token.immediate(c2));
return seq(c1, field(fname, alias(token.immediate(prec(1, rule)), $.word)), token.immediate(c2));
}

0 comments on commit 65bcf74

Please sign in to comment.