Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

F# is an indentation-sensitive language itself and F# compiler uses fslex/fsyacc for parsing. If you take a look at F#'s parser, indentation sensitiveness adds extra complexities to this process.

If you don't have much experience with F#, hand-rolled F# parser is probably not a good idea. I would recommend to use FParsec. It has the flexibility of hand-rolled parsers and is much simpler to use than fslex/fsyacc.

You can find two implementations of an indentation-based grammar in FParsec from this article.

To build a homebrew parser in C#.NET, you may want to look into Rxx extension for Microsoft Reactive Extension (Rx).

Also, checkout this list for creating. parsers in C#.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top