15 Oct 22:35
RegexParsers implicits confusing my code
From: David J. Biesack <David.Biesack <at> sas.com>
Subject: RegexParsers implicits confusing my code
Newsgroups: gmane.comp.lang.scala
Date: 2008-10-15 20:38:23 GMT
Subject: RegexParsers implicits confusing my code
Newsgroups: gmane.comp.lang.scala
Date: 2008-10-15 20:38:23 GMT
I'm trying to define a regex parser that ignores case, so "do" and "Do" and "DO" all match.
Why does the following object compile:
Process inferior-scala finished
Welcome to Scala version 2.7.2.RC3 (Java HotSpot(TM) Client VM, Java 1.6.0).
Type in expressions to have them evaluated.
Type :help for more information.
scala> object MyParser {
type Elem = Char
def ire(s:String) : String = s.map((c:Char) => "(" + c.toUpperCase + "|" + c.toLowerCase + ")").reduceLeft(_+_)
def tokeni(s:String) = ire(s).r
val DO = tokeni("DO")
val WHILE = tokeni("WHILE")
}
defined module MyParser,
This works as I expect:
scala> MyParser.DO
res0: scala.util.matching.Regex = (D|d)(O|o)
scala> MyParser.WHILE
res1: scala.util.matching.Regex = (W|w)(H|h)(I|i)(L|l)(E|e)
However, the following fails when I add RegexParsers:
(Continue reading)
RSS Feed