cartoshka
CartoCSS (carto) parser for Java. All it does is translate CartoCSS to a traversable hierarchy of Java classes.
Features
- Light weight
- High Performance
- Full support of CartoCSS syntax
- Single jar with no additional dependencies
Setup
WARNING: It's a development version and it may not work as expected.
Add the following to your maven configuration or taylor to your own dependency management system.
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.2gis.cartoshka</groupId>
<artifactId>cartoshka</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
</dependencies>
Quickstart
Look at the simple example below
CartoParser parser = new CartoParser();
try (FileReader reader = new FileReader(file)) {
// parsing the file
Block style = parser.parse(file.getName(), reader);
// constant folding
style.accept(new ConstantFoldVisitor(), null);
// pretty print
String pretty = style.accept(new PrintVisitor(2), null);
System.out.println(pretty);
} catch (IOException e) {
e.printStackTrace();
}