From 31023fba3c6d6e2d197d6802779cdc65d250e93e Mon Sep 17 00:00:00 2001 From: nebulon42 Date: Sun, 2 Jul 2017 12:49:39 +0200 Subject: [PATCH] allow expressions in filters, fixes #377 --- CHANGELOG.md | 2 ++ docs/styling_concepts.rst | 5 +++++ lib/carto/parser.js | 1 + test/rendering-mss/issue_377.mss | 3 +++ test/rendering-mss/issue_377.xml | 6 ++++++ 5 files changed, 17 insertions(+) create mode 100644 test/rendering-mss/issue_377.mss create mode 100644 test/rendering-mss/issue_377.xml diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ec0b65b0..2e3fe0c77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ There is a new command line / API switch (`-q / --quiet` / `quiet`) to suppress (`-o / --output` / `outputFormat`) to choose the output format. Possible values are `mapnik` (default) for Mapnik XML and `json` for the JSON variant (part of [#413](https://github.com/mapbox/carto/issues/413)). For Mapnik XML all character data as tag content is now prefixed with CDATA. +* Expressions are allowed in filters e.g. `[height] % 50 = 0` or `[height] + 10 = 0`, fields have to be properly written within brackets +([#377](https://github.com/mapbox/carto/issues/377)) ### Breaking changes diff --git a/docs/styling_concepts.rst b/docs/styling_concepts.rst index 8aa5a9195..1184665da 100644 --- a/docs/styling_concepts.rst +++ b/docs/styling_concepts.rst @@ -134,3 +134,8 @@ String comparisons:: /* a regular expression over name */ #world[name =~ "A.*"] + +More complex expressions:: + + #world[[population] % 50 = 0] + #world[[population] * 2 < 1000] diff --git a/lib/carto/parser.js b/lib/carto/parser.js index 22b4d9624..5de8b861b 100644 --- a/lib/carto/parser.js +++ b/lib/carto/parser.js @@ -547,6 +547,7 @@ carto.Parser = function Parser(env) { /*eslint-disable no-cond-assign */ if (key = $(/^[a-zA-Z0-9\-_]+/) || $(this.entities.quoted) || + $(this.expression) || $(this.entities.variable) || $(this.entities.keyword) || $(this.entities.field)) { diff --git a/test/rendering-mss/issue_377.mss b/test/rendering-mss/issue_377.mss new file mode 100644 index 000000000..0e0e750e7 --- /dev/null +++ b/test/rendering-mss/issue_377.mss @@ -0,0 +1,3 @@ +[[height] % 50 = 0] { + marker-fill: red; +} diff --git a/test/rendering-mss/issue_377.xml b/test/rendering-mss/issue_377.xml new file mode 100644 index 000000000..bd992d1c1 --- /dev/null +++ b/test/rendering-mss/issue_377.xml @@ -0,0 +1,6 @@ +