diff --git a/parserMinimalExample/parserMinimalExample2.cpp b/parserMinimalExample/parserMinimalExample2.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7f6de23576e0ae4e6c1936db5242e63b93219a42 --- /dev/null +++ b/parserMinimalExample/parserMinimalExample2.cpp @@ -0,0 +1,55 @@ +#include <boost/spirit/include/qi.hpp> +#include <iostream> +#include <string> + +namespace qi = boost::spirit::qi; +namespace px = boost::phoenix; +namespace ascii = boost::spirit::ascii; + +typedef qi::rule<std::string::const_iterator,std::string(),qi::ascii::space_type> RuleType; + +template <typename Iterator> +struct dynamicParser + : qi::grammar<Iterator,std::string(), boost::spirit::ascii::space_type> +{ + + dynamicParser (std::vector<RuleType> rules) + : dynamicParser::base_type(startRule) + { + startRule = rules[0]; + } + + RuleType startRule; +}; + +int +main (int argc, char** argv) { + + std::vector<RuleType> myRuleVector; + + myRuleVector.push_back (RuleType(qi::eps));//This rule is going to get replaced + myRuleVector.push_back (RuleType(qi::string("Hello"))); + myRuleVector.push_back (RuleType(qi::string("Hi"))); + myRuleVector.push_back (RuleType(qi::string("Whats up"))); + + //Now magically compose a rule *with arbitrary vectorsize* + //I have no clue how to do this + //But it should result in: + + myRuleVector[0] = myRuleVector[1] | myRuleVector[2] | myRuleVector[3]; + myRuleVector.at(0) = myRuleVector.at(1); + for (int i=2; i < 3; i++) + myRuleVector.at(0) = myRuleVector.at(0).copy() | myRuleVector.at(i); + + dynamicParser<std::string::const_iterator> myDynamicParser(myRuleVector); + + std::string const s ("Hi"); + std::string attr; + + if (qi::phrase_parse (s.begin(), s.end(),myDynamicParser,ascii::space,attr)) + std::cout << "Parse success " << attr << std::endl; + else + std::cout << "Parse failed" << std::endl; + + return 0; +} diff --git a/pocketsphinxAdapter/nbproject/private/configurations.xml b/pocketsphinxAdapter/nbproject/private/configurations.xml index c07ff778d292725d628f981596a1dffdc9c89eaf..37f2755f45d5b34411bae358a1d1667dd97707e1 100644 --- a/pocketsphinxAdapter/nbproject/private/configurations.xml +++ b/pocketsphinxAdapter/nbproject/private/configurations.xml @@ -25,45 +25,7 @@ <in>moc_measureDb.cxx</in> </df> </df> - <df name="cmake"> - <df name="Modules"> - </df> - </df> - <df name="CMakeFiles"> - <df name="2.8.10.2"> - <df name="CompilerIdC"> - <in>CMakeCCompilerId.c</in> - </df> - <df name="CompilerIdCXX"> - <in>CMakeCXXCompilerId.cpp</in> - </df> - </df> - <df name="CMakeTmp"> - </df> - <df name="CompilerIdC"> - <in>CMakeCCompilerId.c</in> - </df> - <df name="CompilerIdCXX"> - <in>CMakeCXXCompilerId.cpp</in> - </df> - <df name="Progress"> - </df> - </df> <df name="src"> - <df name="CMakeFiles"> - <df name="jsgfParser.dir"> - </df> - <df name="jsgfParserTest.dir"> - </df> - <df name="measureAlsaDb.dir"> - </df> - <df name="measureDb.dir"> - </df> - <df name="parserToyExample.dir"> - </df> - <df name="pocketsphinxAdapter.dir"> - </df> - </df> <in>AlsaMicGrabber.cpp</in> <in>AlsaMicGrabber.h</in> <in>EqualizerColorWidget.cpp</in> @@ -99,7 +61,6 @@ <in>moc_SimpleDoubleThresholdSegmenter.cxx</in> <in>moc_SimpleTextAddField.cxx</in> <in>moc_measureDb.cxx</in> - <in>moc_pocketsphinxAdapter.cxx</in> </df> <in>pocketsphinxAdapterConfig.h</in> </df> diff --git a/pocketsphinxAdapter/src/JsgfParser.h b/pocketsphinxAdapter/src/JsgfParser.h index 804b377c9e8b1b14b098bf81a4aaa7c3cbc54f0f..870ef9b130d53e84a52adade40722e654e2645ac 100644 --- a/pocketsphinxAdapter/src/JsgfParser.h +++ b/pocketsphinxAdapter/src/JsgfParser.h @@ -266,11 +266,9 @@ namespace jsgfParserTypes { public: TermWrapperRuleGenerator (std::vector<ruleTPtr> &rules, nameToRuleT & namesToRules,std::string nonterminal) : myRules(rules), myNamesToRules(namesToRules), myNonterminal(nonterminal){} void operator ()(TermT & t) const - { - std::vector<ruleTPtr> temp = myRules; + { TermTRuleGenerator myGenerator (myRules,myNamesToRules, myNonterminal); - myGenerator(t); - + myGenerator(t); } void operator()(TermLeafT & tl) const { @@ -287,7 +285,7 @@ namespace jsgfParserTypes { if (pos != myNamesToRules.end()) { myRules.push_back (new ruleT ((*myRules.at(pos->second))[qi::_val = px::val(myNonterminal) + px::val('+') + qi::_1] >> qi::eps[fun])); - std::cout << "Added nonterminal '" << myNonterminal <<"' link to rule " << pos->second << std::endl; + std::cout << "Added nonterminal '" << trim(tl.symbols.at(i).name) <<"' link to rule " << pos->second << std::endl; } else { @@ -335,6 +333,10 @@ namespace jsgfParserTypes { { boost::apply_visitor(TermWrapperRuleGenerator(myRules,myNamesToRules,myNonterminal),node); } + if (t.children.size() > 1) + { + + } } } diff --git a/pocketsphinxAdapter/src/dynamicParser.h b/pocketsphinxAdapter/src/dynamicParser.h index 3f8652b63e602175ca7d6b091d844622036d92a3..43e2773fc9183444d0eb7e1820a88fda0b42a932 100644 --- a/pocketsphinxAdapter/src/dynamicParser.h +++ b/pocketsphinxAdapter/src/dynamicParser.h @@ -17,6 +17,10 @@ #include <iostream> #include <string> +namespace qi = boost::spirit::qi; +namespace px = boost::phoenix; +namespace ascii = boost::spirit::ascii; + template <typename Iterator> struct dynamicParser : qi::grammar<Iterator,std::string(), boost::spirit::ascii::space_type> { dynamicParser (std::vector<qi::rule<Iterator,std::string(), qi::ascii::space_type>* > rules) : dynamicParser::base_type(startRule) {