Implement Top level Language Parser #60
-
Right now I'm trying to implement a simple language parser for a toy language I made up. Looks something like:
Right now I have a The result I am currently getting is only getting the first element parsed. So just 1 +2 or func test(...) if the that's what's first. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 7 replies
-
That should be the behavior that is already happening. Can you post a minimal example? Preferable on the playground: https://lexy.foonathan.net/playground/ |
Beta Was this translation helpful? Give feedback.
-
https://lexy.foonathan.net/playground/?id=xe1eKx3bs&mode=tree Here's the most minimal and stripped down example that illustrates the problem. |
Beta Was this translation helpful? Give feedback.
-
Nevermind my previous answer. I found a solution that is a lot simpler: https://lexy.foonathan.net/playground/?id=rsaecr3nr&mode=tree Don't allow newlines at the top-level and use them as separator, do allow newlines inside a |
Beta Was this translation helpful? Give feedback.
-
Okay, this is the one I think: https://lexy.foonathan.net/playground/?id=8xvo6zhvM&mode=tree The idea is again to override whitespace while parsing a nested value. However, this doesn't handle You need to do something similar if you want newlines in the parameters as well. |
Beta Was this translation helpful? Give feedback.
Okay, this is the one I think: https://lexy.foonathan.net/playground/?id=8xvo6zhvM&mode=tree
The idea is again to override whitespace while parsing a nested value. However, this doesn't handle
func f() {\n}
orfunc f(){\nnull;}
, as whitespace is only skipped after something. So instead ofdsl::curly_bracketed
we can define or own brackets that skip whitespace after the initial{
. It's not elegant, but it works.You need to do something similar if you want newlines in the parameters as well.