boost::spirit::qi keywords and identifiers

别等时光非礼了梦想. 提交于 2019-11-28 01:18:33

Actually this question deserves some votes. It should be much more oft realized, and probably be addressed in the Spirit Tutorials, as it's often overlooked (obviously the compiler samples are ok)


Perhaps I'm reading the qi syntax wrong, but it seems to me that this would not accept any literal that matches or starts with a keyword.

That's correct. In case you spotted in one of my own answers (quite a good chance) I tend to do this as a quick-and-dirty way to fixup grammars that didn't have proper keyword guards there in the first place.

But yeah, requiring distinct keywords/identifiers requires some more work. I might find a link to an answer where it's done correctly (it's not hard, it's just tedious).

Meanwhile, have a look at the very relevant

If you're building a really robust general-purpose language grammar, this is about the point where you should consider using a Spirit Lexer. Then again, in my humble opinion, Spirit aims at rapid development and small, one-off grammars that are succinctly embedded using Spirit's expression template eDSL. In a lot of aspects, that is much the antipode of when this matters, I reckon.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!