|
1 // lexer.h |
|
2 // |
|
3 // Copyright (c) 2006 - 2010 Accenture. All rights reserved. |
|
4 // This component and the accompanying materials are made available |
|
5 // under the terms of the "Eclipse Public License v1.0" |
|
6 // which accompanies this distribution, and is available |
|
7 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 // |
|
9 // Initial Contributors: |
|
10 // Accenture - Initial contribution |
|
11 // |
|
12 |
|
13 #ifndef __LEXER_H__ |
|
14 #define __LEXER_H__ |
|
15 |
|
16 #include <e32base.h> |
|
17 |
|
18 class CReservedLookup; |
|
19 |
|
20 |
|
21 class TToken |
|
22 { |
|
23 public: |
|
24 enum TType |
|
25 { |
|
26 ENull, |
|
27 EString, |
|
28 EPipe, |
|
29 EDoublePipe, |
|
30 ERedirectStdinFromFile, |
|
31 ERedirectStdoutToFile, |
|
32 ERedirectStdoutToFileAppend, |
|
33 ERedirectStdoutToStderr, |
|
34 ERedirectStderrToFile, |
|
35 ERedirectStderrToFileAppend, |
|
36 ERedirectStderrToStdout, |
|
37 EAmpersand, |
|
38 EDoubleAmpersand, |
|
39 EAmpersandPipe, |
|
40 ENewLine, |
|
41 ESemicolon, |
|
42 EVariable |
|
43 }; |
|
44 public: |
|
45 TToken(); |
|
46 TToken(TType aType, const TDesC& aToken, TInt aPos); |
|
47 TToken& operator=(const TToken& aToken); |
|
48 TType Type() const; |
|
49 TInt Position() const; |
|
50 const TDesC& String() const; |
|
51 private: |
|
52 TType iType; |
|
53 TPtrC iToken; |
|
54 TInt iPos; |
|
55 }; |
|
56 |
|
57 |
|
58 class CLexer : public CBase |
|
59 { |
|
60 public: |
|
61 enum TBehaviour |
|
62 { |
|
63 EHandleSingleQuotes = 0x00000001, ///< Causes text within single quotes to be reported as a single TToken::EString type token. |
|
64 EHandleDoubleQuotes = 0x00000002, ///< Causes text within double quotes to be reported as a single TToken::EString type token. |
|
65 EHandleComments = 0x00000004 ///< Causes text following a '#' until the end of the line to be discarded. |
|
66 }; |
|
67 public: |
|
68 static CLexer* NewL(); |
|
69 static CLexer* NewL(TUint aBehaviour); |
|
70 static CLexer* NewLC(); |
|
71 static CLexer* NewLC(TUint aBehaviour); |
|
72 ~CLexer(); |
|
73 void DefineTokenTypeL(TToken::TType aTokenType, const TDesC& aString); |
|
74 void Set(const TDesC& aDes, const TChar& aEscapeChar); |
|
75 TToken NextToken(); |
|
76 TInt CurrentOffset() const; |
|
77 TBool More(); |
|
78 private: |
|
79 CLexer(TUint aBehaviour); |
|
80 void ConstructL(); |
|
81 void SkipSingleQuotedChars(); |
|
82 void SkipDoubleQuotedChars(); |
|
83 void SkipComment(); |
|
84 void SkipWhiteSpace(); |
|
85 private: |
|
86 TUint iBehaviour; |
|
87 TChar iEscapeChar; |
|
88 TLex iLex; |
|
89 CReservedLookup* iReservedLookup; |
|
90 }; |
|
91 |
|
92 |
|
93 #endif // __LEXER_H__ |