1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_IDL_INC_LEX_HXX
21 #define INCLUDED_IDL_INC_LEX_HXX
23 #include <sal/types.h>
25 #include <tools/stream.hxx>
29 enum class SVTOKENTYPE
{ Empty
, Comment
,
37 friend class SvTokenStream
;
38 sal_uLong nLine
, nColumn
;
46 SvStringHashEntry
* pHash
;
50 SvToken( const SvToken
& rObj
) = delete;
52 SvToken
& operator = ( const SvToken
& rObj
);
54 OString
GetTokenAsString() const;
56 void SetLine( sal_uLong nLineP
) { nLine
= nLineP
; }
57 sal_uLong
GetLine() const { return nLine
; }
59 void SetColumn( sal_uLong nColumnP
) { nColumn
= nColumnP
; }
60 sal_uLong
GetColumn() const { return nColumn
; }
62 bool IsComment() const { return nType
== SVTOKENTYPE::Comment
; }
63 bool IsInteger() const { return nType
== SVTOKENTYPE::Integer
; }
64 bool IsString() const { return nType
== SVTOKENTYPE::String
; }
65 bool IsBool() const { return nType
== SVTOKENTYPE::Bool
; }
66 bool IsIdentifierHash() const
67 { return nType
== SVTOKENTYPE::HashId
; }
68 bool IsIdentifier() const
70 return nType
== SVTOKENTYPE::Identifier
71 || nType
== SVTOKENTYPE::HashId
;
73 bool IsChar() const { return nType
== SVTOKENTYPE::Char
; }
74 bool IsEof() const { return nType
== SVTOKENTYPE::EndOfFile
; }
76 const OString
& GetString() const
78 return IsIdentifierHash()
82 sal_uInt64
GetNumber() const { return nLong
; }
83 bool GetBool() const { return bBool
; }
84 char GetChar() const { return cChar
; }
86 void SetHash( SvStringHashEntry
* pHashP
)
87 { pHash
= pHashP
; nType
= SVTOKENTYPE::HashId
; }
88 bool Is( SvStringHashEntry
const * pEntry
) const
89 { return IsIdentifierHash() && pHash
== pEntry
; }
92 inline SvToken::SvToken()
95 , nType( SVTOKENTYPE::Empty
)
101 sal_uLong nLine
, nColumn
;
103 char c
; // next character
104 static const sal_uInt16 nTabSize
= 4; // length of tabulator
109 std::unique_ptr
<SvFileStream
> pInStream
;
111 std::vector
<std::unique_ptr
<SvToken
> > aTokList
;
112 std::vector
<std::unique_ptr
<SvToken
> >::iterator pCurToken
;
119 char GetFastNextChar()
121 return (nBufPos
< aBufStr
.getLength())
126 void FillTokenList();
127 sal_uInt64
GetNumber();
128 bool MakeToken( SvToken
& );
129 bool IsEof() const { return pInStream
->eof(); }
132 sal_uLong n
= Tell();
138 // if end of line spare calculation
144 nColumn
+= aBufStr
[n
++] == '\t' ? nTabSize
: 1;
148 SvTokenStream( const OUString
& rFileName
);
151 const OUString
& GetFileName() const { return aFileName
; }
152 SvStream
& GetStream() { return *pInStream
; }
154 SvToken
& GetToken_PrevAll()
156 std::vector
<std::unique_ptr
<SvToken
> >::iterator pRetToken
= pCurToken
;
158 // current iterator always valid
159 if(pCurToken
!= aTokList
.begin())
162 return *(*pRetToken
);
165 SvToken
& GetToken_Next()
167 std::vector
<std::unique_ptr
<SvToken
> >::iterator pRetToken
= pCurToken
++;
169 if (pCurToken
== aTokList
.end())
170 pCurToken
= pRetToken
;
174 return *(*pRetToken
);
177 SvToken
& GetToken() const { return *(*pCurToken
); }
179 bool ReadIf( char cChar
)
181 if( GetToken().IsChar() && cChar
== GetToken().GetChar() )
190 void ReadIfDelimiter()
192 if( GetToken().IsChar()
193 && (';' == GetToken().GetChar()
194 || ',' == GetToken().GetChar()) )
200 sal_uInt32
Tell() const { return pCurToken
-aTokList
.begin(); }
202 void Seek( sal_uInt32 nPos
)
204 pCurToken
= aTokList
.begin() + nPos
;
210 pCurToken
= aTokList
.begin()+nMaxPos
;
215 #endif // INCLUDED_IDL_INC_LEX_HXX
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */