1 |
|
---|
2 | #include "StringFormat.h"
|
---|
3 |
|
---|
4 | #include "boost/xpressive/xpressive.hpp"
|
---|
5 |
|
---|
6 | namespace ariba {
|
---|
7 | namespace utility {
|
---|
8 | namespace string_format {
|
---|
9 |
|
---|
10 | using namespace boost::xpressive;
|
---|
11 |
|
---|
12 | // regex: string
|
---|
13 | const sregex rstring = '"' >> keep(*~(boost::xpressive::set = '"'))
|
---|
14 | >> '"';
|
---|
15 |
|
---|
16 | // regex: base64 encoding
|
---|
17 | const sregex rbase64 = '!' >> +(range('a', 'z') | range('A', 'Z')
|
---|
18 | | range('0', '9') | '/' | '+') >> *(boost::xpressive::set = '=');
|
---|
19 |
|
---|
20 | // regex: raw alphabet
|
---|
21 | const sregex rchars = +(range('a', 'z') | range('A', 'Z'));
|
---|
22 |
|
---|
23 | // regex: integer
|
---|
24 | const sregex rint = '0' | (range('1', '9') >> !(range('0', '9')));
|
---|
25 |
|
---|
26 | // regex: binary label
|
---|
27 | const sregex rlabel = rchars | rstring | rbase64;
|
---|
28 |
|
---|
29 | // regex: dot separated identifier
|
---|
30 | const sregex rid = rlabel >> *('.' >> rlabel) >> *('.' >> rint);
|
---|
31 |
|
---|
32 | // regex: "leaf" data
|
---|
33 | const sregex rdata = !(boost::xpressive::set = '!') >> '{'
|
---|
34 | >> *(keep(+~(boost::xpressive::set = '{', '}')) | by_ref(rdata))
|
---|
35 | >> '}';
|
---|
36 |
|
---|
37 | // regex: fields
|
---|
38 | const sregex rfield_label = rlabel >> '=';
|
---|
39 | const sregex rfield = !rfield_label >> (rid | rdata);
|
---|
40 | const sregex rfields = '(' >> rfield >> *(',' >> rfield) >> ')';
|
---|
41 |
|
---|
42 | // regex objects
|
---|
43 | const sregex robject_data = (rdata | rfields);
|
---|
44 | const sregex robject_id = rid;
|
---|
45 | const sregex robject = robject_id >> robject_data;
|
---|
46 | const sregex robjects = robject >> *(',' >> robject);
|
---|
47 |
|
---|
48 | }}}
|
---|