merge the formfield patch from ooo-build
[ooovba.git] / idl / inc / lex.hxx
blob620cfd0a9f791ac4f7fb5459b032cf3c63da84ca
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lex.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _LEX_HXX
32 #define _LEX_HXX
34 #include <hash.hxx>
35 #include <tools/gen.hxx>
36 #include <tools/stream.hxx>
38 /******************** enum ***********************************************/
39 enum SVTOKEN_ENUM { SVTOKEN_EMPTY, SVTOKEN_COMMENT,
40 SVTOKEN_INTEGER, SVTOKEN_STRING,
41 SVTOKEN_BOOL, SVTOKEN_IDENTIFIER,
42 SVTOKEN_CHAR, SVTOKEN_RTTIBASE,
43 SVTOKEN_EOF, SVTOKEN_HASHID };
45 /******************** class SvToken **************************************/
46 class BigInt;
47 class SvToken
49 friend class SvTokenStream;
50 ULONG nLine, nColumn;
51 SVTOKEN_ENUM nType;
52 ByteString aString;
53 union
55 ULONG nLong;
56 BOOL bBool;
57 char cChar;
58 // SvRttiBase * pComplexObj;
59 SvStringHashEntry * pHash;
61 public:
62 SvToken();
63 SvToken( const SvToken & rObj );
64 SvToken( ULONG n );
65 SvToken( SVTOKEN_ENUM nTypeP, BOOL b );
66 SvToken( char c );
67 SvToken( SVTOKEN_ENUM nTypeP, const ByteString & rStr );
68 // SvToken( SvRttiBase * pComplexObj );
69 SvToken( SVTOKEN_ENUM nTypeP );
71 SvToken & operator = ( const SvToken & rObj );
73 ByteString GetTokenAsString() const;
74 SVTOKEN_ENUM GetType() const { return nType; }
76 void SetLine( ULONG nLineP ) { nLine = nLineP; }
77 ULONG GetLine() const { return nLine; }
79 void SetColumn( ULONG nColumnP ) { nColumn = nColumnP; }
80 ULONG GetColumn() const { return nColumn; }
82 BOOL IsEmpty() const { return nType == SVTOKEN_EMPTY; }
83 BOOL IsComment() const { return nType == SVTOKEN_COMMENT; }
84 BOOL IsInteger() const { return nType == SVTOKEN_INTEGER; }
85 BOOL IsString() const { return nType == SVTOKEN_STRING; }
86 BOOL IsBool() const { return nType == SVTOKEN_BOOL; }
87 BOOL IsIdentifierHash() const
88 { return nType == SVTOKEN_HASHID; }
89 BOOL IsIdentifier() const
91 return nType == SVTOKEN_IDENTIFIER
92 || nType == SVTOKEN_HASHID;
94 BOOL IsChar() const { return nType == SVTOKEN_CHAR; }
95 BOOL IsRttiBase() const { return nType == SVTOKEN_RTTIBASE; }
96 BOOL IsEof() const { return nType == SVTOKEN_EOF; }
98 const ByteString & GetString() const
100 return IsIdentifierHash()
101 ? pHash->GetName()
102 : aString;
104 ULONG GetNumber() const { return nLong; }
105 BOOL GetBool() const { return bBool; }
106 char GetChar() const { return cChar; }
107 // SvRttiBase *GetObject() const { return pComplexObj; }
109 void SetHash( SvStringHashEntry * pHashP )
110 { pHash = pHashP; nType = SVTOKEN_HASHID; }
111 BOOL HasHash() const
112 { return nType == SVTOKEN_HASHID; }
113 SvStringHashEntry * GetHash() const { return pHash; }
114 BOOL Is( SvStringHashEntry * pEntry ) const
115 { return IsIdentifierHash() && pHash == pEntry; }
118 inline SvToken::SvToken()
119 : nType( SVTOKEN_EMPTY ) {}
121 inline SvToken::SvToken( ULONG n )
122 : nType( SVTOKEN_INTEGER ), nLong( n ) {}
124 inline SvToken::SvToken( SVTOKEN_ENUM nTypeP, BOOL b )
125 : nType( nTypeP ), bBool( b ) {}
127 inline SvToken::SvToken( char c )
128 : nType( SVTOKEN_CHAR ), cChar( c ) {}
130 inline SvToken::SvToken( SVTOKEN_ENUM nTypeP, const ByteString & rStr )
131 : nType( nTypeP ), aString( rStr ) {}
134 inline SvToken::SvToken( SvRttiBase * pObj )
135 : nType( SVTOKEN_RTTIBASE ), pComplexObj( pObj )
136 { pObj->AddRef(); }
139 inline SvToken::SvToken( SVTOKEN_ENUM nTypeP )
140 : nType( nTypeP ) {}
142 DECLARE_LIST( SvTokenList, SvToken * )
144 /******************** class SvTokenStream ********************************/
145 class SvTokenStream
147 ULONG nLine, nColumn;
148 int nBufPos;
149 int c; // naechstes Zeichen
150 CharSet nCharSet;
151 char * pCharTab; // Zeiger auf die Konverierungstabelle
152 USHORT nTabSize; // Tabulator Laenge
153 ByteString aStrTrue;
154 ByteString aStrFalse;
155 ULONG nMaxPos;
157 SvFileStream * pInStream;
158 SvStream & rInStream;
159 String aFileName;
160 SvTokenList aTokList;
161 SvToken * pCurToken;
163 void InitCtor();
165 ByteString aBufStr;
166 int GetNextChar();
167 int GetFastNextChar()
169 return aBufStr.GetChar((USHORT)nBufPos++);
172 void FillTokenList();
173 ULONG GetNumber();
174 BOOL MakeToken( SvToken & );
175 BOOL IsEof() const { return rInStream.IsEof(); }
176 void SetMax()
178 ULONG n = Tell();
179 if( n > nMaxPos )
180 nMaxPos = n;
182 void CalcColumn()
184 // wenn Zeilenende berechnung sparen
185 if( 0 != c )
187 USHORT n = 0;
188 nColumn = 0;
189 while( n < nBufPos )
190 nColumn += aBufStr.GetChar(n++) == '\t' ? nTabSize : 1;
193 public:
194 SvTokenStream( const String & rFileName );
195 SvTokenStream( SvStream & rInStream, const String & rFileName );
196 ~SvTokenStream();
198 const String & GetFileName() const { return aFileName; }
199 SvStream & GetStream() { return rInStream; }
201 void SetCharSet( CharSet nSet );
202 CharSet GetCharSet() const { return nCharSet; }
204 void SetTabSize( USHORT nTabSizeP )
205 { nTabSize = nTabSizeP; }
206 USHORT GetTabSize() const { return nTabSize; }
208 SvToken * GetToken_PrevAll()
210 SvToken * pRetToken = pCurToken;
211 if( NULL == (pCurToken = aTokList.Prev()) )
212 // Current Zeiger nie Null
213 pCurToken = pRetToken;
215 return pRetToken;
217 SvToken * GetToken_NextAll()
219 SvToken * pRetToken = pCurToken;
220 if( NULL == (pCurToken = aTokList.Next()) )
221 // Current Zeiger nie Null
222 pCurToken = pRetToken;
223 SetMax();
224 return pRetToken;
226 SvToken * GetToken_Next()
228 // Kommentare werden initial entfernt
229 return GetToken_NextAll();
231 SvToken * GetToken() const { return pCurToken; }
232 BOOL Read( char cChar )
234 if( pCurToken->IsChar()
235 && cChar == pCurToken->GetChar() )
237 GetToken_Next();
238 return TRUE;
240 else
241 return FALSE;
243 void ReadDelemiter()
245 if( pCurToken->IsChar()
246 && (';' == pCurToken->GetChar()
247 || ',' == pCurToken->GetChar()) )
249 GetToken_Next();
253 UINT32 Tell() const
254 { return aTokList.GetCurPos(); }
255 void Seek( UINT32 nPos )
257 pCurToken = aTokList.Seek( nPos );
258 SetMax();
260 void SeekRel( INT32 nRelPos )
262 pCurToken = aTokList.Seek( Tell() + nRelPos );
263 SetMax();
265 void SeekEnd()
267 pCurToken = aTokList.Seek( nMaxPos );
273 #endif // _LEX_HXX