BjoernLoetters / macrowave

MIT License
4 stars 0 forks source link

Allow type annotations in scanner/parser #24

Open keddelzz opened 7 years ago

keddelzz commented 7 years ago

Allow:

token( ("a-z".r) : RegExp )

and

val numToken: Token = regex("[a-z]").+
def Expression: Rule1[Int] = (numToken : Rule1[String]) ^^ (_.toInt)

but disallow

def Expr: Rule1[String] = (regex("[a-z]+") : Token) : Rule1[String]

(No "anonymous" tokens allowed!)

BjoernLoetters commented 7 years ago

but disallow

def Expr: Rule1[String] = (regex("[a-z]+") : Token) : Rule1[String]

Independently of the type annotation we need to look up the definition of the token which is used in the rule. If this definition is not of type Token (the user probably triggered the implicit to convert a RegExp to a Token) or the expression does not even refer to a definition (the user probably wrote regex("[a-z]+") directly into the parser rule as seen above), the macro should not accept the grammar specification.