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