Creating Grammar Strings in ScalaCheck

In Scala, I have a grammar implemented using the Parser Combinators library. Now, what I want to do is generate random strings, given the grammar from the parser combinator library.

It seems to me that the ScalaCheck library does this in a way opposite to the Parser combinators in that it combines generators instead of parsers.

Is there a way to generate strings using Parser or ScalaCheck Combiners, or is there an easy way to convert a Parser Combiner to a generator?

+6
source share
1 answer

There is no easy way to convert your grammar into generators. You must write them manually. And it will not be so difficult, because you already have a grammar. You can easily test your parser, but testing your controller can be quite problematic (but still possible). Before you begin, make sure your AST nodes can be compared with each other.

  • Scalacheck allows you to create recursive properties, so you can easily create AST nodes.
  • When you create your AST nodes, you can use Scalacheck and some additional knowledge about white spaces and their praise between the nodes translated into lines.
  • Then you can pass the generated lines to the parser, you are going to check the code and compare them with a preformed AST
+1
source

All Articles