Skip to content

Commit b848266

Browse files
committed
feat: recognize modelines
1 parent 1f71db7 commit b848266

File tree

5 files changed

+1782
-342
lines changed

5 files changed

+1782
-342
lines changed

grammar.js

+28
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ const STOP_CHARS = [
3737
"-",
3838
];
3939

40+
const WHITE_SPACE = /[ \t\f\v]/;
41+
4042
module.exports = grammar({
4143
name: "comment",
4244

@@ -49,6 +51,7 @@ module.exports = grammar({
4951
source: ($) => repeat(
5052
choice(
5153
$.tag,
54+
$.modeline,
5255
$._full_uri,
5356
alias($._text, "text"),
5457
),
@@ -60,6 +63,31 @@ module.exports = grammar({
6063
":",
6164
),
6265

66+
modeline: ($) => prec.right(choice(
67+
// First form
68+
seq(
69+
choice("vi:", "vim:", "ex:"),
70+
$.option,
71+
repeat(seq(choice(repeat1(WHITE_SPACE), ':'), $.option)),
72+
optional(choice(repeat1(WHITE_SPACE), ':')),
73+
),
74+
// Second form
75+
seq(
76+
choice("vi:", "vim:", "ex:"),
77+
/set? /,
78+
repeat1($.option),
79+
":",
80+
),
81+
seq(
82+
"Vim:",
83+
/set /,
84+
repeat1($.option),
85+
":",
86+
),
87+
)),
88+
89+
option: ($) => /[^\s:]+/,
90+
6391
_user: ($) => seq(
6492
"(",
6593
alias(/[^()]+/, $.user),

src/grammar.json

+156
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/node-types.json

+39
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)