Is possible to parse "off-side" (indentation-based) languages with fparsec?
Asked Answered
I

1

7

I wish to use FParsec for a python-like language, indentation-based.

I understand that this must be done in the lexing phase, but FParsec don't have a lexing phase. Is possible to use FParsec, or, how can feed it after lexing?

P.D: I'm new at F#, but experienced in other languages

Indulge answered 27/11, 2014 at 2:47 Comment(0)
N
10

Yes, it's possible.

Here is a relevant article by FParsec author. If you want to go deeper on the subject, this paper might worth a read. The paper points out that there are multiple packages for indentation-aware parsing that based on Parsec, the parser combinator that inspires FParsec.

FParsec doesn't have a separate lexing phase but instead it fuses lexing and parsing to a single phase. IMO indentation-aware parsing is better to be done with parser combinators (FParsec) than parser generators (fslex/fsyacc). The reason is that you need to manually track current indentation and report good error messages based on contexts.

Namedropping answered 27/11, 2014 at 8:33 Comment(1)
Unfortunately SO is not allowing me to edit the question but if anyone finds out that the "relevant article" is dead and is interested to read it, it's in github: github.com/stephan-tolksdorf/fparsec/wiki/…Regolith

© 2022 - 2024 — McMap. All rights reserved.