Replies: 11 comments
-
The issue you've seen was more about generating a grammar at run-time, which is why we closed it as "wont-fix". For the AST, we made some experiments and the result is included in the examples. It's already quite powerful, but we are not sure about the interface's stability. You could give it a try and we'd be happy to receive some feedback, if there are any issues please let us know as well and we can try to improve it. |
Beta Was this translation helpful? Give feedback.
-
Would love to see the interface become more stable. I am currently experimenting with it and it is really useful. Maybe adding source location info would be a next step? |
Beta Was this translation helpful? Give feedback.
-
@samvv It does contain the source location, the example is printing it out in the |
Beta Was this translation helpful? Give feedback.
-
Whoops my bad, I went over it too quickly. But yes in fact that would be required ... I'm thinking of how Clang does it with a Conditionally enabling at compile-time sounds like a good solution for now 👍 |
Beta Was this translation helpful? Give feedback.
-
@samvv I've decided to keep it simple for now and simply added the source. Changing the source handling from a string to an ID sounds interesting, but it will be a 3.0-thing as it'll break the existing API, we'll consider it another time. And for the efficiency, there are even better ways than separately storing the file ID, line, column and byte, for now this is beyond the 2.x-scope. Note that for matches that store a range, we only store the source once - the one active at the begin of the match. I hope this is good enough for you? |
Beta Was this translation helpful? Give feedback.
-
That's perfect, thanks for being so quick! 😃 |
Beta Was this translation helpful? Give feedback.
-
FYI: I just refactored the parse tree support and added some initial documentation. Let me know if you have any questions, remarks, etc. |
Beta Was this translation helpful? Give feedback.
-
I've added a new repo: https://github.com/skyrich62/stringID, which maps unique strings onto integers. It's header only and doesn't require hashing. The interface is simple: auto id = stringID::from_string("foo");
std::cout << id.name(); This class can be used to easily store filenames as a |
Beta Was this translation helpful? Give feedback.
-
@skyrich62 Cool, thanks for the tip! I really don't know if it is the best method for this project, but it to me personally it certainly sounds something worth giving a shot. A short note, though. You seem to be using |
Beta Was this translation helpful? Give feedback.
-
@samvv Hi. I thought that the number of strings, (filenames in this case), would be fairly small. But if unordered_map makes more sense to you, by all means use that. :) I use this technique in my work, and the performance really isn't a problem. |
Beta Was this translation helpful? Give feedback.
-
Since this thread of discussion seems to have petered out, and we have since added some parse tree support, we are closing this issue. Feel free to open a new one if there are any questions to the current state of the parse tree support and/or suggestions on how to further improve on it. |
Beta Was this translation helpful? Give feedback.
-
I'm looking for a C++ parsing library that will easily let me generate an AST. I saw #20 and that seemed close, but I don't care if the grammar is read in at runtime or compile-time. I've had good experiences building compilers in other languages separating out parsing, type checking, and semantics into separate stages that all operate on a (sometimes decorated) AST. Is this something planned?
Beta Was this translation helpful? Give feedback.
All reactions