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