Domanda

What is the advantage of using a library like FParsec for parsing text over using plain regular expressions from a .NET language?

È stato utile?

Soluzione

FParsec can recognise (at least) context-free grammars whereas regular expressions can only recognise regular languages, at least without using somewhat hacky extensions.

One example of something you can't do with a regular language is bracket matching, i.e. tracking the number of opening and closing brackets and make sure that they match up.

Of course you can emulate this with regular expressions by using them repeatedly, but embedding the behaviour into a single parser is significantly cleaner.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top