Skip to content

Instantly share code, notes, and snippets.

@filosganga
Created February 17, 2015 23:15
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 filosganga/455f81372e71bf629be3 to your computer and use it in GitHub Desktop.
Save filosganga/455f81372e71bf629be3 to your computer and use it in GitHub Desktop.
CSS Parser
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