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

mamcx
  • 15,916
  • 26
  • 101
  • 189

1 Answers1

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.

pad
  • 41,040
  • 7
  • 92
  • 166
  • 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: https://github.com/stephan-tolksdorf/fparsec/wiki/Parsing-indentation-based-syntax-with-FParsec – Stelios Adamantidis Sep 24 '22 at 19:44