[Xpressive] Nested patterns and sub-matches' semantic values
Hi,
For one part of a large project, I need to parse math and turn the
"mathematical objects" into a C++ abstraction of them. Is it possible that
a nested pattern hold semantic values within itself and can be queried for
that value somehow? As if a match were a function of its sub-patterns'
matches, if that makes sense...
Code might speak better than my english:
class math_number {...};
class math_addition {...};
class math_arglist {...};
class math_funcdef {...};
sregex integer = (s1= +_d)
[ return math_number( as<int>(s1) ) ];
sregex addition = (s1= integer) >> '+' >> (s2= integer)
[ return math_addition( as
On 13-05-30 08:35 AM, Simon wrote:
Hi, For one part of a large project, I need to parse math and turn the "mathematical objects" into a C++ abstraction of them. Is it possible that a nested pattern hold semantic values within itself and can be queried for that value somehow? As if a match were a function of its sub-patterns' matches, if that makes sense...
Code might speak better than my english:
class math_number {...}; class math_addition {...}; class math_arglist {...}; class math_funcdef {...};
sregex integer = (s1= +_d) [ return math_number( as<int>(s1) ) ];
sregex addition = (s1= integer) >> '+' >> (s2= integer) [ return math_addition( as
(s1), as (s2) ) ]; sregex arglist = (s1= identifier) >> *( ',' >> (s2= arglist)) [ std::vector
ids( as (s2).begin(), as (s2).end() ); ids.push_back(as (s1)); return ids; ] sregex funcdef = ((s1= identifier) >> '(' >> (s2= arglist) >> ")=" >> (s3= addition)) [ return math_funcdef( as
(s1), as (s2), as (s3) ) ]; I just want to avoid the funcdef above to be responsible for the construction of the various math_* objects the funcdef will hold (some of which will be complex to construct). And if I really must store the objects in an external stack, how should the parent-objects find their child-objects?
It really sounds to me that this problem would be better addressed by Boost.Spirit and its attributed parsers. -- Eric Niebler Boost.org
Yes, I've been reading on Spirit for a little while now.
I think I'll be reading a while more before I can do what I want though...
Let me know if you have any ideas using Xpressive.
Thanks,
Simon
On Thu, May 30, 2013 at 3:47 PM, Eric Niebler
On 13-05-30 08:35 AM, Simon wrote:
Hi, For one part of a large project, I need to parse math and turn the "mathematical objects" into a C++ abstraction of them. Is it possible that a nested pattern hold semantic values within itself and can be queried for that value somehow? As if a match were a function of its sub-patterns' matches, if that makes sense...
Code might speak better than my english:
class math_number {...}; class math_addition {...}; class math_arglist {...}; class math_funcdef {...};
sregex integer = (s1= +_d) [ return math_number( as<int>(s1) ) ];
sregex addition = (s1= integer) >> '+' >> (s2= integer) [ return math_addition( as
(s1), as (s2) ) ]; sregex arglist = (s1= identifier) >> *( ',' >> (s2= arglist)) [ std::vector
ids( as (s2).begin(), as (s2).end() ); ids.push_back(as (s1)); return ids; ] sregex funcdef = ((s1= identifier) >> '(' >> (s2= arglist) >> ")=" >> (s3= addition)) [ return math_funcdef( as
(s1), as (s2), as (s3) ) ]; I just want to avoid the funcdef above to be responsible for the construction of the various math_* objects the funcdef will hold (some of which will be complex to construct). And if I really must store the objects in an external stack, how should the parent-objects find their child-objects?
It really sounds to me that this problem would be better addressed by Boost.Spirit and its attributed parsers.
-- Eric Niebler Boost.org _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Eric Niebler
-
Simon