1*234bd5c5SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*234bd5c5SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*234bd5c5SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*234bd5c5SAndrew Rist * distributed with this work for additional information 6*234bd5c5SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*234bd5c5SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*234bd5c5SAndrew Rist * "License"); you may not use this file except in compliance 9*234bd5c5SAndrew Rist * with the License. You may obtain a copy of the License at 10*234bd5c5SAndrew Rist * 11*234bd5c5SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*234bd5c5SAndrew Rist * 13*234bd5c5SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*234bd5c5SAndrew Rist * software distributed under the License is distributed on an 15*234bd5c5SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*234bd5c5SAndrew Rist * KIND, either express or implied. See the License for the 17*234bd5c5SAndrew Rist * specific language governing permissions and limitations 18*234bd5c5SAndrew Rist * under the License. 19*234bd5c5SAndrew Rist * 20*234bd5c5SAndrew Rist *************************************************************/ 21*234bd5c5SAndrew Rist 22*234bd5c5SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _SCANNER_HXX 25cdf0e10cSrcweir #define _SCANNER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <tools/string.hxx> 28cdf0e10cSrcweir #ifndef _SBERRORS_HXX 29cdf0e10cSrcweir #include <basic/sberrors.hxx> 30cdf0e10cSrcweir #endif 31cdf0e10cSrcweir 32cdf0e10cSrcweir // Der Scanner ist stand-alone, d.h. er kann von ueberallher verwendet 33cdf0e10cSrcweir // werden. Eine BASIC-Instanz ist fuer Fehlermeldungen notwendig. Ohne 34cdf0e10cSrcweir // BASIC werden die Fehler nur gezaehlt. Auch ist Basic notwendig, wenn 35cdf0e10cSrcweir // eine erweiterte SBX-Variable zur Erkennung von Datentypen etc. verwendet 36cdf0e10cSrcweir // werden soll. 37cdf0e10cSrcweir 38cdf0e10cSrcweir class StarBASIC; 39cdf0e10cSrcweir 40cdf0e10cSrcweir class SbiScanner 41cdf0e10cSrcweir { 42cdf0e10cSrcweir ::rtl::OUString aBuf; // Input-Puffer 43cdf0e10cSrcweir ::rtl::OUString aLine; // aktuelle Zeile 44cdf0e10cSrcweir const sal_Unicode* pLine; // Pointer 45cdf0e10cSrcweir const sal_Unicode* pSaveLine; // Merker fuer Line 46cdf0e10cSrcweir protected: 47cdf0e10cSrcweir String aSym; // Symbolpuffer 48cdf0e10cSrcweir String aError; // Fehler-String 49cdf0e10cSrcweir SbxDataType eScanType; // evtl. Datentyp 50cdf0e10cSrcweir StarBASIC* pBasic; // Instanz fuer Fehler-Callbacks 51cdf0e10cSrcweir double nVal; // numerischer Wert 52cdf0e10cSrcweir short nCurCol1; // aktuelle Spalte 1 53cdf0e10cSrcweir short nSavedCol1; // gerettete Spalte 1 54cdf0e10cSrcweir short nCol; // aktuelle Spaltennummer 55cdf0e10cSrcweir short nErrors; // Anzahl Fehler 56cdf0e10cSrcweir short nColLock; // Lock-Zaehler fuer Col1 57cdf0e10cSrcweir sal_Int32 nBufPos; // aktuelle Buffer-Pos 58cdf0e10cSrcweir sal_uInt16 nLine; // aktuelle Zeile 59cdf0e10cSrcweir sal_uInt16 nCol1, nCol2; // aktuelle 1. und 2. Spalte 60cdf0e10cSrcweir sal_Bool bSymbol; // sal_True: Symbol gescannt 61cdf0e10cSrcweir sal_Bool bNumber; // sal_True: Zahl gescannt 62cdf0e10cSrcweir sal_Bool bSpaces; // sal_True: Whitespace vor Token 63cdf0e10cSrcweir sal_Bool bErrors; // sal_True: Fehler generieren 64cdf0e10cSrcweir sal_Bool bAbort; // sal_True: abbrechen 65cdf0e10cSrcweir sal_Bool bHash; // sal_True: # eingelesen 66cdf0e10cSrcweir sal_Bool bError; // sal_True: Fehler generieren 67cdf0e10cSrcweir sal_Bool bUsedForHilite; // sal_True: Nutzung fuer Highlighting 68cdf0e10cSrcweir sal_Bool bCompatible; // sal_True: OPTION Compatibl 69cdf0e10cSrcweir sal_Bool bVBASupportOn; // sal_True: OPTION VBASupport 1 otherwise default False 70cdf0e10cSrcweir sal_Bool bPrevLineExtentsComment; // sal_True: Previous line is comment and ends on "... _" 71cdf0e10cSrcweir 72cdf0e10cSrcweir void GenError( SbError ); 73cdf0e10cSrcweir public: 74cdf0e10cSrcweir SbiScanner( const ::rtl::OUString&, StarBASIC* = NULL ); 75cdf0e10cSrcweir ~SbiScanner(); 76cdf0e10cSrcweir EnableErrors()77cdf0e10cSrcweir void EnableErrors() { bError = sal_False; } IsHash()78cdf0e10cSrcweir sal_Bool IsHash() { return bHash; } IsCompatible()79cdf0e10cSrcweir sal_Bool IsCompatible() { return bCompatible; } SetCompatible(bool b)80cdf0e10cSrcweir void SetCompatible( bool b ) { bCompatible = b; } // #118206 IsVBASupportOn()81cdf0e10cSrcweir sal_Bool IsVBASupportOn() { return bVBASupportOn; } SetVBASupportOn(bool b)82cdf0e10cSrcweir void SetVBASupportOn( bool b ) { bVBASupportOn = b; } WhiteSpace()83cdf0e10cSrcweir sal_Bool WhiteSpace() { return bSpaces; } GetErrors()84cdf0e10cSrcweir short GetErrors() { return nErrors; } GetLine()85cdf0e10cSrcweir short GetLine() { return nLine; } GetCol1()86cdf0e10cSrcweir short GetCol1() { return nCol1; } GetCol2()87cdf0e10cSrcweir short GetCol2() { return nCol2; } SetCol1(short n)88cdf0e10cSrcweir void SetCol1( short n ) { nCol1 = n; } GetBasic()89cdf0e10cSrcweir StarBASIC* GetBasic() { return pBasic; } SaveLine(void)90cdf0e10cSrcweir void SaveLine(void) { pSaveLine = pLine; } RestoreLine(void)91cdf0e10cSrcweir void RestoreLine(void) { pLine = pSaveLine; } 92cdf0e10cSrcweir void LockColumn(); 93cdf0e10cSrcweir void UnlockColumn(); 94cdf0e10cSrcweir sal_Bool DoesColonFollow(); 95cdf0e10cSrcweir 96cdf0e10cSrcweir sal_Bool NextSym(); // naechstes Symbol lesen GetSym()97cdf0e10cSrcweir const String& GetSym() { return aSym; } GetType()98cdf0e10cSrcweir SbxDataType GetType() { return eScanType; } GetDbl()99cdf0e10cSrcweir double GetDbl() { return nVal; } 100cdf0e10cSrcweir }; 101cdf0e10cSrcweir 102cdf0e10cSrcweir class LetterTable 103cdf0e10cSrcweir { 104cdf0e10cSrcweir bool IsLetterTab[256]; 105cdf0e10cSrcweir 106cdf0e10cSrcweir public: 107cdf0e10cSrcweir LetterTable( void ); 108cdf0e10cSrcweir isLetter(sal_Unicode c)109cdf0e10cSrcweir inline bool isLetter( sal_Unicode c ) 110cdf0e10cSrcweir { 111cdf0e10cSrcweir bool bRet = (c < 256) ? IsLetterTab[c] : isLetterUnicode( c ); 112cdf0e10cSrcweir return bRet; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir bool isLetterUnicode( sal_Unicode c ); 115cdf0e10cSrcweir }; 116cdf0e10cSrcweir 117cdf0e10cSrcweir class BasicSimpleCharClass 118cdf0e10cSrcweir { 119cdf0e10cSrcweir static LetterTable aLetterTable; 120cdf0e10cSrcweir 121cdf0e10cSrcweir public: isAlpha(sal_Unicode c,bool bCompatible)122cdf0e10cSrcweir static sal_Bool isAlpha( sal_Unicode c, bool bCompatible ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir sal_Bool bRet = (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') 125cdf0e10cSrcweir || (bCompatible && aLetterTable.isLetter( c )); 126cdf0e10cSrcweir return bRet; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir isDigit(sal_Unicode c)129cdf0e10cSrcweir static sal_Bool isDigit( sal_Unicode c ) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir sal_Bool bRet = (c >= '0' && c <= '9'); 132cdf0e10cSrcweir return bRet; 133cdf0e10cSrcweir } 134cdf0e10cSrcweir isAlphaNumeric(sal_Unicode c,bool bCompatible)135cdf0e10cSrcweir static sal_Bool isAlphaNumeric( sal_Unicode c, bool bCompatible ) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir sal_Bool bRet = isDigit( c ) || isAlpha( c, bCompatible ); 138cdf0e10cSrcweir return bRet; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir }; 141cdf0e10cSrcweir 142cdf0e10cSrcweir #endif 143