-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuri.js
45 lines (40 loc) · 1.22 KB
/
uri.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module.exports = {
//////////////////
// URI definition - modified from https://github.com/atusy/tree-sitter-uri to handle " ; "
// Added commit hash matching.
uri: ($) =>
alias(seq(
$.scheme,
":",
choice(
$.authority, // e.g., https://example.com
$.path, // e.g., file:///home
prec(2, seq($.authority, $.path)), // e.g., https://example.com/foo
),
optional(seq("?", $.query)),
optional(seq("#", $.fragment)),
), $.string),
authority: ($) =>
seq("//", optional($.userinfo), optional(choice(prec(2, seq($.host, ":", $.port, /[^\s]/)), $.host))),
scheme: () => /[a-zA-Z][a-zA-Z0-9+.-]*/,
userinfo: () => /[^\n@\/]+@/,
host: () =>
choice(
// host without colon
/[^\n@:/;]+/, // no-colon
// host not beginning with colon
seq(
/[^\n@:/;]+/,
/[^\n@/;]*:/,
choice(
/[^\n@/:0-9][^\n@/:;]*/, // : followed by non-numeric
/[0-9]+[^\n@/:0-9][^\n@/:;]*/, // : followed by non-numeric
),
),
),
port: () => /\d+/,
path: ($) => seq(/[^\n?#"]/, /([^\n?#"@]*)?/, optional(seq("@", $.hash))),
query: () => /[^\n#"]*/,
fragment: () => /[^\n"]*/,
hash: () => /[A-Fa-f0-9]+/,
};