-
Did I already mention that I simply love PEGTL? It has saved me tonnes of time! However, I'm recently having a problem with parsing an indentation-sensitive language very similar to Haskell. How would one go to tackle this particular problem in a "neat" way? One naive solution I thought of is by replacing every (hidden) occurrence of |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
I went on to hack the source in order to force |
Beta Was this translation helpful? Give feedback.
-
Never mind; I just went on to learn from this answer that relying on "global" state using a PEG parser can cause unwanted side-effects. Will have to find another tool that can handle the job 😢 |
Beta Was this translation helpful? Give feedback.
-
While the expressive power of PEGs can be a limit, the PEGTL allows for arbitrary custom rules with arbitrary state which can basically parse "everything"; perhaps we can add an example for an indentation-sensitive grammar to the PEGTL. |
Beta Was this translation helpful? Give feedback.
-
@ColinH Oh really, even with location-dependant indentation? Then my reasoning was wrong! Would love to see such an example. Would make it myself but that's where the problem lies. 😅 Maybe a a very basic Python-ish language, if I may make a suggestion? |
Beta Was this translation helpful? Give feedback.
-
Is it possible to see the source and/or specification for the language you are trying to parse? We don't have any experience with designing PEGTL grammars for indentation-aware languages yet, and the toy example I just wanted to implement seems to be too simple, it doesn't really pose any problem. (Global state with a stack of indentation scopes; the rule for every line starts with Speaking of a global parser state, that can be a general issue with PEGs; in the case of the PEGTL this role is taken by the state variables passed to the PEGTL |
Beta Was this translation helpful? Give feedback.
-
I just added an (improved over yesterday's version) example for how one could handle a Python-style indentation aware grammar in |
Beta Was this translation helpful? Give feedback.
I just added an (improved over yesterday's version) example for how one could handle a Python-style indentation aware grammar in
src/example/pegtl/indent_aware.cpp
. For now the code is not particularly elegant, but it does seem to work for the very simplified language that it is intended to recognise, including the check for whether anelse
has a matching precedingif
.