Created
February 17, 2015 23:15
-
-
Save filosganga/455f81372e71bf629be3 to your computer and use it in GitHub Desktop.
CSS Parser
This file contains hidden or 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 util.parsing.combinator.JavaTokenParsers | |
case class Rule(val selectors : List[String], val properties : List[Property]) | |
case class Property(name: String, value: String) | |
object CssParser extends JavaTokenParsers { | |
def rules = rule+ | |
private def rule = selectors ~ properties ^^ { | |
case s ~ p => Rule(s,p) | |
} ; | |
private def selectors = repsep(selector, ","); | |
private def selector = """[A-Za-z0-9-_~:#=">$\*\.\[\]\|\s\^\+\(\)]+""".r; | |
private def properties = "{" ~> repsep(property, ";") <~ "}"; | |
private def property = propertyName ~ propertyValue ^^ { | |
case n ~ v => Property(n,v); | |
}; | |
private def propertyName = """([\w\d-_]+)""".r <~ ":"; | |
private def propertyValue = """[^;}]+""".r; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment