Allow ^^ in Rule1[] on token (see here) so that I can write `NUMBER ^^ (.toInt)`.
~Allow a single token as right hand side of a rule (see here), so that I don't have to explicitly call singletonRule.~
Infer better type for regular operations on Rule1[_]
optional (?) (see here), so that I get the type def Optional: Rule[Option[String] :: HNil] = NUMBER ?.
positive closure (+) (see here), so that I get the type def Optional: Rule[(String :: HNil) :: Option[String :: HNil] :: HNil] = NUMBER +.
kleene (see here), so that I get the type def Optional: Rule[List[String :: HNil] :: HNil] = NUMBER *.
Infer scanner- and parser-rule-types to make the definition of a grammar easier
@grammar
class TestParser {
import scala.language.postfixOps
val digit : RegExp = regex("[0-9]")
val number: RegExp = digit *
val NUMBER: Token = token(number)
@start def S = NUMBER
}
The example above triggers the error: 'TestParser.this.NUMBER' is not a token!, because the implicit conversion from Token -> Rule1[String] doesn't trigger and thus the macro doesn't accept the parse-rule definition. Explicitly annotating the rule S with the type Rule1[String] will get rid of the error. A smarter grammar analysis could trigger the implicit conversion manually.
^^
in Rule1[] on token (see here) so that I can write `NUMBER ^^ (.toInt)`.singletonRule
.~Rule1[_]
?
) (see here), so that I get the typedef Optional: Rule[Option[String] :: HNil] = NUMBER ?
.+
) (see here), so that I get the typedef Optional: Rule[(String :: HNil) :: Option[String :: HNil] :: HNil] = NUMBER +
.def Optional: Rule[List[String :: HNil] :: HNil] = NUMBER *
.Infer scanner- and parser-rule-types to make the definition of a grammar easier
The example above triggers the error:
'TestParser.this.NUMBER' is not a token!
, because the implicit conversion from Token -> Rule1[String] doesn't trigger and thus the macro doesn't accept the parse-rule definition. Explicitly annotating the ruleS
with the typeRule1[String]
will get rid of the error. A smarter grammar analysis could trigger the implicit conversion manually.