Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# or F# for Parsing Slim-like indentation-conscious languages? [closed]

In order to build a parser for Slim-like template languages (for ASP) in .NET, which language is more suitable C# or F#? (to me, F# seems more scientific and appropriate for such tasks..)

Other than language selection, which of the two techniques are suitable for parsing languages, in which there is 2-space incrementing indentation to describe nesting/block (such as; Slim, Haml or SCSS): Recursive Descent Parsing or Recursive Ascent Parsing?

OAN, is there any OOTB support for RDP or RAP in .NET? Or a generic, elegant third-party parsing library like Java's parboiled?

like image 372
vulcan raven Avatar asked Dec 05 '25 20:12

vulcan raven


1 Answers

F# is an excellent tool for writing parsers. You have a variety of choices:

  • Active patterns let you define fairly simple parsers that are very readable. I used this approach in my Markdown parser I wrote a chapter about this for an upcoming F# book which is freely available as PDF.

  • Parser combinators are another options. The idea is that you can build parser from basic building blocks (such as parsing a list separated by a given character etc.). There is an F# implementation called FParsec

  • FsLex and FsYacc give you the standard tools for writing parsers. There is a new more efficient implementation and also a version in the F# PowerPack which is used by the F# compiler itself.

like image 79
Tomas Petricek Avatar answered Dec 08 '25 22:12

Tomas Petricek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!