Skip to content

Commit

Permalink
Merge pull request #802 from Golmote/prism-parigp
Browse files Browse the repository at this point in the history
Add support for PARI/GP
  • Loading branch information
Golmote committed Oct 16, 2015
2 parents 6803ca0 + 804ed77 commit 253c035
Show file tree
Hide file tree
Showing 12 changed files with 408 additions and 2 deletions.
4 changes: 4 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ var components = {
"title": "OCaml",
"owner": "Golmote"
},
"parigp": {
"title": "PARI/GP",
"owner": "Golmote"
},
"pascal": {
"title": "Pascal",
"owner": "Golmote"
Expand Down
27 changes: 27 additions & 0 deletions components/prism-parigp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Prism.languages.parigp = {
'comment': /\/\*[\s\S]*?\*\/|\\\\.*/,
'string': /"(?:[^"\\]|\\.)*"/,
// PARI/GP does not care about white spaces at all
// so let's process the keywords to build an appropriate regexp
// (e.g. "b *r *e *a *k", etc.)
'keyword': (function () {
var keywords = [
'breakpoint', 'break', 'dbg_down', 'dbg_err', 'dbg_up', 'dbg_x',
'forcomposite', 'fordiv', 'forell', 'forpart', 'forprime',
'forstep', 'forsubgroup', 'forvec', 'for', 'iferr', 'if',
'local', 'my', 'next', 'return', 'until', 'while'
];
keywords = keywords.map(function (keyword) {
return keyword.split('').join(' *');
}).join('|');
return RegExp('\\b(?:' + keywords + ')\\b');
}()),
'function': /\w[\w ]*?(?= *\()/,
'number': {
// The lookbehind and the negative lookahead prevent from breaking the .. operator
pattern: /((?:\. *\. *)?)(?:\d(?: *\d)*(?: *(?!\. *\.)\.(?: *\d)*)?|\. *\d(?: *\d)*)(?: *e *[+-]? *\d(?: *\d)*)?/i,
lookbehind: true
},
'operator': /\. *\.|[*\/!](?: *=)?|%(?: *=|(?: *#)?(?: *')*)?|\+(?: *[+=])?|-(?: *[-=>])?|<(?:(?: *<)?(?: *=)?| *>)?|>(?: *>)?(?: *=)?|=(?: *=){0,2}|\\(?: *\/)?(?: *=)?|&(?: *&)?|\| *\||['#~^]/,
'punctuation': /[\[\]{}().,:;|]/
};
1 change: 1 addition & 0 deletions components/prism-parigp.min.js

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

33 changes: 33 additions & 0 deletions examples/prism-parigp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<h1>PARI/GP</h1>
<p>To use this language, use the class "language-parigp".</p>

<h2>Comments</h2>
<pre><code>\\ Single line comment
/* Multi line
comment */</code></pre>

<h2>Strings</h2>
<pre><code>""
"Foo \"bar\" baz"</code></pre>

<h2>Numbers</h2>
<pre><code>0.
42
3 . 14 15 9
5.2 E +12
.89</code></pre>

<h2>Ignored whitespaces</h2>
<pre><code>p r i n t ("hello")
if err(1/i, E, print (E))
a + = b \ / c</code></pre>

<h2>Known failures</h2>
<p>There are certain edge cases where Prism will fail.
There are always such cases in every regex-based syntax highlighter.
However, Prism dares to be open and honest about them.
If a failure is listed here, it doesn’t mean it will never be fixed. This is more of a “known bugs” list, just with a certain type of bug.
</p>

<h3>Comment-like substrings</h3>
<pre><code>"foo /* baz */" "foo \\ baz"</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 @@ -5,7 +5,7 @@ if (typeof self === 'undefined' || !self.Prism || !self.document) {
}

// The languages map is built automatically with gulp
var Languages = /*languages_placeholder[*/{"css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","aspnet":"ASP.NET (C#)","autoit":"AutoIt","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","fsharp":"F#","glsl":"GLSL","http":"HTTP","inform7":"Inform 7","latex":"LaTeX","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","yaml":"YAML"}/*]*/;
var Languages = /*languages_placeholder[*/{"css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","asciidoc":"AsciiDoc","aspnet":"ASP.NET (C#)","autoit":"AutoIt","autohotkey":"AutoHotkey","basic":"BASIC","csharp":"C#","cpp":"C++","coffeescript":"CoffeeScript","css-extras":"CSS Extras","fsharp":"F#","glsl":"GLSL","http":"HTTP","inform7":"Inform 7","latex":"LaTeX","lolcode":"LOLCODE","matlab":"MATLAB","mel":"MEL","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","parigp":"PARI/GP","php":"PHP","php-extras":"PHP Extras","powershell":"PowerShell","jsx":"React JSX","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","typescript":"TypeScript","vhdl":"VHDL","vim":"vim","wiki":"Wiki markup","yaml":"YAML"}/*]*/;
Prism.hooks.add('before-highlight', function(env) {
var pre = env.element.parentNode;
if (!pre || !/pre/i.test(pre.nodeName)) {
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.

18 changes: 18 additions & 0 deletions tests/languages/parigp/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**/
/* foo
bar */
\\
\\ foobar

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

[
["comment", "/**/"],
["comment", "/* foo\r\nbar */"],
["comment", "\\\\"],
["comment", "\\\\ foobar"]
]

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

Checks for comments.
13 changes: 13 additions & 0 deletions tests/languages/parigp/function_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
foo()
f o o b a r ( )

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

[
["function", "foo"], ["punctuation", "("], ["punctuation", ")"],
["function", "f o o b a r"], ["punctuation", "("], ["punctuation", ")"]
]

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

Checks for functions. Also checks that whitespaces are ignored.
103 changes: 103 additions & 0 deletions tests/languages/parigp/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
break
breakpoint
dbg_down
dbg_err
dbg_up
dbg_x
for
forcomposite
fordiv
forell
forpart
forprime
forstep
forsubgroup
forvec
if
iferr
local
my
next
return
until
while

br e ak
break point
d b g_down
dbg_e r r
dbg _ up
db g _x
f o r
for composite
for div
for ell
for part
for prime
for step
for subgroup
for vec
i f
if err
l o c a l
m y
ne xt
re tu rn
u nti l
whi le

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

[
["keyword", "break"],
["keyword", "breakpoint"],
["keyword", "dbg_down"],
["keyword", "dbg_err"],
["keyword", "dbg_up"],
["keyword", "dbg_x"],
["keyword", "for"],
["keyword", "forcomposite"],
["keyword", "fordiv"],
["keyword", "forell"],
["keyword", "forpart"],
["keyword", "forprime"],
["keyword", "forstep"],
["keyword", "forsubgroup"],
["keyword", "forvec"],
["keyword", "if"],
["keyword", "iferr"],
["keyword", "local"],
["keyword", "my"],
["keyword", "next"],
["keyword", "return"],
["keyword", "until"],
["keyword", "while"],

["keyword", "br e ak"],
["keyword", "break point"],
["keyword", "d b g_down"],
["keyword", "dbg_e r r"],
["keyword", "dbg _ up"],
["keyword", "db g _x"],
["keyword", "f o r"],
["keyword", "for composite"],
["keyword", "for div"],
["keyword", "for ell"],
["keyword", "for part"],
["keyword", "for prime"],
["keyword", "for step"],
["keyword", "for subgroup"],
["keyword", "for vec"],
["keyword", "i f"],
["keyword", "if err"],
["keyword", "l o c a l"],
["keyword", "m y"],
["keyword", "ne xt"],
["keyword", "re tu rn"],
["keyword", "u nti l"],
["keyword", "whi le"]
]

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

Checks for all keywords. Also checks that whitespaces are ignored.
39 changes: 39 additions & 0 deletions tests/languages/parigp/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
0
42
1 2 3 4 5
4.
4 .
.5
. 5
3.14159
3 . 14 15 9
3E8
3 E 8
2.0e-7
2 . 0 e - 7
.28e+12
. 2 8 e + 1 2

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

[
["number", "0"],
["number", "42"],
["number", "1 2 3 4 5"],
["number", "4."],
["number", "4 ."],
["number", ".5"],
["number", ". 5"],
["number", "3.14159"],
["number", "3 . 14 15 9"],
["number", "3E8"],
["number", "3 E 8"],
["number", "2.0e-7"],
["number", "2 . 0 e - 7"],
["number", ".28e+12"],
["number", ". 2 8 e + 1 2"]
]

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

Checks for numbers. Also checks that whitespaces are ignored.
Loading

0 comments on commit 253c035

Please sign in to comment.