我想为任何不遵循以下模式之一的左大括号创建匹配模式:
{\n\n{\s*\/\/.*\n\(\s*\/\/.*\)\?\n更普遍的问题是突出显示工作中违反编码规范的行为,这会强制执行空行 {
澄清,我正在寻找这样的代码,如下所示:
if (foo) {
this_is_bad____no_blank_line_above();
} else {this_is_worse();}
while (1) { //This comment is allowed
//This one too
theres_nothing_wrong_with_this();
}
if (foo) {
....//<-- Ideally we could mark this as bad, due to the spaces here
otherwise_perfectly_good();
}
Run Code Online (Sandbox Code Playgroud)
我真正需要的是: {\(\n\n\|\s*\/\/.*\n\(\s*\/\/.*\)\?\n\)\!
制作符号\!表示"与这两个选项中的任何一个都不匹配".我看到了为个别角色做这种方式的方法,但不是更长的字符串.
我有一个相当奇怪的情况,我希望能够定义ABC的子类可以覆盖的某些常量.
struct A {
static const int a = 20;
virtual int func() = 0;
};
struct B : public A {
static const int a = 3;
int func() { return 5; }
};
struct C : public A {
static const int a = 4;
int func() { return 3; }
};
Run Code Online (Sandbox Code Playgroud)
不幸的是,如果我使用A *aPtr = new B,aPtr->a将返回20,而不是3.
我看到的一个解决方法是单行函数(沿着上例中的行func),但是常量的语法在概念上更适合于这种特殊情况.是否有一种语法上合理的方法来解析在运行时使用哪些常量,其中调用代码在创建初始对象后不需要知道任何内容?
通过boost :: spirit :: qi :: symbols文档的开头段落,我假设从语义动作向qi :: symbols添加符号并不太难.不幸的是,它似乎并不像我想象的那么简单.
以下测试代码表明了问题:
#define BOOST_SPIRIT_USE_PHOENIX_V3
#include <boost/spirit/include/qi.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <string>
namespace qi = boost::spirit::qi;
typedef qi::symbols<char, unsigned int> constants_dictionary;
template <typename Iter> struct parser : public qi::grammar<Iter, qi::space_type> {
parser(constants_dictionary &dict) : parser::base_type(start) {
start = qi::lit("@") >> ((+qi::char_) >> qi::uint_)[dict.add(qi::_1, qi::_2)];
}
qi::rule<Iter> start;
};
int main() {
constants_dictionary dict;
parser<std::string::const_iterator> prsr(dict);
std::string test = "@foo 3";
parse(test.begin(), test.end(), prsr, qi::space);
}
Run Code Online (Sandbox Code Playgroud)
从VS2010中提供与qi :: _ 2相关的类型错误:
C:\Users\k\Coding\dashCompiler\spirit_test.cpp(12) : error …Run Code Online (Sandbox Code Playgroud) 我有一个或多或少遵循这种模式的结构:
struct sTruct {
int count;
struct {
int A;
int B;
int C;
} array[]; //count is the size of this array
};
Run Code Online (Sandbox Code Playgroud)
我希望能够使用以下语法初始化它们:
sTruct gInit1 = { 2, { {1,2,3},{4,5,6} }};
Run Code Online (Sandbox Code Playgroud)
实际上,初始化语法(或者更确切地说,它的紧凑性)比特定的结构布局更重要.我无法访问标准容器(嵌入式平台),但如果需要,我可以复制它们的一些行为.
在最终形式中,我想一次初始化大约300个这些sTruct容器的数组,只是为了添加一个更高级别的括号.
我正在申请一个项目的SVN回购,需要整合到我的Mercurial仓库中.为了简单起见,我有一个本地hgsubversion repo和一个本地hg repo.但是,mercurial和hgsubversion repo都使用default默认的分支名称.我的目标是将原始代码和更新放在一个分支上,将我的代码放在default分支上
但是我还没有能够做到这一点.
W:\programming\tcsite-svn-test>hg clone http://*HG_SITE*/hg .
no changes found
updating to branch default
0 files updated, 0 files merged, 0 files removed, 0 files unresolved
W:\programming\tcsite-svn-test>hg branch blizzard
marked working directory as branch blizzard
W:\programming\tcsite-svn-test>hg commit
W:\programming\tcsite-svn-test>hg log
changeset: 0:be13a9580df0
branch: blizzard
tag: tip
user: Leon Blakey <lord.quackstar@gmail.com>
date: Fri Jan 14 23:44:25 2011 -0500
summary: Created Blizzard Branch
W:\programming\tcsite-svn-test>hg pull http://*SVN_SITE*/svn/
pulling from http://*SVN_SITE*/svn/
....
pulled 23 revisions
(run 'hg update' to …Run Code Online (Sandbox Code Playgroud) c++ ×3
boost-spirit ×1
const ×1
hgsubversion ×1
mercurial ×1
polymorphism ×1
regex ×1
static ×1
vim ×1