Skip to content

Instantly share code, notes, and snippets.

@aereal
Created June 14, 2011 18:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aereal/1025517 to your computer and use it in GitHub Desktop.
Save aereal/1025517 to your computer and use it in GitHub Desktop.
// vim:set noet sw=3 ts=3 sts=3
import scala.util.parsing.combinator._
import java.io.FileReader
class XselfParser extends RegexParsers {
def expression: Parser[Any] = opt("(")~rep(identifier)~opt(")")
def identifier: Parser[Any] = rep("""[a-zA-Z0-9]""".r | symbol)
def symbol: Parser[Any] = "~" | "!" | "@" | "$" | "%" | "^" | "&" | "*" | "-" | "_" | "=" | "+" | "|" | ":" | "<" | ">" | "/" | "?"
}
object Xself extends XselfParser {
def main(args: Array[String]) {
val reader = new FileReader(args(0))
println(parseAll(expression, reader))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment