From 52433e56e562976887325ce48a6271abb82a89aa Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 28 Oct 2009 23:41:51 -0400 Subject: Fixed "show" keywords, and added // syntax --- src/predicate.h | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-) (limited to 'src/predicate.h') diff --git a/src/predicate.h b/src/predicate.h index dc39f2f2..555fac05 100644 --- a/src/predicate.h +++ b/src/predicate.h @@ -106,7 +106,7 @@ class query_lexer_t string::const_iterator arg_i; string::const_iterator arg_end; - bool consume_whitespace; + bool consume_whitespace; public: struct token_t @@ -220,16 +220,33 @@ public: value_t::sequence_t::const_iterator _end) : begin(_begin), end(_end), consume_whitespace(false) { + TRACE_CTOR(query_lexer_t, ""); assert(begin != end); arg_i = (*begin).as_string().begin(); arg_end = (*begin).as_string().end(); } + query_lexer_t(const query_lexer_t& lexer) + : begin(lexer.begin), end(lexer.end), + arg_i(lexer.arg_i), arg_end(lexer.arg_end), + consume_whitespace(lexer.consume_whitespace), + token_cache(lexer.token_cache) + { + TRACE_CTOR(query_lexer_t, "copy"); + } + ~query_lexer_t() throw() { + TRACE_DTOR(query_lexer_t); + } token_t next_token(); void push_token(token_t tok) { assert(token_cache.kind == token_t::UNKNOWN); token_cache = tok; } + token_t peek_token() { + if (token_cache.kind == token_t::UNKNOWN) + token_cache = next_token(); + return token_cache; + } }; class query_parser_t @@ -245,22 +262,33 @@ class query_parser_t public: query_parser_t(value_t::sequence_t::const_iterator begin, value_t::sequence_t::const_iterator end) - : lexer(begin, end) {} + : lexer(begin, end) { + TRACE_CTOR(query_parser_t, ""); + } + query_parser_t(const query_parser_t& parser) + : lexer(parser.lexer) { + TRACE_CTOR(query_parser_t, "copy"); + } + ~query_parser_t() throw() { + TRACE_DTOR(query_parser_t); + } expr_t::ptr_op_t parse(); - value_t::sequence_t::const_iterator begin() const { - return lexer.begin; - } - value_t::sequence_t::const_iterator end() const { - return lexer.end; + bool tokens_remaining() { + query_lexer_t::token_t tok = lexer.peek_token(); + assert(tok.kind != query_lexer_t::token_t::UNKNOWN); + return tok.kind != query_lexer_t::token_t::END_REACHED; } }; -std::pair +std::pair args_to_predicate(value_t::sequence_t::const_iterator begin, value_t::sequence_t::const_iterator end); +std::pair +args_to_predicate(query_parser_t parser); + } // namespace ledger #endif // _PREDICATE_H -- cgit v1.2.3