1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scanner.hxx,v $
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 ************************************************************************/
34 #include <tools/string.hxx>
36 #include <basic/sberrors.hxx>
39 // Der Scanner ist stand-alone, d.h. er kann von ueberallher verwendet
40 // werden. Eine BASIC-Instanz ist fuer Fehlermeldungen notwendig. Ohne
41 // BASIC werden die Fehler nur gezaehlt. Auch ist Basic notwendig, wenn
42 // eine erweiterte SBX-Variable zur Erkennung von Datentypen etc. verwendet
49 ::rtl::OUString aBuf
; // Input-Puffer
50 ::rtl::OUString aLine
; // aktuelle Zeile
51 const sal_Unicode
* pLine
; // Pointer
52 const sal_Unicode
* pSaveLine
; // Merker fuer Line
54 String aSym
; // Symbolpuffer
55 String aError
; // Fehler-String
56 SbxDataType eScanType
; // evtl. Datentyp
57 StarBASIC
* pBasic
; // Instanz fuer Fehler-Callbacks
58 double nVal
; // numerischer Wert
59 short nCurCol1
; // aktuelle Spalte 1
60 short nSavedCol1
; // gerettete Spalte 1
61 short nCol
; // aktuelle Spaltennummer
62 short nErrors
; // Anzahl Fehler
63 short nColLock
; // Lock-Zaehler fuer Col1
64 INT32 nBufPos
; // aktuelle Buffer-Pos
65 USHORT nLine
; // aktuelle Zeile
66 USHORT nCol1
, nCol2
; // aktuelle 1. und 2. Spalte
67 BOOL bSymbol
; // TRUE: Symbol gescannt
68 BOOL bNumber
; // TRUE: Zahl gescannt
69 BOOL bSpaces
; // TRUE: Whitespace vor Token
70 BOOL bErrors
; // TRUE: Fehler generieren
71 BOOL bAbort
; // TRUE: abbrechen
72 BOOL bHash
; // TRUE: # eingelesen
73 BOOL bError
; // TRUE: Fehler generieren
74 BOOL bUsedForHilite
; // TRUE: Nutzung fuer Highlighting
75 BOOL bCompatible
; // TRUE: OPTION Compatibl
76 BOOL bVBASupportOn
; // TRUE: OPTION VBASupport 1 otherwise default False
77 BOOL bPrevLineExtentsComment
; // TRUE: Previous line is comment and ends on "... _"
79 void GenError( SbError
);
81 SbiScanner( const ::rtl::OUString
&, StarBASIC
* = NULL
);
84 void EnableErrors() { bError
= FALSE
; }
85 BOOL
IsHash() { return bHash
; }
86 BOOL
IsCompatible() { return bCompatible
; }
87 void SetCompatible( bool b
) { bCompatible
= b
; } // #118206
88 BOOL
IsVBASupportOn() { return bVBASupportOn
; }
89 void SetVBASupportOn( bool b
) { bVBASupportOn
= b
; }
90 BOOL
WhiteSpace() { return bSpaces
; }
91 short GetErrors() { return nErrors
; }
92 short GetLine() { return nLine
; }
93 short GetCol1() { return nCol1
; }
94 short GetCol2() { return nCol2
; }
95 void SetCol1( short n
) { nCol1
= n
; }
96 StarBASIC
* GetBasic() { return pBasic
; }
97 void SaveLine(void) { pSaveLine
= pLine
; }
98 void RestoreLine(void) { pLine
= pSaveLine
; }
101 BOOL
DoesColonFollow();
103 BOOL
NextSym(); // naechstes Symbol lesen
104 const String
& GetSym() { return aSym
; }
105 SbxDataType
GetType() { return eScanType
; }
106 double GetDbl() { return nVal
; }
111 bool IsLetterTab
[256];
116 inline bool isLetter( sal_Unicode c
)
118 bool bRet
= (c
< 256) ? IsLetterTab
[c
] : isLetterUnicode( c
);
121 bool isLetterUnicode( sal_Unicode c
);
124 class BasicSimpleCharClass
126 static LetterTable aLetterTable
;
129 static BOOL
isAlpha( sal_Unicode c
, bool bCompatible
)
131 BOOL bRet
= (c
>= 'a' && c
<= 'z') || (c
>= 'A' && c
<= 'Z')
132 || (bCompatible
&& aLetterTable
.isLetter( c
));
136 static BOOL
isDigit( sal_Unicode c
)
138 BOOL bRet
= (c
>= '0' && c
<= '9');
142 static BOOL
isAlphaNumeric( sal_Unicode c
, bool bCompatible
)
144 BOOL bRet
= isDigit( c
) || isAlpha( c
, bCompatible
);