blob: 4ca6c8ffc97c8bfbe582bb36087f9e1411e92be0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
/*------------------------------------------------------------------------------
* Copyright (C) 2003-2006 Ben van Klinken and the CLucene Team
*
* Distributable under the terms of either the Apache License (Version 2.0) or
* the GNU Lesser General Public License, as specified in the COPYING file.
*
* Changes are Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
------------------------------------------------------------------------------*/
#ifndef _lucene_queryParser_Lexer_
#define _lucene_queryParser_Lexer_
#if defined(_LUCENE_PRAGMA_ONCE)
# pragma once
#endif
#include "CLucene/util/FastCharStream.h"
#include "CLucene/util/Reader.h"
#include "CLucene/util/StringBuffer.h"
#include "TokenList.h"
CL_NS_DEF(queryParser)
class QueryParserBase;
// A simple Lexer that is used by QueryParser.
class Lexer:LUCENE_BASE
{
private:
CL_NS(util)::FastCharStream* reader;
QueryParserBase* queryparser; //holds the queryparser so that we can do callbacks
bool delSR; //Indicates if the reader must be deleted or not
public:
// Initializes a new instance of the Lexer class with the specified
// query to lex.
Lexer(QueryParserBase* queryparser, const TCHAR* query);
// Initializes a new instance of the Lexer class with the specified
// TextReader to lex.
Lexer(QueryParserBase* queryparser, CL_NS(util)::Reader* source);
//Breaks the input stream onto the tokens list tokens
void Lex(TokenList *tokens);
~Lexer();
private:
bool GetNextToken(QueryToken* token);
// Reads an integer number. buf should quite large, probably as large as a field should ever be
void ReadIntegerNumber(const TCHAR ch, TCHAR* buf, int buflen);
// Reads an inclusive range like [some words]
bool ReadInclusiveRange(const TCHAR prev, QueryToken* token);
// Reads an exclusive range like {some words}
bool ReadExclusiveRange(const TCHAR prev, QueryToken* token);
// Reads quoted string like "something else"
bool ReadQuoted(const TCHAR prev, QueryToken* token);
bool ReadTerm(const TCHAR prev, QueryToken* token);
//reads an escaped character into the buf. Buf requires at least 3 characters
bool ReadEscape(const TCHAR prev, TCHAR* buf);
};
CL_NS_END
#endif
|