Created
July 16, 2011 15:06
-
-
Save anonymous/1086425 to your computer and use it in GitHub Desktop.
This code will never end
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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