GLSL parser by Laurent Le Brun is a gold nugget for those who would like to use FParsec to parse C-like languages. As I have plans to use this script as a starting point for my TouchDevelop parser, this script was the first I looked at after I fixed F# support in my Visual Studio 2010.
It turned out, however, that the script is somewhat outdated: written in 2010 (according to the date of the blog entry) it requires an earlier version of FParsec library. Trying to compile it against the latest stable version of FParsec (0.9.1) fails due to some deprecated names (mostly abbreviations that were previously used in FParsec, like "Assoc", are now written in full). Besides, the syntax for SyntaxParser generic constructor has been changed to include the UserState type.
I adapted the code by Laurent Le Brun, the working versions of the script with minimal changes (see below) can be downloaded from this blog entry.
Changes compared to the original version of the script:
- Assoc -> Associativity
- µOp -> µOperator where µ in {Infix, Prefix, Postfix, Ternary}
- Parse -> GlslParser
- Ast -> GlslAst
I also put together a small VS2010 project containing the latest version of
FParsec along with a sample
GLSL script that is automatically parsed if run in debug mode.
Files:
glsl_parser.fs (8 Kb)
VisualStudio 2010 solution with FParsec 0.9.1 and sample script (1.36 Mb)