I am trying to learn how to use Parsec to write a Delphi parser, but I am getting stuck at defining the LanguageDef.
In Delphi, there are two types of comment blocks, (* comments *) and { comments }.
But the types of commentStart & commentEnd of LanguageDef are String, not [String], so I could only put in one or the other.
So, I tried to make my own whiteSpace parser, but I’m not sure I could actually pass it into makeTokenParser.
Any help would be appreciated.
Thanks
John and Chris have helped me to understand and get around the problem, but the solution involves replacing a huge number of parsers that makeTokenParser provides, so it’s not exactly desirable.
I will post again if I could find a better solution.
My reading of the
Text.ParserCombinators.Parsec.Languagefile is that this cannot be done directly using aLanguageDef.I believe you are on the right track to write your own
whiteSpaceparser. In order to use it successfully, you need to overwrite thewhiteSpaceparser that is generated bymakeTokenParser. TheTokenParsercreated bymakeTokenParseris a record with each field containing a parser. We can create a new copy of the record with one of those fields replaced as follows: