String Barser使用BOOST.Spirit [英] String Parser using BOOST.Spirit
问题描述
i有问题实现解析器comman分隔的字符串解析器
string:
" str1,str2 ,str3"
INTO:
1. str1
2. str2
3. str3
*也是字符串是任何字符串(没有特定的字符串/关键字)
我在下面有这个代码,它到目前为止解析的是具体的
string:" x1"," x2"," y1"," y2"
但我需要的是任何类型的字符串解析器(逗号分隔)
bool
parse_string(char const * str,vector< string>& v)
(
返回解析(str,
(
(str_p(" x1" [push_back_a(v)])|
str_p(" x2")[push_back_a(v)])
i have problem implemting a string parser that parser comman delimited
string:
"str1,str2,str3"
INTO:
1. str1
2. str2
3. str3
*also strings are of any string (no specific string/keyword)
I have this code below, what it does so far is to parse specific
string: "x1", "x2", "y1", "y2"
but what i need is a parser for any kind of string (comma delimited)
bool
parse_string(char const* str, vector<string>&v)
(
return parse(str,
(
(str_p("x1"[push_back_a(v)]) |
str_p("x2")[push_back_a(v)] )
*('',''>>(str_p(" y1")[push_back_a(v) ] |
*('','' >> (str_p("y1")[push_back_a(v)] |
str_p(" y2")[push_back_a(v)]) )
),
space_p).full;
)
示例使用:INPUT: " x1,y2,y1,y2"
输出:
x1
y2
y1
y2
我需要的是:
例如:INPUT:this,is,a,test
输出:
这个
是
a
测试
ps。我需要使用BOOST实现这个.Spirit
-
Thx
str_p("y2")[push_back_a(v)] ) )
),
space_p).full;
)
example use: INPUT: "x1,y2,y1,y2"
OUTPUT:
x1
y2
y1
y2
what i need is:
example: INPUT: "this,is,a,test"
OUTPUT:
this
is
a
test
ps. i need to implement this using BOOST.Spirit
--
Thx
推荐答案
krbyxtrm写道:
krbyxtrm wrote:
我有问题实现解析器comman分隔的字符串解析器
字符串:
" str1,str2 ,str3"
INTO:
1. str1
2. str3
* str3
*字符串都是任意字符串(没有特定的字符串/关键字)
i have problem implemting a string parser that parser comman delimited
string:
"str1,str2,str3"
INTO:
1. str1
2. str2
3. str3
*also strings are of any string (no specific string/keyword)
最好加入boost.spirit邮件列表:
http://lists.sourceforge.net/lists/l...spirit-general
另外如果没有一个例子可以说明你的精神装置是什么,我会感到惊讶。像规则<>之类的东西comma_delimited =
(*(anychar_p - '',''))[push_back_a(a)]%'','';
Jeff Flinn
Your better off joining the boost.spirit mailing list at:
http://lists.sourceforge.net/lists/l...spirit-general
Also I''d be surprised if there weren''t an example of doing exactly that in
your spirit installation. Something like rule<> comma_delimited =
(*(anychar_p-'',''))[push_back_a(a)] % '','';
Jeff Flinn
如果没有一个完全正确的例子,我也会感到惊讶你的精神装置。类似规则<>
comma_delimited =(*(anychar_p - '',''))[push_back_a(a)]%'','';
Also I''d be surprised if there weren''t an example of doing exactly
that in your spirit installation. Something like rule<>
comma_delimited = (*(anychar_p-'',''))[push_back_a(a)] % '','';
OT,但是:%运算符用于什么?
OT, but: What is that % operator used for?
Gernot Frisch写道:
Gernot Frisch wrote:
如果在你的精神装置中没有一个完全正确的例子,我也会感到惊讶。类似规则<>
comma_delimited =(*(anychar_p - '',''))[push_back_a(a)]%'','';
Also I''d be surprised if there weren''t an example of doing exactly
that in your spirit installation. Something like rule<>
comma_delimited = (*(anychar_p-'',''))[push_back_a(a)] % '','';
OT ,但是:%运算符用于什么?
OT, but: What is that % operator used for?
来自 http://www.boost.org/libs/spirit/doc/operators.html ,
a%b;匹配由b / b
出现的一个或多个重复的列表。这与>>相同*(b>> a)。请注意,一定不能
也匹配b。
Jeff
From the docs at http://www.boost.org/libs/spirit/doc/operators.html,
a % b ; Match a list of one or more repetitions of a separated by
occurrences of b. This is the same as a >> *(b >> a). Note that a must not
also match b.
Jeff
这篇关于String Barser使用BOOST.Spirit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!