From 10491e4ed812093c3b9f1cf0de2d64f60e3eb38a Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Wed, 27 May 2009 20:01:34 +0000 Subject: [PATCH] A few small improvements to helper functions --- langkit/langkit_parser.cpp | 9 +++++++++ langkit/langkit_parser.hpp | 2 ++ langkit/main.cpp | 20 +++++--------------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/langkit/langkit_parser.cpp b/langkit/langkit_parser.cpp index 88cc871..424dcd7 100644 --- a/langkit/langkit_parser.cpp +++ b/langkit/langkit_parser.cpp @@ -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)); +} + diff --git a/langkit/langkit_parser.hpp b/langkit/langkit_parser.hpp index f6f5158..7c898c3 100644 --- a/langkit/langkit_parser.hpp +++ b/langkit/langkit_parser.hpp @@ -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_ */ diff --git a/langkit/main.cpp b/langkit/main.cpp index 5843cbf..68ca05c 100644 --- a/langkit/main.cpp +++ b/langkit/main.cpp @@ -49,24 +49,14 @@ std::string load_file(const char *filename) { void parse(std::vector &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 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"));