Skip to content

Commit

Permalink
Added BNF and RBNF languages (#1754)
Browse files Browse the repository at this point in the history
This adds the BNF and RBNF languages.
  • Loading branch information
RunDevelopment authored Feb 28, 2019
1 parent 6d98f0e commit 1df96c5
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@
"require": "c",
"owner": "Golmote"
},
"bnf": {
"title": "Backus–Naur form",
"alias": "rbfn",
"aliasTitles": {
"rbfn": "Routing Backus–Naur form"
},
"owner": "RunDevelopment"
},
"brainfuck": {
"title": "Brainfuck",
"owner": "Golmote"
Expand Down
21 changes: 21 additions & 0 deletions components/prism-bnf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Prism.languages.bnf = {
'string': {
pattern: /"[^\r\n"]*"|'[^\r\n']*'/
},
'definition': {
pattern: /<[^<>\r\n\t]+>(?=\s*::=)/,
alias: ['rule', 'keyword'],
inside: {
'punctuation': /^<|>$/
}
},
'rule': {
pattern: /<[^<>\r\n\t]+>/,
inside: {
'punctuation': /^<|>$/
}
},
'operator': /::=|[|()[\]{}*+?]|\.{3}/
};

Prism.languages.rbnf = Prism.languages.bnf;
1 change: 1 addition & 0 deletions components/prism-bnf.min.js

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

27 changes: 27 additions & 0 deletions examples/prism-bnf.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<h2>Full example</h2>
<pre><code>&lt;number&gt; ::= "+" &lt;unsigned&gt; | "-" &lt;unsigned&gt; | &lt;unsigned&gt;
&lt;unsigned&gt; ::= "NaN" | "Infinity" | &lt;decimal&gt; | &lt;decimal&gt; &lt;exponent&gt;
&lt;decimal&gt; ::= &lt;integer&gt; | "." &lt;non-zero-integer&gt; | &lt;non-zero-integer&gt; "." | &lt;integer&gt; "." &lt;integer&gt;

&lt;exponent&gt; ::= &lt;exponent-char&gt; &lt;exponent-sign&gt; &lt;integer&gt;
&lt;exponent-char&gt; ::= "e" | "E"
&lt;exponent-sign&gt; ::= "+" | "-" | ""

&lt;integer&gt; ::= "0" | &lt;non-zero-integer&gt;
&lt;non-zero-integer&gt; ::= &lt;non-zero-digit&gt; | &lt;non-zero-digit&gt; &lt;digits&gt;

&lt;digits&gt; ::= &lt;digit&gt; | &lt;digit&gt; &lt;digits&gt;
&lt;digit&gt; ::= "0" | &lt;non-zero-digit&gt;
&lt;non-zero-digit&gt; ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"</code></pre>

<h2>Routing Backus–Naur form</h2>
<pre><code>&lt;number&gt; ::= [ "+" | "-" ] &lt;unsigned&gt;
&lt;unsigned&gt; ::= "NaN" | "Infinity" | &lt;decimal&gt; [ &lt;exponent&gt; ]
&lt;decimal&gt; ::= &lt;integer&gt; [ "." &lt;integer&gt; ] | "." &lt;non-zero-integer&gt; | &lt;non-zero-integer&gt; "."
&lt;exponent&gt; ::= ( "e" | "E" ) [ "+" | "-" ] &lt;integer&gt;

&lt;integer&gt; ::= "0" | &lt;non-zero-integer&gt;
&lt;non-zero-integer&gt; ::= &lt;non-zero-digit&gt; [ &lt;digit&gt;... ]

&lt;digit&gt; ::= "0" | &lt;non-zero-digit&gt;
&lt;non-zero-digit&gt; ::= "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"</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","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"}/*]*/;
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","bnf":"Backus–Naur form","rbfn":"Routing Backus–Naur form","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.

17 changes: 17 additions & 0 deletions tests/languages/bnf/definition_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<foo> ::= "a"

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

[
["definition", [
["punctuation", "<"],
"foo",
["punctuation", ">"]
]],
["operator", "::="],
["string", "\"a\""]
]

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

Checks for definitions.
28 changes: 28 additions & 0 deletions tests/languages/bnf/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
::= |
() [] {}
* + ?
...

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

[
["operator", "::="],
["operator", "|"],

["operator", "("],
["operator", ")"],
["operator", "["],
["operator", "]"],
["operator", "{"],
["operator", "}"],

["operator", "*"],
["operator", "+"],
["operator", "?"],

["operator", "..."]
]

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

Checks for operators.
21 changes: 21 additions & 0 deletions tests/languages/bnf/rule_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<foo-bar>
<öäüß>

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

[
["rule", [
["punctuation", "<"],
"foo-bar",
["punctuation", ">"]
]],
["rule", [
["punctuation", "<"],
"öäüß",
["punctuation", ">"]
]]
]

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

Checks for rules.
21 changes: 21 additions & 0 deletions tests/languages/bnf/string_featrue.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
""
''
"'"
'"'
"foo"
'bar|::=()'

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

[
["string", "\"\""],
["string", "''"],
["string", "\"'\""],
["string", "'\"'"],
["string", "\"foo\""],
["string", "'bar|::=()'"]
]

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

Checks for strings.

0 comments on commit 1df96c5

Please sign in to comment.