Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Python
Cannot retrieve the latest commit at this time.
Permalink
| Failed to load latest commit information. | |||
|
|
mapcss_parser |
|
|
|
|
test |
|
|
|
|
.gitignore |
|
|
|
|
LICENSE |
|
|
|
|
README |
|
|
|
|
mapcss-parser.py |
|
|
|
|
setup.py |
|
|
README
This is MapCSS parser I use in my OSM rendering. I've tried to implement spec from http://wiki.openstreetmap.org/wiki/MapCSS but it's not very formal, so the implementation may doesn't match with your vision of MapCSS. This parser use PLY (http://www.dabeaz.com/ply) library. == Dependency sudo pip install ply == Installation sudo python setup.py install == Layout mapcss_parser/ast.py - Abstract Syntax Tree classes mapcss_parser/lex.py - Lexer mapcss_parser.py - MapCSS parser entry point mapcss_parser/parse.py - Parser test/parser_test.py - Unit tests of MapCSS parser == Usage Simple way to see MapCSS parser in action is use CLI: > python mapcss-parser.py <YOUR_MAP_CSS_FILE> This script will parse your file to AST, and build it again from AST to MapCSS. Not very useful, ah? More complex example. I use this parser to convert MapCSS to the code. So I've just mixed-in necessary methods directly to AST classes. import sys sys.path.insert(0,"../mapcss-parser") from mapcss_parser import MapCSSParser import ast if len(sys.argv) != 2: print "usage : mapcss.py inputfile" raise SystemExit content = open(sys.argv[1]).read() parser = MapCSSParser(debug=False) mapcss = parser.parse(content) def mapcss_convert(self): imports = "".join(map(lambda imp: propagate_import(imp.url).as_js, self.imports)) rules = "\n".join(map(lambda x: x.as_js(), self.rules)) return "%s%s" % (imports, rules) ast.MapCSS.convert = mapcss_convert ... And so on for other 13 AST classes print mapcss.convert() If you have questions about MapCSS parser, you can find me on #osm and #osm_ru IRC channels, of e-mail me to <mr.miroff@gmail.com>