I'm trying to write a small DSL parser using fslex and fsyacc. The input is composed of interleaving chunks of two different languages which require different lexing rules. How do I write my fslex file to support that?
(I guess a similar case would be how to define an fslex file for the c language but with support for inline assembly, which requires different lexing rules?)
What I have currently is something like this:
rule tokenize = parse
| "core" { core lexbuf }
...
and core = parse
| ...
The thing is, once a token gets returned by the core parser, the next part of the input gets passed to tokenize instead. However I want to stay (as it were) in the core state. How do I do that?
Thanks!
I actually managed to find a solution on my own. I defined my own tokenizer function which decides based on the
BufferLocalStorestate which tokenizer to call.And I modified my
fslexinput file slightly:Amazing how simply asking the question can lead you to the solution, and I hope this helps someone besides me :)