Skip to content

Instantly share code, notes, and snippets.

@hyqhyq3
Created November 13, 2013 05:39
Show Gist options
  • Save hyqhyq3/7444287 to your computer and use it in GitHub Desktop.
Save hyqhyq3/7444287 to your computer and use it in GitHub Desktop.
ini grammar
template<typename Iterator>
struct IniGrammar
: qi::grammar<Iterator, std::map<std::string, std::string>()>
{
IniGrammar()
: IniGrammar::base_type(start)
{
using ascii::char_;
using qi::lexeme;
using spirit::skip;
using ascii::space;
comment %= ';' >> *(char_ - '\n');
key %= lexeme[+(char_("a-zA-Z0-9._-"))];
value %= lexeme[*(char_ - '\n')];
item %= skip(space)[key >> '=' >> value] ;
start %= (item|comment) % '\n';
}
qi::rule<Iterator, void()> comment;
qi::rule<Iterator, std::string()> key;
qi::rule<Iterator, std::string()> value;
qi::rule<Iterator, std::pair<std::string, std::string>()> item;
qi::rule<Iterator, std::map<std::string, std::string>()> start;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment