A few small improvements to helper functions

This commit is contained in:
Jonathan Turner
2009-05-27 20:01:34 +00:00
parent f6f6a8305e
commit 10491e4ed8
3 changed files with 16 additions and 15 deletions

View File

@@ -94,3 +94,12 @@ Rule Str(const std::string &text, bool keep) {
Rule Id(int id, bool keep) {
return Rule(boost::bind(Type_Rule, _1, _2, _3, id, keep));
}
Rule Str(const std::string &text) {
return Rule(boost::bind(String_Rule, _1, _2, _3, text, false));
}
Rule Id(int id) {
return Rule(boost::bind(Type_Rule, _1, _2, _3, id, false));
}

View File

@@ -69,5 +69,7 @@ private:
Rule Str(const std::string &text, bool keep);
Rule Id(int id, bool keep);
Rule Str(const std::string &text);
Rule Id(int id);
#endif /* LANGKIT_PARSER_HPP_ */

View File

@@ -49,24 +49,14 @@ std::string load_file(const char *filename) {
void parse(std::vector<TokenPtr> &tokens) {
/*
Rule rule;
rule.rule = boost::bind(String_Rule, _1, _2, _3, "def", true);
Token_Iterator iter = tokens.begin(), end = tokens.end();
TokenPtr parent(new Token("Root", 0, "test"));
std::pair<Token_Iterator, bool> results = rule(iter, end, parent);
if (results.second) {
std::cout << "Parse successful: " << std::endl;
debug_print(parent, "");
}
*/
Rule lhs;
Rule rhs;
Rule rule = lhs & rhs; //(boost::bind(And_Rule, _1, _2, _3, lhs, rhs));
Rule rule = lhs & rhs;
lhs = Str("def", true);
rhs = Str("int", true);
rhs = Id(TokenType::Identifier, true);
*/
Rule rule = Str("def") & Id(TokenType::Identifier, true);
Token_Iterator iter = tokens.begin(), end = tokens.end();
TokenPtr parent(new Token("Root", 0, "test"));