blob: abb5efd208d94a1e072c3ed85d992c68a36993ab (
plain) (
blame)
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
|
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2009, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $Id$
package scala.util.regexp
/** Basic regular expressions.
*
* @author Burak Emir
* @version 1.0
*/
abstract class Base
{
type _regexpT <: RegExp
abstract class RegExp {
val isNullable: Boolean
}
object Alt {
/** Alt( R,R,R* ) */
def apply(rs: _regexpT*) =
if (rs.size < 2) throw new SyntaxError("need at least 2 branches in Alt")
else new Alt(rs: _*)
// Can't enforce that statically without changing the interface
// def apply(r1: _regexpT, r2: _regexpT, rs: _regexpT*) = new Alt(Seq(r1, r2) ++ rs: _*)
def unapplySeq(x: Alt) = Some(x.rs)
}
class Alt private (val rs: _regexpT*) extends RegExp {
final val isNullable = rs exists (_.isNullable)
}
object Sequ {
/** Sequ( R,R* ) */
def apply(rs: _regexpT*) = if (rs.isEmpty) Eps else new Sequ(rs: _*)
def unapplySeq(x: Sequ) = Some(x.rs)
}
class Sequ private (val rs: _regexpT*) extends RegExp {
final val isNullable = rs forall (_.isNullable)
}
case class Star(r: _regexpT) extends RegExp {
final lazy val isNullable = true
}
// The empty Sequ.
case object Eps extends RegExp {
final lazy val isNullable = true
override def toString() = "Eps"
}
/** this class can be used to add meta information to regexps */
class Meta(r1: _regexpT) extends RegExp {
final val isNullable = r1.isNullable
def r = r1
}
}
|