Skip to content

Commit

Permalink
Merge pull request #630 from Golmote/prism-prolog
Browse files Browse the repository at this point in the history
Add support for Prolog
  • Loading branch information
Golmote committed Sep 9, 2015
2 parents e47087b + fe52a97 commit dd04c32
Show file tree
Hide file tree
Showing 11 changed files with 211 additions and 0 deletions.
4 changes: 4 additions & 0 deletions components.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ var components = {
"require": "clike",
"owner": "Golmote"
},
"prolog": {
"title": "Prolog",
"owner": "Golmote"
},
"pure": {
"title": "Pure",
"owner": "Golmote"
Expand Down
17 changes: 17 additions & 0 deletions components/prism-prolog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Prism.languages.prolog = {
// Syntax depends on the implementation
'comment': [
/%.+/,
/\/\*[\s\S]*?\*\//
],
// Depending on the implementation, strings may allow escaped newlines and quote-escape
'string': /(["'])(?:\1\1|\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
'builtin': /\b(?:fx|fy|xf[xy]?|yfx?)\b/,
'variable': /\b[A-Z_]\w*/,
// FIXME: Should we list all null-ary predicates (not followed by a parenthesis) like halt, trace, etc.?
'function': /\b[a-z]\w*(?:(?=\()|\/\d+)/,
'number': /\b\d+\.?\d*/,
// Custom operators are allowed
'operator': /[:\\=><\-?*@\/;+^|!$.]+|\b(?:is|mod|not|xor)\b/,
'punctuation': /[(){}\[\],]/
};
1 change: 1 addition & 0 deletions components/prism-prolog.min.js

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

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

<h2>Comments</h2>
<pre><code>% This is a comment
/* This is a
multi-line comment */</code></pre>

<h2>Numbers</h2>
<pre><code>42
3.1415</code></pre>

<h2>Strings</h2>
<pre><code>"This is a string."
"This is a string \
on multiple lines."
"A string with \"quotes\" in it."
"Another string with ""quotes"" in it."</code></pre>

<h2>Example</h2>
<pre><code>:- dynamic fibo/2.
fibo(0, 1). fibo(1, 1).
fibo(N, F) :-
N >= 2, N1 is N - 1, N2 is N - 2,
fibo(N1, F1), fibo(N2, F2), F is F1 + F2,
assert(fibo(N,F):-!). % assert as first clause</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 % bar"</code></pre>

<h3>% inside a quoted atom</h3>
<pre><code>'foo % bar'</code></pre>

<h3>Null-ary predicates are not highlighted</h3>
<pre><code>halt.
trace.

:- if(test1).
section_1.
:- elif(test2).
section_2.
:- elif(test3).
section_3.
:- else.
section_else.
:- endif.</code></pre>
17 changes: 17 additions & 0 deletions tests/languages/prolog/builtin_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
fx
fy
xf xfx xfy
yf yfx

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

[
["builtin", "fx"],
["builtin", "fy"],
["builtin", "xf"], ["builtin", "xfx"], ["builtin", "xfy"],
["builtin", "yf"], ["builtin", "yfx"]
]

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

Checks for builtins.
16 changes: 16 additions & 0 deletions tests/languages/prolog/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
% Foobar
/**/
/* Foo
bar */

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

[
["comment", "% Foobar"],
["comment", "/**/"],
["comment", "/* Foo\r\nbar */"]
]

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

Checks for comments.
17 changes: 17 additions & 0 deletions tests/languages/prolog/function_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
foobar(
foo_bar_42(
abs/1
atan/2

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

[
["function", "foobar"], ["punctuation", "("],
["function", "foo_bar_42"], ["punctuation", "("],
["function", "abs/1"],
["function", "atan/2"]
]

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

Checks for functions.
15 changes: 15 additions & 0 deletions tests/languages/prolog/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
42
3.14159
0

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

[
["number", "42"],
["number", "3.14159"],
["number", "0"]
]

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

Checks for numbers.
29 changes: 29 additions & 0 deletions tests/languages/prolog/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
is mod not xor

: \ =
> < -
? * @
/ ; +
^ | !
$ .

=@=

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

[
["operator", "is"], ["operator", "mod"], ["operator", "not"], ["operator", "xor"],

["operator", ":"], ["operator", "\\"], ["operator", "="],
["operator", ">"], ["operator", "<"], ["operator", "-"],
["operator", "?"], ["operator", "*"], ["operator", "@"],
["operator", "/"], ["operator", ";"], ["operator", "+"],
["operator", "^"], ["operator", "|"], ["operator", "!"],
["operator", "$"], ["operator", "."],

["operator", "=@="]
]

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

Checks for operators.
27 changes: 27 additions & 0 deletions tests/languages/prolog/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
""
"fo\"obar"
"fo""obar"
"foo\
bar"
''
'fo\'obar'
'fo''obar'
'foo\
bar'

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

[
["string", "\"\""],
["string", "\"fo\\\"obar\""],
["string", "\"fo\"\"obar\""],
["string", "\"foo\\\r\nbar\""],
["string", "''"],
["string", "'fo\\'obar'"],
["string", "'fo''obar'"],
["string", "'foo\\\r\nbar'"]
]

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

Checks for strings.
15 changes: 15 additions & 0 deletions tests/languages/prolog/variable_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Foobar
Foo_bar_42
_foo

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

[
["variable", "Foobar"],
["variable", "Foo_bar_42"],
["variable", "_foo"]
]

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

Checks for variables.

0 comments on commit dd04c32

Please sign in to comment.