Building a regex with packrat parsers in Scala

I have two packrat parsers in scala:

val symbols : PackratParser[String] =
    "{" | "}" | ">"

val keywords : PackratParser[String] =
    "BOOL" | "INT"

I want to build a parser that can recognise if a statement is composed of one or more of those two parsers. The way I'd usually do it is:

val statement : PackratParser[String] =
    regex( "[symbols | keywords]+".r )

But that wouldn't work because they're thinking I want the actual "symbols" or "keywords" token... Can anyone help?


You can't use a regex this way. However, the whole point of parser combinators is that they can be combined!

val statement : PackratParser[List[String]] =
    rep1(symbols | keywords)

Need Your Help

Does sonar analyse code in test directory of a Maven project?

maven junit sonarqube

Does sonar analyse code in test directory of Maven project ?

Classes in Python

python class

In Python is there any way to make a class, then make a second version of that class with identical dat,a but which can be changed, then reverted to be the same as the data in the original class?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.