zevv / npeg

PEGs for Nim, another take
MIT License
330 stars 22 forks source link

Parsing indentation-based grammars #34

Closed xigoi closed 3 years ago

xigoi commented 3 years ago

Many languages, including Nim, use indentation to represent a tree structure. Would it be possible to add a mechanism for parsing such languages into NPEG? Indentation-based grammars are not strictly context-free, but it's quite easy to convert them into a context-free grammar by introducing special “indent” and “dedent” tokens, representing a change in the indentation level, which can then work like brackets.

zevv commented 3 years ago

Hi Adam,

Is this helpful?

https://github.com/zevv/npeg/blob/master/misc/indent.nim

xigoi commented 3 years ago

Hi Adam, Is this helpful? https://github.com/zevv/npeg/blob/master/misc/indent.nim

Thanks! It's amazing how flexible npeg is. Maybe it would be good to mention this in the documentation.

zevv commented 3 years ago

Quoting Adam Blažek (2021-06-12 17:36:31)

Hi Adam, Is this helpful? https://github.com/zevv/npeg/blob/master/misc/indent.nim

Thanks! It's amazing how flexible npeg is. Maybe it would be good to mention this in the documentation.

Sure, I'll add a note to the documentation mentioning how amazingly flexible npeg is :)