Fork me on GitHub

I think it might be an instance of lacking the right words to google for the answer effectively.


@bwstearns: You could concatenate all the strings as a transform step.


i.e. unhide the letter and number tags, but add :letter str, :number str into your transformer map.


@aengelberg: that's what I'm doing now. Because I'm doing it for a bunch of tags I was wondering if there was something built in for handling that as a common case or not.


Other than regexes, there's no way to concatenate strings in a way specified entirely by the instaparse grammar.


The transform approach is the easiest way I could think of out of all the "do something to the tree, fresh out of the parser" possible approaches.


That makes sense. I think what I'll do is put the preprocessor transforms into another hash to keep the more meaninful transform actions less cluttered and then merge them right before usage.


That can work. Or just call insta/transform twice, if you don't mind the performance impact of traversing the tree twice.


that works too. I don't think I have any performance issues on the horizon with this project.


@aengelberg: thanks a ton for taking a look. The question got some foot traffic but no feedback. If you're looking for internet points feel free to drop what you said in there and I'll accept it. Otherwise I'll copy it in as an own-answer for the next person.


@bwstearns: Any time! I've added an answer to your post


awesome. thanks. Didn't think about the performant part, is that primarily due to the extra step of having to transform it or is it because regexes are inherently faster than using parser rules?


#'a+' is faster than 'a'+, as letting regexes do the work of searching for all possible "a"s is faster than having instaparse do that work


Right, that makes sense because of the greediness. Thanks a ton for taking the time on this.


It's not exactly *because* of the greediness, it's just speedier when a Java program is doing this task than Clojure simple_smile