【发布时间】:2017-10-26 17:31:41
【问题描述】:
这是我的小样本..我有一种语言,在解析时我有类似的东西
foo()
nextfoo() <-- here an error appears because of the keyword "next"
所以语法
typedef boost::proto::result_of::deep_copy<BOOST_TYPEOF(ascii::no_caseqi::lit(std::wstring())])>::type nocaselit_return_type;
nocaselit_return_type nocaselit(const std::wstring& keyword)
{
return boost::proto::deep_copy(ascii::no_case[qi::lit(keyword)]);
}
keywords = nocaselit(L"next")
| nocaselit(L"else")
| nocaselit(L"if")
| nocaselit(L"then")
| nocaselit(L"for")
| nocaselit(L"to")
| nocaselit(L"dim")
| nocaselit(L"true")
| nocaselit(L"false")
| nocaselit(L"as")
| nocaselit(L"class")
| nocaselit(L"end")
| nocaselit(L"function")
| nocaselit(L"new")
| nocaselit(L"sub");
name_valid = !keywords>> lexeme[+(boost::spirit::standard_wide::alpha | '_') >> *(boost::spirit::standard_wide::alnum | '_')];
我从 docu 和 goolge 中了解到,我必须编写类似这样的内容才能使解析器正确使用关键字
name_valid = distinct(Keywords)[ lexeme[+(boost::spirit::standard_wide::alpha | '_') >> *(boost::spirit::standard_wide::alnum | '_')] ];
但这不起作用..有人能解释一下为什么吗?
特殊问题 .. 只要我使用上面的语法,我就会收到模板编译器错误,工作示例必须按以下方式编写(关键字列表是内联的,而不是规则)。我认为这与规则的类型规范有关。但正确的是什么?
name_valid = distinct(nocaselit(L"next")| nocaselit(L"else") | ... )
[ lexeme[+(boost::spirit::standard_wide::alpha | '_') >> *(boost
谢谢
【问题讨论】:
-
你是如何定义
nocaselit的?这不是我以前见过的。 -
将 nocaselit 放入文本中 ..
标签: boost boost-spirit