1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _SCANNER_HXX 29*cdf0e10cSrcweir #define _SCANNER_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <tools/string.hxx> 32*cdf0e10cSrcweir #ifndef _SBERRORS_HXX 33*cdf0e10cSrcweir #include <basic/sberrors.hxx> 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir // Der Scanner ist stand-alone, d.h. er kann von ueberallher verwendet 37*cdf0e10cSrcweir // werden. Eine BASIC-Instanz ist fuer Fehlermeldungen notwendig. Ohne 38*cdf0e10cSrcweir // BASIC werden die Fehler nur gezaehlt. Auch ist Basic notwendig, wenn 39*cdf0e10cSrcweir // eine erweiterte SBX-Variable zur Erkennung von Datentypen etc. verwendet 40*cdf0e10cSrcweir // werden soll. 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir class StarBASIC; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir class SbiScanner 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir ::rtl::OUString aBuf; // Input-Puffer 47*cdf0e10cSrcweir ::rtl::OUString aLine; // aktuelle Zeile 48*cdf0e10cSrcweir const sal_Unicode* pLine; // Pointer 49*cdf0e10cSrcweir const sal_Unicode* pSaveLine; // Merker fuer Line 50*cdf0e10cSrcweir protected: 51*cdf0e10cSrcweir String aSym; // Symbolpuffer 52*cdf0e10cSrcweir String aError; // Fehler-String 53*cdf0e10cSrcweir SbxDataType eScanType; // evtl. Datentyp 54*cdf0e10cSrcweir StarBASIC* pBasic; // Instanz fuer Fehler-Callbacks 55*cdf0e10cSrcweir double nVal; // numerischer Wert 56*cdf0e10cSrcweir short nCurCol1; // aktuelle Spalte 1 57*cdf0e10cSrcweir short nSavedCol1; // gerettete Spalte 1 58*cdf0e10cSrcweir short nCol; // aktuelle Spaltennummer 59*cdf0e10cSrcweir short nErrors; // Anzahl Fehler 60*cdf0e10cSrcweir short nColLock; // Lock-Zaehler fuer Col1 61*cdf0e10cSrcweir sal_Int32 nBufPos; // aktuelle Buffer-Pos 62*cdf0e10cSrcweir sal_uInt16 nLine; // aktuelle Zeile 63*cdf0e10cSrcweir sal_uInt16 nCol1, nCol2; // aktuelle 1. und 2. Spalte 64*cdf0e10cSrcweir sal_Bool bSymbol; // sal_True: Symbol gescannt 65*cdf0e10cSrcweir sal_Bool bNumber; // sal_True: Zahl gescannt 66*cdf0e10cSrcweir sal_Bool bSpaces; // sal_True: Whitespace vor Token 67*cdf0e10cSrcweir sal_Bool bErrors; // sal_True: Fehler generieren 68*cdf0e10cSrcweir sal_Bool bAbort; // sal_True: abbrechen 69*cdf0e10cSrcweir sal_Bool bHash; // sal_True: # eingelesen 70*cdf0e10cSrcweir sal_Bool bError; // sal_True: Fehler generieren 71*cdf0e10cSrcweir sal_Bool bUsedForHilite; // sal_True: Nutzung fuer Highlighting 72*cdf0e10cSrcweir sal_Bool bCompatible; // sal_True: OPTION Compatibl 73*cdf0e10cSrcweir sal_Bool bVBASupportOn; // sal_True: OPTION VBASupport 1 otherwise default False 74*cdf0e10cSrcweir sal_Bool bPrevLineExtentsComment; // sal_True: Previous line is comment and ends on "... _" 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir void GenError( SbError ); 77*cdf0e10cSrcweir public: 78*cdf0e10cSrcweir SbiScanner( const ::rtl::OUString&, StarBASIC* = NULL ); 79*cdf0e10cSrcweir ~SbiScanner(); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir void EnableErrors() { bError = sal_False; } 82*cdf0e10cSrcweir sal_Bool IsHash() { return bHash; } 83*cdf0e10cSrcweir sal_Bool IsCompatible() { return bCompatible; } 84*cdf0e10cSrcweir void SetCompatible( bool b ) { bCompatible = b; } // #118206 85*cdf0e10cSrcweir sal_Bool IsVBASupportOn() { return bVBASupportOn; } 86*cdf0e10cSrcweir void SetVBASupportOn( bool b ) { bVBASupportOn = b; } 87*cdf0e10cSrcweir sal_Bool WhiteSpace() { return bSpaces; } 88*cdf0e10cSrcweir short GetErrors() { return nErrors; } 89*cdf0e10cSrcweir short GetLine() { return nLine; } 90*cdf0e10cSrcweir short GetCol1() { return nCol1; } 91*cdf0e10cSrcweir short GetCol2() { return nCol2; } 92*cdf0e10cSrcweir void SetCol1( short n ) { nCol1 = n; } 93*cdf0e10cSrcweir StarBASIC* GetBasic() { return pBasic; } 94*cdf0e10cSrcweir void SaveLine(void) { pSaveLine = pLine; } 95*cdf0e10cSrcweir void RestoreLine(void) { pLine = pSaveLine; } 96*cdf0e10cSrcweir void LockColumn(); 97*cdf0e10cSrcweir void UnlockColumn(); 98*cdf0e10cSrcweir sal_Bool DoesColonFollow(); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir sal_Bool NextSym(); // naechstes Symbol lesen 101*cdf0e10cSrcweir const String& GetSym() { return aSym; } 102*cdf0e10cSrcweir SbxDataType GetType() { return eScanType; } 103*cdf0e10cSrcweir double GetDbl() { return nVal; } 104*cdf0e10cSrcweir }; 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir class LetterTable 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir bool IsLetterTab[256]; 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir public: 111*cdf0e10cSrcweir LetterTable( void ); 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir inline bool isLetter( sal_Unicode c ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir bool bRet = (c < 256) ? IsLetterTab[c] : isLetterUnicode( c ); 116*cdf0e10cSrcweir return bRet; 117*cdf0e10cSrcweir } 118*cdf0e10cSrcweir bool isLetterUnicode( sal_Unicode c ); 119*cdf0e10cSrcweir }; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir class BasicSimpleCharClass 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir static LetterTable aLetterTable; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir public: 126*cdf0e10cSrcweir static sal_Bool isAlpha( sal_Unicode c, bool bCompatible ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir sal_Bool bRet = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') 129*cdf0e10cSrcweir || (bCompatible && aLetterTable.isLetter( c )); 130*cdf0e10cSrcweir return bRet; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir static sal_Bool isDigit( sal_Unicode c ) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir sal_Bool bRet = (c >= '0' && c <= '9'); 136*cdf0e10cSrcweir return bRet; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir static sal_Bool isAlphaNumeric( sal_Unicode c, bool bCompatible ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir sal_Bool bRet = isDigit( c ) || isAlpha( c, bCompatible ); 142*cdf0e10cSrcweir return bRet; 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir }; 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir #endif 147