Skip to content

Commit

Permalink
feat: recognize modelines
Browse files Browse the repository at this point in the history
  • Loading branch information
ribru17 committed May 8, 2024
1 parent 5d8b29f commit bcc2505
Show file tree
Hide file tree
Showing 6 changed files with 1,841 additions and 425 deletions.
28 changes: 28 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const STOP_CHARS = [
"-",
];

const WHITE_SPACE = /[ \t\f\v]/;

module.exports = grammar({
name: "comment",

Expand All @@ -49,6 +51,7 @@ module.exports = grammar({
source: ($) => repeat(
choice(
$.tag,
$.modeline,
$._full_uri,
alias($._text, "text"),
),
Expand All @@ -60,6 +63,31 @@ module.exports = grammar({
":",
),

modeline: ($) => prec.right(choice(
// First form
seq(
choice("vi:", "vim:", "ex:"),
$.option,
repeat(seq(choice(repeat1(WHITE_SPACE), ':'), $.option)),
optional(choice(repeat1(WHITE_SPACE), ':')),
),
// Second form
seq(
choice("vi:", "vim:", "ex:"),
/set? /,
repeat1($.option),
":",
),
seq(
"Vim:",
/set /,
repeat1($.option),
":",
),
)),

option: ($) => /[^\s:]+/,

_user: ($) => seq(
"(",
alias(/[^()]+/, $.user),
Expand Down
156 changes: 156 additions & 0 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bcc2505

Please sign in to comment.