What's the purpose of ElementFilterExpression parsing? #3302
-
Naively, I'd assume that once you parsed the elements into Kotlin objects, you'd filter them directly with Kotlin code. And indeed, under the hood that's what happens — the string is parsed into an So what's the purpose of the extra level of abstraction, writing them as strings? Is it to match query syntax from somewhere else in the OSM ecosystem (e.g. overpass)? (In more academic terms, why write a DSL instead of a library?) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
It makes it easier to edit/read it? How else it would be written? As instantiation of several objects and putting them together? |
Beta Was this translation helpful? Give feedback.
-
Part of my motivation for asking this question was: The way filter expressions are currently written, there's very little shared code. For something like #3301, the same logic would need to be duplicated for each quest which should have the same restrictions. That makes it hard to ensure that quests which target the same "base" set of elements do so consistently. There's good reasons to be cautious about de-duplicating here. Surely, there's lots of incidental duplication, which would only tie together otherwise-unrelated functions if we tried to pull out the common code. But I think it's at least still worth exploring. With the current approach, it's technically *possible* to split up and re-use sections of a filter.val isFoot = "foot != no"
val isTrafficSignals = "highway = traffic_signals and crossing = traffic_signals"
val isCrossing = "highway = crossing" private val crossingFilter by lazy { """
nodes with
(
$isTrafficSignals and $isFoot
or $isCrossing and $isFoot
)
""".toElementFilterExpression() } However, at that point, in my opinion, we've thrown away any readability advantage compared to what I wrote in the thread above (converted to an extension function) private val crossingFilter: Element.() -> Boolean = {
this is Node &&
(
isTrafficSignals && isFoot
|| isCrossing && isFoot
)
} |
Beta Was this translation helpful? Give feedback.
It makes it easier to edit/read it? How else it would be written? As instantiation of several objects and putting them together?