vshaxe / hxparser

OCaml/menhir implementation of a new Haxe parser.
MIT License
16 stars 2 forks source link

Parse string interpolation expressions #10

Open Gama11 opened 7 years ago

Gama11 commented 7 years ago

Right now, it's all just one token:

Simn commented 7 years ago

Any suggestions for a representation?

nadako commented 7 years ago

what come to mind mind is something like Array<StringPart> where

enum StringPart {
 PString(string:Token);
 PIdent(dollar:Token, ident:Token);
 PExpr(dollar:Token, bropen:Token, expr:Expr, brclose:Token);
}
Simn commented 7 years ago

This is giving me a bit of a headache. I checked how roslyn does it: They tokenize a single string token (like we do now), then create a fresh scanner/parser to break it up into multiple tokens, which themselves contain parsed data in the case of expressions, or something like that.

For starters, I'm having architectural issues because emitters can't really create new parsers as that would require them to refer to themselves recursively. This could probably be solved in some way, but I'm not sure how to properly do it.

Then there's the problem of the token list. By the time the original string token is emitted, it is already part of the token list. We would have to replace it with the result of the recursive parsing operation.

Overall, this seems very complicated. It might be a better idea to leave it unchanged for now and provide an entry point "interpolated_string". The result can then be combined through the incremental parsing API that we hopefully manage to get right at some point.