-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds a new language: ANBF (Augmented Backus–Naur form).
- Loading branch information
1 parent
ae4842d
commit 6d98f0e
Showing
17 changed files
with
341 additions
and
3 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(function (Prism) { | ||
|
||
var coreRules = '(?:ALPHA|BIT|CHAR|CR|CRLF|CTL|DIGIT|DQUOTE|HEXDIG|HTAB|LF|LWSP|OCTET|SP|VCHAR|WSP)'; | ||
|
||
Prism.languages.abnf = { | ||
'comment': /;.*/, | ||
'string': { | ||
pattern: /(?:%[is])?"[^"\n\r]*"/, | ||
greedy: true, | ||
inside: { | ||
'punctuation': /^%[is]/ | ||
} | ||
}, | ||
'range': { | ||
pattern: /%(?:b[01]+-[01]+|d\d+-\d+|x[A-F\d]+-[A-F\d]+)/i, | ||
alias: 'number' | ||
}, | ||
'terminal': { | ||
pattern: /%(?:b[01]+(?:\.[01]+)*|d\d+(?:\.\d+)*|x[A-F\d]+(?:\.[A-F\d]+)*)/i, | ||
alias: 'number' | ||
}, | ||
'repetition': { | ||
pattern: /(^|[^\w-])(?:\d*\*\d*|\d+)/, | ||
lookbehind: true, | ||
alias: 'operator' | ||
}, | ||
'definition': { | ||
pattern: /(^[ \t]*)(?:[a-z][\w-]*|<[^>\r\n]*>)(?=\s*=)/m, | ||
lookbehind: true, | ||
alias: 'keyword', | ||
inside: { | ||
'punctuation': /<|>/ | ||
} | ||
}, | ||
'core-rule': { | ||
pattern: RegExp('(?:(^|[^<\\w-])' + coreRules + '|<' + coreRules + '>)(?![\\w-])', 'i'), | ||
lookbehind: true, | ||
alias: ['rule', 'constant'], | ||
inside: { | ||
'punctuation': /<|>/ | ||
} | ||
}, | ||
'rule': { | ||
pattern: /(^|[^<\w-])[a-z][\w-]*|<[^>\r\n]*>/i, | ||
lookbehind: true, | ||
inside: { | ||
'punctuation': /<|>/ | ||
} | ||
}, | ||
'operator': /=\/?|\//, | ||
'punctuation': /[()\[\]]/ | ||
}; | ||
|
||
})(Prism); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<h2>Full example</h2> | ||
<pre><code>rulelist = 1*( rule / (*c-wsp c-nl) ) | ||
|
||
rule = rulename defined-as elements c-nl | ||
; continues if next line starts | ||
; with white space | ||
|
||
rulename = ALPHA *(ALPHA / DIGIT / "-") | ||
|
||
defined-as = *c-wsp ("=" / "=/") *c-wsp | ||
; basic rules definition and | ||
; incremental alternatives | ||
|
||
elements = alternation *c-wsp | ||
|
||
c-wsp = WSP / (c-nl WSP) | ||
|
||
c-nl = comment / CRLF | ||
; comment or newline | ||
|
||
comment = ";" *(WSP / VCHAR) CRLF | ||
|
||
alternation = concatenation | ||
*(*c-wsp "/" *c-wsp concatenation) | ||
|
||
concatenation = repetition *(1*c-wsp repetition) | ||
|
||
repetition = [repeat] element | ||
|
||
repeat = 1*DIGIT / (*DIGIT "*" *DIGIT) | ||
|
||
element = rulename / group / option / | ||
char-val / num-val / prose-val | ||
|
||
group = "(" *c-wsp alternation *c-wsp ")" | ||
|
||
option = "[" *c-wsp alternation *c-wsp "]" | ||
|
||
char-val = DQUOTE *(%x20-21 / %x23-7E) DQUOTE | ||
; quoted string of SP and VCHAR | ||
; without DQUOTE | ||
|
||
num-val = "%" (bin-val / dec-val / hex-val) | ||
|
||
bin-val = "b" 1*BIT | ||
[ 1*("." 1*BIT) / ("-" 1*BIT) ] | ||
; series of concatenated bit values | ||
; or single ONEOF range | ||
|
||
dec-val = "d" 1*DIGIT | ||
[ 1*("." 1*DIGIT) / ("-" 1*DIGIT) ] | ||
|
||
hex-val = "x" 1*HEXDIG | ||
[ 1*("." 1*HEXDIG) / ("-" 1*HEXDIG) ] | ||
|
||
prose-val = "<" *(%x20-3D / %x3F-7E) ">" | ||
; bracketed string of SP and VCHAR | ||
; without angles | ||
; prose description, to be used as | ||
; last resort</code></pre> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
; | ||
; comment | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", ";"], | ||
["comment", "; comment"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
ALPHA | ||
BIT | ||
CHAR | ||
CR | ||
CRLF | ||
CTL | ||
DIGIT | ||
DQUOTE | ||
HEXDIG | ||
HTAB | ||
LF | ||
LWSP | ||
OCTET | ||
SP | ||
VCHAR | ||
WSP | ||
|
||
bit | ||
biT | ||
<bIt> | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["core-rule", ["ALPHA"]], | ||
["core-rule", ["BIT"]], | ||
["core-rule", ["CHAR"]], | ||
["core-rule", ["CR"]], | ||
["core-rule", ["CRLF"]], | ||
["core-rule", ["CTL"]], | ||
["core-rule", ["DIGIT"]], | ||
["core-rule", ["DQUOTE"]], | ||
["core-rule", ["HEXDIG"]], | ||
["core-rule", ["HTAB"]], | ||
["core-rule", ["LF"]], | ||
["core-rule", ["LWSP"]], | ||
["core-rule", ["OCTET"]], | ||
["core-rule", ["SP"]], | ||
["core-rule", ["VCHAR"]], | ||
["core-rule", ["WSP"]], | ||
|
||
["core-rule", ["bit"]], | ||
["core-rule", ["biT"]], | ||
["core-rule", [ | ||
["punctuation", "<"], | ||
"bIt", | ||
["punctuation", ">"] | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for core rules. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
foo-bar = %x20 | ||
<foo-foo> =/ foo-bar | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["definition", ["foo-bar"]], | ||
["operator", "="], | ||
["terminal", "%x20"], | ||
|
||
["definition", [ | ||
["punctuation", "<"], | ||
"foo-foo", | ||
["punctuation", ">"] | ||
]], | ||
["operator", "=/"], | ||
["rule", ["foo-bar"]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for definitions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
= =/ / | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["operator", "="], | ||
["operator", "=/"], | ||
["operator", "/"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for operators. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
() | ||
[] | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["punctuation", "("], | ||
["punctuation", ")"], | ||
["punctuation", "["], | ||
["punctuation", "]"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for punctuation. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
%b0-11111 | ||
%d0-31 | ||
%x0-1F | ||
%x0-1f | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["range", "%b0-11111"], | ||
["range", "%d0-31"], | ||
["range", "%x0-1F"], | ||
["range", "%x0-1f"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for ranges. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
*foo | ||
2foo | ||
*2foo | ||
2*foo | ||
2*3foo | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["repetition", "*"], ["rule", ["foo"]], | ||
["repetition", "2"], ["rule", ["foo"]], | ||
["repetition", "*2"], ["rule", ["foo"]], | ||
["repetition", "2*"], ["rule", ["foo"]], | ||
["repetition", "2*3"], ["rule", ["foo"]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for repetitions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
foo | ||
foo-Bar | ||
<foo-bar> | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["rule", ["foo"]], | ||
["rule", ["foo-Bar"]], | ||
["rule", [ | ||
["punctuation", "<"], | ||
"foo-bar", | ||
["punctuation", ">"] | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for rules. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"" | ||
"a" | ||
"abc<d>" | ||
";" | ||
|
||
%s"abc" | ||
%i"abc" | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["string", ["\"\""]], | ||
["string", ["\"a\""]], | ||
["string", ["\"abc<d>\""]], | ||
["string", ["\";\""]], | ||
|
||
["string", [ | ||
["punctuation", "%s"], | ||
"\"abc\"" | ||
]], | ||
["string", [ | ||
["punctuation", "%i"], | ||
"\"abc\"" | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for strings. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
%b1000001 | ||
%d65 | ||
%x41 | ||
%d65.66.67 | ||
%x41.42.43 | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["terminal", "%b1000001"], | ||
["terminal", "%d65"], | ||
["terminal", "%x41"], | ||
["terminal", "%d65.66.67"], | ||
["terminal", "%x41.42.43"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for strings. |