CLucene - a full-featured, c++ search engine
API Documentation
00001 /*------------------------------------------------------------------------------ 00002 * Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team 00003 * 00004 * Distributable under the terms of either the Apache License (Version 2.0) or 00005 * the GNU Lesser General Public License, as specified in the COPYING file. 00006 ------------------------------------------------------------------------------*/ 00007 #ifndef _lucene_queryParser_Lexer_ 00008 #define _lucene_queryParser_Lexer_ 00009 00010 #if defined(_LUCENE_PRAGMA_ONCE) 00011 # pragma once 00012 #endif 00013 00014 #include "CLucene/util/FastCharStream.h" 00015 #include "CLucene/util/Reader.h" 00016 #include "CLucene/util/StringBuffer.h" 00017 00018 #include "TokenList.h" 00019 class QueryParserBase; 00020 00021 CL_NS_DEF(queryParser) 00022 00023 // A simple Lexer that is used by QueryParser. 00024 class Lexer:LUCENE_BASE 00025 { 00026 private: 00027 CL_NS(util)::FastCharStream* reader; 00028 QueryParserBase* queryparser; //holds the queryparser so that we can do callbacks 00029 bool delSR; //Indicates if the reader must be deleted or not 00030 00031 public: 00032 // Initializes a new instance of the Lexer class with the specified 00033 // query to lex. 00034 Lexer(QueryParserBase* queryparser, const TCHAR* query); 00035 00036 // Initializes a new instance of the Lexer class with the specified 00037 // TextReader to lex. 00038 Lexer(QueryParserBase* queryparser, CL_NS(util)::Reader* source); 00039 00040 //Breaks the input stream onto the tokens list tokens 00041 void Lex(TokenList *tokens); 00042 00043 ~Lexer(); 00044 00045 private: 00046 bool GetNextToken(QueryToken* token); 00047 00048 // Reads an integer number. buf should quite large, probably as large as a field should ever be 00049 void ReadIntegerNumber(const TCHAR ch, TCHAR* buf, int buflen); 00050 00051 // Reads an inclusive range like [some words] 00052 bool ReadInclusiveRange(const TCHAR prev, QueryToken* token); 00053 00054 // Reads an exclusive range like {some words} 00055 bool ReadExclusiveRange(const TCHAR prev, QueryToken* token); 00056 00057 // Reads quoted string like "something else" 00058 bool ReadQuoted(const TCHAR prev, QueryToken* token); 00059 00060 bool ReadTerm(const TCHAR prev, QueryToken* token); 00061 00062 //reads an escaped character into the buf. Buf requires at least 3 characters 00063 bool ReadEscape(const TCHAR prev, TCHAR* buf); 00064 }; 00065 CL_NS_END 00066 #endif