Extractor composition with dependent sub-patterns

2019-08-10 05:40发布

问题:

Is it possible to define an extractor that is composed such that a sub-pattern depends on a previously matched sub-pattern?

Consider matching a date pattern, where valid "days" depends on the matched "month".

This is to avoid a guard to compare values bound by the sub-patterns, and also to avoid providing an overly-customized extractor.

Sample syntax:

case r"\d{4}-$month\d{2}-${day filter month.allows}\d{2}" => s"$month $day"

回答1:

Perhaps you can formulate it under the aegis of this behavior:

https://issues.scala-lang.org/browse/SI-796

That is, before they fix it.



标签: scala