parser-combinators

How to parse placeholders from text without throwing away your sword so you can fight off the marauders with a lampshade.

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...

Expected type of Parser in method "|"

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...

Appending a label to immutable case classes in Scala

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...

How to write parser for unified diff syntax

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. ...

Parsing a blank / whitespace with RegexParsers

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...

How do I write a regex that matches all characters that are not a '$' followed by 'i' or '{'?

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 ...