PrintingParser version of Arithmetic.swift example? #315
-
I'm finding this library intriguing, but I'm also having a hard time figuring how to use it. In particular I'm having trouble building recursive parsers with infix operators while getting the benefit of PrintingParser. I think most of my questions would be answered if there was a PrintingParser version of the Arithmetic parser. Does such an example exist? And if not can anyone outline the steps needed to make a PrintingParser version of the Arithmetic example that worked on this enum:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
I've made related progress (boolean parser instead of Arithmetic). I think I have everything working, but the code needs simplification. In particular I'm having to use a custom converter for The converter code is repetitive. I think I can get rid of the repetition with a custom converter, but I'm not understanding the type system well enough to create the converter. Could someone help me with a converter to remove the duplicate code. I think it would look like this when used:
And it will take two params of BooleanExpression type. The second one optional. Then run the same logic that I'm using in the
|
Beta Was this translation helpful? Give feedback.
-
Ok, I've got something! This isn't the Arithmetic printer parser, but it's a boolean expression printer parser, which is the same thing as far as I'm concerned. Again, my goal was to learn the best way to build recursive parsers, with infix operators, while getting the benefit of printing parser. From what I can tell this is fully working, while also avoiding redundant code and fitting into the swift-parsing design. Before I go and implement a full parser based on this design I would love any feedback that you might have.
Thanks,
|
Beta Was this translation helpful? Give feedback.
-
Closing this, what I have seems to be working well. |
Beta Was this translation helpful? Give feedback.
Closing this, what I have seems to be working well.