forked from greasemonkey/greasemonkey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peg.txt
96 lines (85 loc) · 1.95 KB
/
peg.txt
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// PEG grammar for parsing user script metadata
// http://pegjs.majda.cz/online
/*
Test value:
// ==UserScript==
// @name Metadata Test
// @name:de Auf deutsch bitte!
// @namespace test
// @description Test value including all metas.
// @version 1.2.3
// @icon http://example.com/favicon.ico
// @include http://example.com/*
// @match http://example.net/*
// @exclude http://example.com/foo
// @run-at document-start
// @grant none
// @downloadURL http://example.org/foo.user.js
// @updateURL http://example.org/foo.meta.js
// @require http://example.net/library.js
// @resource css http://example.net/library.css
// @noframes
// ==/UserScript==
*/
/*
// Uncomment to parse an entire metadata block.
// I.E for testing/development.
meta =
"// ==UserScript==\n"
lines:line*
"// ==/UserScript==" ("\n"?)
{ return lines; }
*/
line =
"// @"
meta:(
keyword0 /
keyword1 /
keyword2 /
keywordLocale)
"\n"?
{ return meta; }
whitespace = [ \t\n]+
non_whitespace = $[^ \t\n]+
non_newline = $[^\n]+
keyword0 =
keyword:(
"noframes"
)
{ return {keyword:keyword}; }
keyword1 =
keyword:(
"author" /
"downloadURL" /
"exclude" /
"grant" /
"homepageURL" /
"icon" /
"include" /
"installURL" /
"match" /
"namespace" /
"require" /
"run-at" /
"updateURL" /
"version"
)
whitespace
value:non_newline
{ return {keyword:keyword, value:value}; }
keyword2 =
keyword:("resource")
whitespace
value1:non_whitespace
whitespace
value2:non_newline
{ return {keyword:keyword, value1:value1, value2:value2}; }
keywordLocale
= keyword:(
"description" /
"name"
)
locale:(":" localeValue:$[a-zA-Z-]+ { return localeValue })?
whitespace
value:non_newline
{ return {keyword:keyword, locale:locale, value:value}; }