- About Scala
- In the Enterprise
- Scala Community
- Language Research
- In the Press
- The Scala Team
- Scala's Prehistory
- Contact Us
- Learning Scala
- Tour of Scala
- Scala API
- Setup & Getting Started
- Programming Guides
- Other Guides
- Code Examples
- Scala Developers
How to handle a superclass constructor call with a complex condition?
Sat, 2009-01-17, 21:13
As my Scala learning exercise, I'm writing a little library to allow
regular expressions to be dealt with at a more abstract level. One of
the classes I have is this short one:
protected case class RawCharSet(in:String, notIn:String) extends
Matcher("[" + in + (if (notIn =="") "" else "&&[^" + notIn + "]")
Basically, it produces regular expressions like [abc] if the second
argument is "", or [abc&&[^def]] if the second argument is a value
such as "def".
However, this is less than readable. I'd like to factor it into a form
where the the string argument is built first, and then the constructor
(or superclass constructor, with the code organization above) is
called--but that's not possible, as even for auxiliary constructors,
the first statement must be a call on "this(...)".
Any tricks I'm not aware of that you can suggest?