1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
<h1>Pure</h1>
<p>To use this language, use the class "language-pure".</p>
<h2>Comments</h2>
<pre><code>#! shebang
// Single line comment
/* Multi-line
comment */</code></pre>
<h2>Strings</h2>
<pre><code>"This is a string."
"This is a string with \"quotes\" in it."</code></pre>
<h2>Numbers</h2>
<pre><code>4711
4711L
1.2e-3
.14
1000
0x3e8
01750
0b1111101000
inf
nan</code></pre>
<h2>Inline code</h2>
<p>Inline code requires the desired language to be loaded.
On this page, check C, C++ and Fortran <strong>before</strong> checking Pure should make
the examples below work properly.</p>
<pre><code>%<
int mygcd(int x, int y)
{
if (y == 0)
return x;
else
return mygcd(y, x%y);
}
%>
%< -*- Fortran90 -*-
function fact(n) result(p)
integer n, p
p = 1
do i = 1, n
p = p*i
end do
end function fact
%>
%< -*- C++ -*-
#include <pure/runtime.h>
#include <string>
#include <map>
// An STL map mapping strings to Pure expressions.
using namespace std;
typedef map<string,pure_expr*> exprmap;
// Since we can't directly deal with C++ classes in Pure, provide some C
// functions to create, destroy and manipulate these objects.
extern "C" exprmap *map_create()
{
return new exprmap;
}
extern "C" void map_add(exprmap *m, const char *key, pure_expr *x)
{
exprmap::iterator it = m->find(string(key));
if (it != m->end()) pure_free(it->second);
(*m)[key] = pure_new(x);
}
extern "C" void map_del(exprmap *m, const char *key)
{
exprmap::iterator it = m->find(key);
if (it != m->end()) {
pure_free(it->second);
m->erase(it);
}
}
extern "C" pure_expr *map_get(exprmap *m, const char *key)
{
exprmap::iterator it = m->find(key);
return (it != m->end())?it->second:0;
}
extern "C" pure_expr *map_keys(exprmap *m)
{
size_t i = 0, n = m->size();
pure_expr **xs = new pure_expr*[n];
for (exprmap::iterator it = m->begin(); it != m->end(); ++it)
xs[i++] = pure_string_dup(it->first.c_str());
pure_expr *x = pure_listv(n, xs);
delete[] xs;
return x;
}
extern "C" void map_destroy(exprmap *m)
{
for (exprmap::iterator it = m->begin(); it != m->end(); ++it)
pure_free(it->second);
delete m;
}
%></code></pre>
<h2>Example</h2>
<pre><code>queens n = catch reverse (search n 1 []) with
search n i p = throw p if i>n;
= void [search n (i+1) ((i,j):p) | j = 1..n; safe (i,j) p];
safe (i,j) p = ~any (check (i,j)) p;
check (i1,j1) (i2,j2)
= i1==i2 || j1==j2 || i1+j1==i2+j2 || i1-j1==i2-j2;
end;</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>Commented inline code</h3>
<pre><code>/* %<
f()
%> */</code></pre>
<h3>Comment-like substrings</h3>
<pre><code>"foo /* bar */ baz"; "foo // bar";</code></pre>
<h3>Inline code-like substrings</h3>
<pre><code>"foo %< f() %> bar"</code></pre>