Skip to content
Snippets Groups Projects
Commit 5d11466c authored by Matthias Schoepfer's avatar Matthias Schoepfer
Browse files

still fixing...

parent 25e59e38
No related branches found
No related tags found
No related merge requests found
#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;
}
......@@ -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>
......
......@@ -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)
{
}
}
}
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment