how to parse: varia = [ dddd dddd ffff ] ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

how to parse: varia = [ dddd dddd ffff ] ?

Jens Kallup
Hello,
how can I parse [ ssss sss ]?
the code here don't work.
the main code work.

TIA
Jens

 1.
    // this will not work:
 2.
 3.
               symbol_string =
 4.
    (
 5.
                            lit("[")
 6.
    >  *(char_ - char_("]"))
 7.
    >>  *(space)
 8.
    >>  *(char_ - char_("]"))
 9.
    >   lit("]")
10.
    )
11.
    ;
12.
13.
               symbol_def_expr %=
14.
    (
15.
    (variable - (dont_handle_keywords))
16.
    >  (
17.
    ( (lit('=') - (dont_handle_keywords))
18.
    >  (
19.
    (symbol_string)
20.
    |
21.
    (symbol_expr)
22.
    )
23.
    )
24.
    )
25.
    )
26.
    ;
27.
28.
29.
    // this work:
30.
31.
    #include <boost/config/warning_disable.hpp>
32.
    #include <boost/spirit/include/qi.hpp>
33.
34.
    #include <iostream>
35.
    #include <string>
36.
37.
    #include <cstring>
38.
    #include <cstdlib>
39.
40.
    using namespace std;
41.
    using namespace boost::spirit;
42.
    using namespace boost::spirit::qi;
43.
44.
    namespace client {
45.
    template <typename Iterator, typename Skipper>
46.
    struct my_test : public qi::grammar<Iterator, Skipper>
47.
    {
48.
    my_test() : my_test::base_type(vs, "test")
49.
    {
50.
       vs =
51.
    (
52.
                    lit("[")
53.
    >  *(char_ - char_("]"))
54.
    >>  *(space)
55.
    >>  *(char_ - char_("]"))
56.
    >     lit("]")
57.
    )
58.
    ;
59.
    }
60.
             rule<Iterator,Skipper> vs;
61.
    };
62.
    }
63.
64.
    int main()
65.
    {
66.
    typedef std::string::iterator iterator_t;
67.
68.
    try {
69.
       std::string source = "[ ssssss ssss ] ";
70.
    typedef client::my_test <iterator_t, decltype(qi::space)> grammar;
71.
72.
       grammar pg;
73.
74.
       iterator_t iter = source.begin();
75.
       iterator_t end = source.end();
76.
77.
    bool ok = phrase_parse(iter,end, pg, space);
78.
    if (ok) {
79.
               std::cout
80.
    << "successful"
81.
    << std::endl;
82.
    return 0;
83.
    }
84.
       std::cout << "error" << std::endl;
85.
    }
86.
    catch(expectation_failure<iterator_t>& e)
87.
    {
88.
       std::cout << "expected: " << e.what_ << std::endl;
89.
    }
90.
91.
    return 0;
92.
    }


------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: how to parse: varia = [ dddd dddd ffff ] ?

PB-19


On 7 December 2016 at 22:42, Jens Kallup <[hidden email]> wrote:
Hello,
how can I parse [ ssss sss ]?
the code here don't work.


Have you tried turning it off and on again?

------------------------------------------------------------------------------
Developer Access Program for Intel Xeon Phi Processors
Access to Intel Xeon Phi processor-based developer platforms.
With one year of Intel Parallel Studio XE.
Training and support from Colfax.
Order your platform today.http://sdm.link/xeonphi
_______________________________________________
Spirit-general mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/spirit-general
Loading...