Merge branch 'prism-examples'
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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
diff --git a/examples/prism-autohotkey.html b/examples/prism-autohotkey.html
new file mode 100644
index 0000000..e7afbbc
--- /dev/null
+++ b/examples/prism-autohotkey.html
@@ -0,0 +1,71 @@
+<h1>AutoHotkey</h1>
+<p>To use this language, use the class "language-autohotkey".</p>
+
+<h2>Comments</h2>
+<pre><code>; This is a comment</code></pre>
+
+<h2>Strings</h2>
+<pre><code>"foo ""bar"" baz"</code></pre>
+
+<h2>Numbers</h2>
+<pre><code>123
+123.456
+123.456e789
+0xAF</code></pre>
+
+<h2>Full example</h2>
+<pre><code>;----Open the selected favorite
+f_OpenFavorite:
+; Fetch the array element that corresponds to the selected menu item:
+StringTrimLeft, f_path, f_path%A_ThisMenuItemPos%, 0
+if f_path =
+ return
+if f_class = #32770 ; It's a dialog.
+{
+ if f_Edit1Pos <> ; And it has an Edit1 control.
+ {
+ ; Activate the window so that if the user is middle-clicking
+ ; outside the dialog, subsequent clicks will also work:
+ WinActivate ahk_id %f_window_id%
+ ; Retrieve any filename that might already be in the field so
+ ; that it can be restored after the switch to the new folder:
+ ControlGetText, f_text, Edit1, ahk_id %f_window_id%
+ ControlSetText, Edit1, %f_path%, ahk_id %f_window_id%
+ ControlSend, Edit1, {Enter}, ahk_id %f_window_id%
+ Sleep, 100 ; It needs extra time on some dialogs or in some cases.
+ ControlSetText, Edit1, %f_text%, ahk_id %f_window_id%
+ return
+ }
+ ; else fall through to the bottom of the subroutine to take standard action.
+}
+else if f_class in ExploreWClass,CabinetWClass ; In Explorer, switch folders.
+{
+ if f_Edit1Pos <> ; And it has an Edit1 control.
+ {
+ ControlSetText, Edit1, %f_path%, ahk_id %f_window_id%
+ ; Tekl reported the following: "If I want to change to Folder L:\folder
+ ; then the addressbar shows http://www.L:\folder.com. To solve this,
+ ; I added a {right} before {Enter}":
+ ControlSend, Edit1, {Right}{Enter}, ahk_id %f_window_id%
+ return
+ }
+ ; else fall through to the bottom of the subroutine to take standard action.
+}
+else if f_class = ConsoleWindowClass ; In a console window, CD to that directory
+{
+ WinActivate, ahk_id %f_window_id% ; Because sometimes the mclick deactivates it.
+ SetKeyDelay, 0 ; This will be in effect only for the duration of this thread.
+ IfInString, f_path, : ; It contains a drive letter
+ {
+ StringLeft, f_path_drive, f_path, 1
+ Send %f_path_drive%:{enter}
+ }
+ Send, cd %f_path%{Enter}
+ return
+}
+; Since the above didn't return, one of the following is true:
+; 1) It's an unsupported window type but f_AlwaysShowMenu is y (yes).
+; 2) It's a supported type but it lacks an Edit1 control to facilitate the custom
+; action, so instead do the default action below.
+Run, Explorer %f_path% ; Might work on more systems without double quotes.
+return</code></pre>
\ No newline at end of file
diff --git a/examples/prism-haskell.html b/examples/prism-haskell.html
new file mode 100644
index 0000000..a142318
--- /dev/null
+++ b/examples/prism-haskell.html
@@ -0,0 +1,93 @@
+<h1>Haskell</h1>
+<p>To use this language, use the class "language-haskell".</p>
+
+<h2>Comments</h2>
+<pre><code>-- Single line comment
+{- Multi-line
+comment -}</code></pre>
+
+<h2>Strings and characters</h2>
+<pre><code>'a'
+'\n'
+'\^A'
+'\^]'
+'\NUL'
+'\23'
+'\o75'
+'\xFE'
+"Here is a backslant \\ as well as \137, \
+ \a numeric escape character, and \^X, a control character."</code></pre>
+
+<h2>Numbers</h2>
+<pre><code>42
+123.456
+123.456e-789
+1e+3
+0o74
+0XAF</code></pre>
+
+<h2>Full example</h2>
+<pre><code>hGetLine h =
+ wantReadableHandle_ "Data.ByteString.hGetLine" h $
+ \ h_@Handle__{haByteBuffer} -> do
+ flushCharReadBuffer h_
+ buf <- readIORef haByteBuffer
+ if isEmptyBuffer buf
+ then fill h_ buf 0 []
+ else haveBuf h_ buf 0 []
+ where
+
+ fill h_@Handle__{haByteBuffer,haDevice} buf len xss =
+ len `seq` do
+ (r,buf') <- Buffered.fillReadBuffer haDevice buf
+ if r == 0
+ then do writeIORef haByteBuffer buf{ bufR=0, bufL=0 }
+ if len > 0
+ then mkBigPS len xss
+ else ioe_EOF
+ else haveBuf h_ buf' len xss
+
+ haveBuf h_@Handle__{haByteBuffer}
+ buf@Buffer{ bufRaw=raw, bufR=w, bufL=r }
+ len xss =
+ do
+ off <- findEOL r w raw
+ let new_len = len + off - r
+ xs <- mkPS raw r off
+
+ -- if eol == True, then off is the offset of the '\n'
+ -- otherwise off == w and the buffer is now empty.
+ if off /= w
+ then do if (w == off + 1)
+ then writeIORef haByteBuffer buf{ bufL=0, bufR=0 }
+ else writeIORef haByteBuffer buf{ bufL = off + 1 }
+ mkBigPS new_len (xs:xss)
+ else do
+ fill h_ buf{ bufL=0, bufR=0 } new_len (xs:xss)
+
+ -- find the end-of-line character, if there is one
+ findEOL r w raw
+ | r == w = return w
+ | otherwise = do
+ c <- readWord8Buf raw r
+ if c == fromIntegral (ord '\n')
+ then return r -- NB. not r+1: don't include the '\n'
+ else findEOL (r+1) w raw
+
+mkPS :: RawBuffer Word8 -> Int -> Int -> IO ByteString
+mkPS buf start end =
+ create len $ \p ->
+ withRawBuffer buf $ \pbuf -> do
+ copyBytes p (pbuf `plusPtr` start) len
+ where
+ len = end - start</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 -} baz"; "foo -- bar";</code></pre>
\ No newline at end of file
diff --git a/examples/prism-pascal.html b/examples/prism-pascal.html
new file mode 100644
index 0000000..7fd7997
--- /dev/null
+++ b/examples/prism-pascal.html
@@ -0,0 +1,68 @@
+<h1>Pascal</h1>
+<p>To use this language, use the class "language-pascal".</p>
+
+<h2>Comments</h2>
+<pre><code>(* This is an
+old style comment *)
+{ This is a
+Turbo Pascal comment }
+// This is a Delphi comment.</code></pre>
+
+<h2>Strings and characters</h2>
+<pre><code>'This is a pascal string'
+''
+'a'
+^G
+#7
+#$f4
+'A tabulator character: '#9' is easy to embed'</code></pre>
+
+<h2>Numbers</h2>
+<pre><code>123
+123.456
+132.456e-789
+132.456e+789
+$7aff
+&17
+%11110101</code></pre>
+
+<h2>Full example</h2>
+<pre><code>Type
+ Str25 = String[25];
+ TBookRec = Record
+ Title, Author,
+ ISBN : Str25;
+ Price : Real;
+ End;
+
+Procedure EnterNewBook(var newBook : TBookRec);
+Begin
+ Writeln('Please enter the book details: ');
+ Write('Book Name: ');
+ Readln(newBook.Title);
+ Write('Author: ');
+ Readln(newBook.Author);
+ Write('ISBN: ');
+ Readln(newBook.ISBN);
+ Write('Price: ');
+ Readln(newBook.Price);
+End;
+
+Var
+ bookRecArray : Array[1..10] of TBookRec;
+ i : 1..10;
+
+Begin
+ For i := 1 to 10 do
+ EnterNewBook(bookRecArray[i]);
+ Writeln('Thanks for entering the book details');
+ Write('Now choose a record to display from 1 to 10: ');
+ Readln(i);
+ Writeln('Here are the book details of record #',i,':');
+ Writeln;
+ Writeln('Title: ', bookRecArray[i].Title);
+ Writeln('Author: ', bookRecArray[i].Author);
+ Writeln('ISBN: ', bookRecArray[i].ISBN);
+ Writeln('Price: ', bookRecArray[i].Price);
+ Readln;
+End.</code></pre>
\ No newline at end of file
diff --git a/examples/prism-r.html b/examples/prism-r.html
new file mode 100644
index 0000000..8e33ac7
--- /dev/null
+++ b/examples/prism-r.html
@@ -0,0 +1,41 @@
+<h1>R</h1>
+<p>To use this language, use the class "language-r".</p>
+
+<h2>Comments</h2>
+<pre><code># This is a comment</code></pre>
+
+<h2>Strings</h2>
+<pre><code>"foo \"bar\" baz"
+'foo \'bar\' baz'</code></pre>
+
+<h2>Full example</h2>
+<pre><code># Goal: To make a latex table with results of an OLS regression.
+
+# Get an OLS --
+x1 = runif(100)
+x2 = runif(100, 0, 2)
+y = 2 + 3*x1 + 4*x2 + rnorm(100)
+m = lm(y ~ x1 + x2)
+
+# and print it out prettily --
+library(xtable)
+# Bare --
+xtable(m)
+xtable(anova(m))
+
+# Better --
+print.xtable(xtable(m, caption="My regression",
+ label="t:mymodel",
+ digits=c(0,3,2,2,3)),
+ type="latex",
+ file="xtable_demo_ols.tex",
+ table.placement = "tp",
+ latex.environments=c("center", "footnotesize"))
+
+print.xtable(xtable(anova(m),
+ caption="ANOVA of my regression",
+ label="t:anova_mymodel"),
+ type="latex",
+ file="xtable_demo_anova.tex",
+ table.placement = "tp",
+ latex.environments=c("center", "footnotesize"))</code></pre>
\ No newline at end of file
diff --git a/examples/prism-scala.html b/examples/prism-scala.html
new file mode 100644
index 0000000..f8649d5
--- /dev/null
+++ b/examples/prism-scala.html
@@ -0,0 +1,109 @@
+<h1>Scala</h1>
+<p>To use this language, use the class "language-scala".</p>
+
+<h2>Comments</h2>
+<pre><code>// Single line comment
+/* Mutli-line
+comment */</code></pre>
+
+<h2>Strings and characters</h2>
+<pre><code>'a'
+"foo bar baz"
+"""Multi-line
+string"""</code></pre>
+
+<h2>Numbers</h2>
+<pre><code>0
+21
+0xFFFFFFFF
+-42L
+0.0
+1e30f
+3.14159f
+1.0e-100
+.1
+</code></pre>
+
+<h2>Symbols</h2>
+<pre><code>'x
+'identifier</code></pre>
+
+<h2>Full example</h2>
+<pre><code>// Contributed by John Williams
+package examples
+
+object lazyLib {
+
+ /** Delay the evaluation of an expression until it is needed. */
+ def delay[A](value: => A): Susp[A] = new SuspImpl[A](value)
+
+ /** Get the value of a delayed expression. */
+ implicit def force[A](s: Susp[A]): A = s()
+
+ /**
+ * Data type of suspended computations. (The name froms from ML.)
+ */
+ abstract class Susp[+A] extends Function0[A]
+
+ /**
+ * Implementation of suspended computations, separated from the
+ * abstract class so that the type parameter can be invariant.
+ */
+ class SuspImpl[A](lazyValue: => A) extends Susp[A] {
+ private var maybeValue: Option[A] = None
+
+ override def apply() = maybeValue match {
+ case None =>
+ val value = lazyValue
+ maybeValue = Some(value)
+ value
+ case Some(value) =>
+ value
+ }
+
+ override def toString() = maybeValue match {
+ case None => "Susp(?)"
+ case Some(value) => "Susp(" + value + ")"
+ }
+ }
+}
+
+object lazyEvaluation {
+ import lazyLib._
+
+ def main(args: Array[String]) = {
+ val s: Susp[Int] = delay { println("evaluating..."); 3 }
+
+ println("s = " + s) // show that s is unevaluated
+ println("s() = " + s()) // evaluate s
+ println("s = " + s) // show that the value is saved
+ println("2 + s = " + (2 + s)) // implicit call to force()
+
+ val sl = delay { Some(3) }
+ val sl1: Susp[Some[Int]] = sl
+ val sl2: Susp[Option[Int]] = sl1 // the type is covariant
+
+ println("sl2 = " + sl2)
+ println("sl2() = " + sl2())
+ println("sl2 = " + sl2)
+ }
+}</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>Nested block comments</h3>
+<pre><code>/* Nested block
+ /* comments
+ are */
+not supported */</code></pre>
+
+<h3>Comment-like substrings</h3>
+<pre><code>"foo /* bar */ baz"; "foo // bar";</code></pre>
+
+<h3>Escaped characters</h3>
+<pre><code>'\u0041'</code></pre>
\ No newline at end of file