The goal of this library is to have a extendable headers only C++ library
for converting strings that represent the python types (primitive types, lists,
dictionaries, sets) to the corresponding C++ types.
The library depends only on Boost headers.
#inlcude "parsim.h"
#include <iostream>
#include <map>
#include <vector>
#include <string>
using namespace std;
// You can use any type composed by supported containers and primitive types
map<int, vector<string> > result;
try {
parse_("{1: ['Hello', 'Google'], 2: ['Hello', 'Github']", result);
} catch(parsim::expectation_failure e) {
cout << "Expected: " << e.what_.tag << endl;
cout << "Found: " << string(e.first, e.second) << endl;
}
- integers: 10 , 2e+2 ,
- floats: 1.9 , 2.009
- chars: 'a'
- strings: "Hello "Google"!" , 'Hello "Guthub"!'
The containers can hold values of primitive type or hold other containers.
- list: [value, value, ...]
- dictionary: {key: value, key: value, ...}
- pairs: (first, second), (first: second)
- tuples: (valueOfType1, valueOfType2, valueOfType3)
{ 10: "value" /* My comment */, 20: "another value"} // End of line
[10, 20, 30] # Python's comment
[CERN Gaudi framework][Gaudi] [Gaudi]: http://svnweb.cern.ch/world/wsvn/gaudi/Gaudi/trunk/GaudiKernel/GaudiKernel/GrammarsV2.h