"updateDet" shouldnt recognize as keyword "update"

57 views Asked by At

With this code

import scala.util.parsing.combinator.JavaTokenParsers

class TestKeywords  extends JavaTokenParsers {

  def keywords: Parser[String] = "update"

  def identifier: Parser[String] = not(keywords) ~> """[a-zA-Z0-9_$#]+""".r

  def script: Parser[Any] = repsep(identifier,",")
}

object TestKeywordsApp extends TestKeywords with App {
  val cmd = """updateDet,update"""
  parseAll(script,
    cmd.stripMargin) match {
    case Success(lup, _) => println(lup)
    case x => println(x)
  }
}

i get error

[1.1] failure: string matching regex \z' expected butu' found

updateDet,update

How to fix it? updateDet shouldnt recognize as keyword

scala 2.10.2

1

There are 1 answers

0
Armali On

word boundaries perhaps – Amit Joki

To expand, you've said that identifier is not(keywords) followed by some characters. But updateDet isn't that - it does start with a keyword. Perhaps you should declare that a keyword ends with a word boundary (regex \b)? – lmm