I needed to parse placeholders out of text like abc $$FOO$$ cba. I hacked to together something with Scala's parser combinators, but I'm not really happy with the solution.
In particular, I resorted to a zero-width matcher in the regular expression (?=(\$\$|\z)) to stop parsing the text and start parsing the placeholders. This sounds pe...
I have the following code being compiled against scala 2.8.0:
import scala.util.parsing.combinator.{syntactical,PackratParsers}
import syntactical.StandardTokenParsers
object MyParser extends StandardTokenParsers with PackratParsers{
lexical.reserved ++= Set("int","char","boolean")
lazy val primitiveType:PackratParser[PrimitiveTyp...
Im trying to create a parser for a small language with commands including labels and goto:
...
lazy val cmds = opt("{")~>rep(cmd<~opt(";"))<~opt("}") ^^ {...}
lazy val cmd = ("if"~boolexpr~"then"~cmds~"else"~cmds
^^ { case _~b~_~c1~_~c2 => IFCMD(boolexpr,c1
| ident ~":="~numericLit ^^ {case i1~_~v => ASSIGN(i1,v) }
| "goto" ~>ide...
Should I use RegexParsers, StandardTokenParsers or are these suitable at all for parsing this kind of syntax? Example of the syntax can be found from here.
...
What is the problem with parsing the blank/whitespace?
scala> object BlankParser extends RegexParsers {
def blank: Parser[Any] = " "
def foo: Parser[Any] = "foo"
}
defined module BlankParser
scala> BlankParser.parseAll(BlankParser.foo, "foo")
res15: BlankParser.ParseResult[Any] = [1.4] parsed: foo
scala> Blank...
Meaning, I want to match:
$10
or
$
but not this:
${name}
or:
$image{http://wrfgadgadga.com/gadgad.png}
I also want to match everything else... normal characters, symbols, numbers, etc.
Matching everything but things that start with $ is easy. It's like this:
def literalCharacter: Parser[String] = """[^\$]""".r
I've tried ...