100 lines
2.4 KiB
Java
100 lines
2.4 KiB
Java
|
<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>
|