Search code examples
scalaparser-combinators

How to "dequote" a stringLiteral in Scala parser combinator?


I was wondering if there is an easy way I'm unaware of at the moment to remove " characters from the beginning and end of a stringLiteral captured by a TokenParser?

I searched through the Scaladocs but haven't found a handy util function for it. Yeah, I can surely do it by playing with substring(1, str.length - 1) but my gut feeling is that it is already written somewhere I'm just cannot find it :-)

Thanks in advance!


Solution

  • If you want to use stringLiteral from JavaTokenParsers you could create your own parser based on it:

    def deguoted: Parser[String] = stringLiteral ^^ {str => str.substring(1, str.length - 1)}