Skip to content

Commit

Permalink
Added ANBF language (#1753)
Browse files Browse the repository at this point in the history
This adds a new language: ANBF (Augmented Backus–Naur form).
  • Loading branch information
RunDevelopment committed Feb 28, 2019
1 parent ae4842d commit 6d98f0e
Show file tree
Hide file tree
Showing 17 changed files with 341 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@
"title": "ABAP",
"owner": "dellagustin"
},
"abnf": {
"title": "Augmented Backus–Naur form",
"owner": "RunDevelopment"
},
"actionscript": {
"title": "ActionScript",
"require": "javascript",
Expand Down
54 changes: 54 additions & 0 deletions components/prism-abnf.js
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);
1 change: 1 addition & 0 deletions components/prism-abnf.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 60 additions & 0 deletions examples/prism-abnf.html
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 = "&lt;" *(%x20-3D / %x3F-7E) ">"
; bracketed string of SP and VCHAR
; without angles
; prose description, to be used as
; last resort</code></pre>
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) {
}

// The languages map is built automatically with gulp
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","js":"JavaScript","abap":"ABAP","apacheconf":"Apache Configuration","apl":"APL","arff":"ARFF","asciidoc":"AsciiDoc","adoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Bash","basic":"BASIC","csharp":"C#","dotnet":"C#","cpp":"C++","cil":"CIL","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","jinja2":"Django/Jinja2","dockerfile":"Docker","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","gamemakerlanguage":"GameMaker Language","graphql":"GraphQL","hcl":"HCL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","javastacktrace":"Java stack trace","json":"JSON","jsonp":"JSONP","latex":"LaTeX","emacs":"Lisp","elisp":"Lisp","emacs-lisp":"Lisp","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n1ql":"N1QL","n4js":"N4JS","n4jsd":"N4JS","nand2tetris-hdl":"Nand To Tetris HDL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","ts":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","vb":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML"}/*]*/;
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","js":"JavaScript","abap":"ABAP","abnf":"Augmented Backus–Naur form","apacheconf":"Apache Configuration","apl":"APL","arff":"ARFF","asciidoc":"AsciiDoc","adoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Bash","basic":"BASIC","csharp":"C#","dotnet":"C#","cpp":"C++","cil":"CIL","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","jinja2":"Django/Jinja2","dockerfile":"Docker","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","gamemakerlanguage":"GameMaker Language","graphql":"GraphQL","hcl":"HCL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","javastacktrace":"Java stack trace","json":"JSON","jsonp":"JSONP","latex":"LaTeX","emacs":"Lisp","elisp":"Lisp","emacs-lisp":"Lisp","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n1ql":"N1QL","n4js":"N4JS","n4jsd":"N4JS","nand2tetris-hdl":"Nand To Tetris HDL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","toml":"TOML","tt2":"Template Toolkit 2","ts":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","vb":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML"}/*]*/;

Prism.plugins.toolbar.registerButton('show-language', function(env) {
var pre = env.element.parentNode;
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions tests/languages/abnf/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
;
; comment

----------------------------------------------------

[
["comment", ";"],
["comment", "; comment"]
]

----------------------------------------------------

Checks for comments.
53 changes: 53 additions & 0 deletions tests/languages/abnf/core-rule_feature.test
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.
22 changes: 22 additions & 0 deletions tests/languages/abnf/definition_feature.test
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.
13 changes: 13 additions & 0 deletions tests/languages/abnf/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
= =/ /

----------------------------------------------------

[
["operator", "="],
["operator", "=/"],
["operator", "/"]
]

----------------------------------------------------

Checks for operators.
15 changes: 15 additions & 0 deletions tests/languages/abnf/punctuation_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
()
[]

----------------------------------------------------

[
["punctuation", "("],
["punctuation", ")"],
["punctuation", "["],
["punctuation", "]"]
]

----------------------------------------------------

Checks for punctuation.
17 changes: 17 additions & 0 deletions tests/languages/abnf/range_feature.test
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.
19 changes: 19 additions & 0 deletions tests/languages/abnf/repetition_feature.test
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.
19 changes: 19 additions & 0 deletions tests/languages/abnf/rule_feature.test
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.
29 changes: 29 additions & 0 deletions tests/languages/abnf/string_feature.test
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.
19 changes: 19 additions & 0 deletions tests/languages/abnf/terminal_feature.test
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.

0 comments on commit 6d98f0e

Please sign in to comment.