Fork me on GitHub
#instaparse
<
2016-04-21
>
bwstearns03:04:30

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

aengelberg03:04:44

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

aengelberg03:04:01

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

bwstearns03:04:18

@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.

aengelberg03:04:27

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

aengelberg03:04:34

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.

bwstearns03:04:57

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.

aengelberg03:04:48

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

bwstearns03:04:27

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

bwstearns03:04:38

@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.

aengelberg03:04:41

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

bwstearns03:04:30

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?

aengelberg03:04:30

#'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

bwstearns04:04:53

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

aengelberg04:04:03

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