Scala: Find doubled words

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Scala: Find doubled words

Sonson
I try to find double words in a String like "Test Test" with a Scala Parboiled Grammar (The real grammar is much more complex).

My first attempt to solve the problem:

  def DoubleWord: Rule0 = rule {
    var firstWord: String = null
    Word ~% (firstWord = _) ~ " " ~ firstWord
  }
 
  def Word = rule { oneOrMore(!(" ") ~ Letter) }
  def Letter = rule { "a" - "z" | "A" - "Z" }

But this doesn't work, firstWord will always stay null.

I have seen a similar problem solved in the Markdown-Parser Pegdown https://github.com/sirthias/pegdown/tree/master/src/main/java/org/pegdown when matching full Html blocks (line 485). Is there anything like the @DontSkipActionsInPredicates-annotation (which is used in Pegdown) in Scala Parboiled?
Loading...