IDFstepper
IDF to STEP converter
|
00001 #ifndef CONFIGGRAMMAR_HPP_INCLUDED 00002 #define CONFIGGRAMMAR_HPP_INCLUDED 00003 00004 #include "ConfigType.hpp" 00005 #include <boost/optional.hpp> 00006 #include <boost/config/warning_disable.hpp> 00007 #include <boost/spirit/include/qi.hpp> 00008 #include <boost/spirit/include/phoenix_core.hpp> 00009 #include <boost/spirit/include/phoenix_operator.hpp> 00010 #include <boost/spirit/include/phoenix_fusion.hpp> 00011 #include <boost/spirit/include/phoenix_stl.hpp> 00012 #include <boost/spirit/include/phoenix_object.hpp> 00013 #include <boost/fusion/include/std_pair.hpp> 00014 #include <boost/variant.hpp> 00015 #include <boost/foreach.hpp> 00016 00017 #include <iostream> 00018 #include <fstream> 00019 #include <string> 00020 #include <vector> 00021 #include <map> 00022 00030 namespace config { 00031 00032 namespace fusion = boost::fusion; 00033 namespace phoenix = boost::phoenix; 00034 namespace qi = boost::spirit::qi; 00035 namespace ascii = boost::spirit::ascii; 00036 00042 template <typename Iterator> 00043 struct ConfigGrammar 00044 : qi::grammar<Iterator, Config(), qi::rule<Iterator> > 00045 { 00046 00047 typedef qi::rule<Iterator> SkipType; 00048 00049 ConfigGrammar() : ConfigGrammar::base_type(conf) { 00050 using qi::lit; 00051 using qi::eol; 00052 using qi::lexeme; 00053 using qi::double_; 00054 using qi::int_; 00055 using qi::debug; 00056 using qi::eps; 00057 using ascii::blank; 00058 using ascii::char_; 00059 using ascii::string; 00060 using ascii::no_case; 00061 using namespace qi::labels; 00062 00063 skipper = blank; // Tabs and spaces 00064 00065 eeol = +(eol | ((lit('#') | ';') >> *(char_ - eol) >> eol)); 00066 00067 boolean = no_case[ 00068 (lit("yes") | "true" | "on") [_val = true] 00069 | (lit("no") | "false" | "off") [_val = false] 00070 ]; 00071 00072 quotedStr %= '"' >> *(char_ - '"') >> '"'; 00073 00074 str %= quotedStr | +(char_ - blank - eeol - '=' - ';' - '#'); 00075 00076 value %= boolean | double_ | str; 00077 00078 option %= str >> '=' >> value; 00079 00080 conf %= *eeol >> option % +eeol; 00081 } 00082 00085 SkipType skipper; 00086 qi::rule<Iterator> eeol; // Extended EOL for empty lines and comments 00087 00088 qi::rule<Iterator, bool()> boolean; 00089 qi::rule<Iterator, std::string()> quotedStr; 00090 qi::rule<Iterator, std::string()> str; 00091 qi::rule<Iterator, Value()> value; 00092 qi::rule<Iterator, std::pair<std::string, Value>(), SkipType> option; 00093 qi::rule<Iterator, Config(), SkipType> conf; 00094 00095 }; 00096 00097 } 00098 00099 #endif 00100