Hey,
I’m building a parser in Scala 3 for some log files and I’d like to create some enums that represent the different handled tokens. Here are the enums :
enum RawLogToken(val line: Int):
case TimestampToken(ts: Timestamp, override val line: Int) extends RawLogToken(line)
case TextBlockToken(text: String, override val line: Int) extends RawLogToken(line)
case LogLineToken(text: String, override val line: Int) extends RawLogToken(line)
case UnknownToken(text: String, override val line: Int) extends RawLogToken(line)
As you can see, this enum has the line number from the read file. This compiles fine.
But in the next step of the parsing pipeline, I try to separate the different values into different sub-enums:
sealed trait LogLine(val line: Int)
enum HeaderLine(line: Int) extends LogLine(line):
case Rank(i: Int, override val line: Int) extends HeaderLine(line)
/* a lot of other cases */
enum IterationLine(line: Int) extends LogLine(line):
case BeginIteration(ts: Timestamp, number: Int, override val line: Int) extends IterationLine(line)
/* a lot of other cases */
enum DismissLine(line: Int) extends LogLine(line): // lines we don't really care about
case ConnectionSetup(override val line: Int) extends DismissLine(line)
/* a lot of other cases */
This gives warning that the ‘override val’ in the cases is a deprecated way of doing things.
What is the recommended way of solving this ? Do I have to fall back to sealed traits and case classes instead of enums ?
Best,
MRandl