/parsim

Parsers

Primary LanguageC++BSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Strings Parsers C++ Library

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;
}

Strings syntax

Supported types

Primitive types

  • integers: 10 , 2e+2 ,
  • floats: 1.9 , 2.009
  • chars: 'a'
  • strings: "Hello "Google"!" , 'Hello "Guthub"!'

Containers

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)

Comments

{ 10: "value" /* My  comment */, 20: "another value"} // End of line
[10, 20, 30] # Python's  comment

Where it is used?

[CERN Gaudi framework][Gaudi] [Gaudi]: http://svnweb.cern.ch/world/wsvn/gaudi/Gaudi/trunk/GaudiKernel/GaudiKernel/GrammarsV2.h