Skip to content

Commit

Permalink
Import GM peg.txt
Browse files Browse the repository at this point in the history
Misc note(s):
* `$ git checkout greasemonkey/greasemonkey/master peg.txt` after remote is added temporarily

Applies to OpenUserJS#285
  • Loading branch information
Martii committed Jul 18, 2015
1 parent ddc5a6a commit 03f9107
Showing 1 changed file with 94 additions and 0 deletions.
94 changes: 94 additions & 0 deletions peg.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// 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:(
"downloadURL" /
"exclude" /
"grant" /
"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}; }

0 comments on commit 03f9107

Please sign in to comment.