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