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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top