blob: 92195eff42f80f6120d8956374d2b173a8b1a54c (
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
67
68
69
70
71
72
73
74
75
76
|
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
** __\ \/ /__/ __ |/ /__/ __ | **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
// $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
}
/** Alt( R,R,R* ) */
case class Alt(rs: _regexpT*) extends RegExp {
// check rs \in R,R,R*
// @todo: flattening
if ({ val it = rs.elements; !it.hasNext || {it.next; !it.hasNext }})
throw new SyntaxError("need at least 2 branches in Alt");
final val isNullable = {
val it = rs.elements
while (it.hasNext && it.next.isNullable) {}
!it.hasNext
}
}
case class Sequ(rs: _regexpT*) extends RegExp {
// @todo: flattening
// check rs \in R,R*
if ({ val it = rs.elements; !it.hasNext })
throw new SyntaxError("need at least 1 item in Sequ")
final val isNullable = {
val it = rs.elements
while (it.hasNext && it.next.isNullable) {}
!it.hasNext
}
}
case class Star(r: _regexpT) extends RegExp {
final val isNullable = true
}
case object Eps extends RegExp {
final 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
}
final def mkSequ(rs: _regexpT *): RegExp =
if (!rs.elements.hasNext)
Eps
else
Sequ(rs:_*)
}
|