| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
* |
| 9 |
* This file incorporates work covered by the following license notice: |
| 10 |
* |
| 11 |
* Licensed to the Apache Software Foundation (ASF) under one or more |
| 12 |
* contributor license agreements. See the NOTICE file distributed |
| 13 |
* with this work for additional information regarding copyright |
| 14 |
* ownership. The ASF licenses this file to you under the Apache |
| 15 |
* License, Version 2.0 (the "License"); you may not use this file |
| 16 |
* except in compliance with the License. You may obtain a copy of |
| 17 |
* the License at http://www.apache.org/licenses/LICENSE-2.0 . |
| 18 |
*/ |
| 19 |
|
| 20 |
#pragma once |
| 21 |
|
| 22 |
#include <basic/sbxdef.hxx> |
| 23 |
#include <comphelper/errcode.hxx> |
| 24 |
|
| 25 |
// The scanner is stand-alone, i. e. it can be used from everywhere. |
| 26 |
// A BASIC-instance is necessary for error messages. Without BASIC |
| 27 |
// the errors are only counted. Also the BASIC is necessary when an |
| 28 |
// advanced SBX-variable shall be used for data type recognition etc. |
| 29 |
|
| 30 |
class StarBASIC; |
| 31 |
|
| 32 |
class SbiScanner |
| 33 |
{ |
| 34 |
OUString aBuf; // input buffer |
| 35 |
OUString aLine; |
| 36 |
OUString aSaveLine; |
| 37 |
sal_Int32 nLineIdx; |
| 38 |
sal_Int32 nSaveLineIdx; |
| 39 |
StarBASIC* pBasic; // instance for error callbacks |
| 40 |
|
| 41 |
void scanAlphanumeric(); |
| 42 |
void scanGoto(); |
| 43 |
bool readLine(); |
| 44 |
protected: |
| 45 |
OUString aSym; |
| 46 |
OUString aError; |
| 47 |
SbxDataType eScanType; |
| 48 |
double nVal; // numeric value |
| 49 |
sal_Int32 nSavedCol1; |
| 50 |
sal_Int32 nCol; |
| 51 |
sal_Int32 nErrors; |
| 52 |
sal_Int32 nColLock; // lock counter for Col1 |
| 53 |
sal_Int32 nBufPos; |
| 54 |
sal_Int32 nLine; |
| 55 |
sal_Int32 nCol1, nCol2; |
| 56 |
bool bSymbol; // true: symbol scanned |
| 57 |
bool bNumber; // true: number scanned |
| 58 |
bool bSpaces; // true: whitespace before token |
| 59 |
bool bAbort; |
| 60 |
bool bHash; // true: # has been read in |
| 61 |
bool bError; // true: generate error |
| 62 |
bool bCompatible; // true: OPTION compatible |
| 63 |
bool bVBASupportOn; // true: OPTION VBASupport 1 otherwise default False |
| 64 |
bool bPrevLineExtentsComment; // true: Previous line is comment and ends on "... _" |
| 65 |
bool bClosingUnderscore; // true: Closing underscore followed by end of line |
| 66 |
bool bLineEndsWithWhitespace; // true: Line ends with whitespace (BasicCharClass::isWhitespace) |
| 67 |
|
| 68 |
bool bInStatement; |
| 69 |
void GenError( ErrCode ); |
| 70 |
public: |
| 71 |
SbiScanner( OUString , StarBASIC* = nullptr ); |
| 72 |
|
| 73 |
void EnableErrors() { bError = false; } |
| 74 |
bool IsHash() const { return bHash; } |
| 75 |
bool IsCompatible() const { return bCompatible; } |
| 76 |
void SetCompatible( bool b ) { bCompatible = b; } // #118206 |
| 77 |
bool IsVBASupportOn() const { return bVBASupportOn; } |
| 78 |
bool WhiteSpace() const { return bSpaces; } |
| 79 |
sal_Int32 GetErrors() const { return nErrors; } |
| 80 |
sal_Int32 GetLine() const { return nLine; } |
| 81 |
sal_Int32 GetCol1() const { return nCol1; } |
| 82 |
void SetCol1( sal_Int32 n ) { nCol1 = n; } |
| 83 |
StarBASIC* GetBasic() { return pBasic; } |
| 84 |
void SaveLine() { aSaveLine = aLine; nSaveLineIdx = nLineIdx; } |
| 85 |
void RestoreLine() { nLineIdx = nSaveLineIdx; aLine = aSaveLine; } |
| 86 |
void LockColumn(); |
| 87 |
void UnlockColumn(); |
| 88 |
bool DoesColonFollow(); |
| 89 |
|
| 90 |
bool NextSym(); |
| 91 |
const OUString& GetSym() const { return aSym; } |
| 92 |
SbxDataType GetType() const { return eScanType; } |
| 93 |
double GetDbl() const { return nVal; } |
| 94 |
}; |
| 95 |
|
| 96 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |