Skip to content

Instantly share code, notes, and snippets.

Created July 16, 2011 15:06
Show Gist options
  • Save anonymous/1086425 to your computer and use it in GitHub Desktop.
Save anonymous/1086425 to your computer and use it in GitHub Desktop.
This code will never end
import org.parboiled.scala._
import org.parboiled.support._
import org.parboiled.support.ParseTreeUtils
class HamlParser extends Parser {
def Haml = rule {
WhiteSpace ~ Doctype ~ EOI
}
def Doctype = rule {
str("!!!") ~ WhiteSpace ~ Inline
}
def Inline = rule {
oneOrMore(anyOf(Characters.allBut("\r\n"))) // This line is the reason
}
def WhiteSpace: Rule0 = rule { zeroOrMore(anyOf(" \n\r\t\f")) }
def NewLine = rule {
"\n" | "\r" ~ optional("\n")
}
}
object HamlParser {
def main(args: Array[String]) {
val input = """
!!! ABC"""
val parser = new HamlParser { override val buildParseTree = true }
val result = ReportingParseRunner(parser.Haml).run(input)
val out = ParseTreeUtils.printNodeTree(result)
if (!result.matched) {
println(result.parseErrors.mkString("---\n"))
}
println(out)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment