LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / basic / source / inc / token.hxx
blob4230ff585b7aaa3c2b6fe2f940ba224b5147fa45
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include "scanner.hxx"
24 // The tokenizer is stand-alone, i. e. he can be used from everywhere.
25 // A BASIC-instance is necessary for error messages. Without BASIC the
26 // errors are only counted. The BASIC is also necessary when an advanced
27 // SBX-variable shall be used for recognition of data types etc.
30 enum SbiToken {
31 NIL = 0,
32 // tokens between 0x20 and 0x3F are literals:
33 LPAREN = '(', RPAREN = ')', COMMA = ',', DOT = '.', EXCLAM = '!',
34 HASH = '#', SEMICOLON = ';',
36 // commands:
37 FIRSTKWD = 0x40,
38 AS = FIRSTKWD, ALIAS, ASSIGN,
39 CALL, CASE, CLOSE, COMPARE, CONST_,
40 DECLARE, DIM, DO,
42 // in the order of the data type enums!
43 DEFINT, DEFLNG, DEFSNG, DEFDBL, DEFCUR, DEFDATE, DEFSTR, DEFOBJ,
44 DEFERR, DEFBOOL, DEFVAR,
45 // in the order of the data type enums!
46 DATATYPE1,
47 TINTEGER = DATATYPE1,
48 TLONG, TSINGLE, TDOUBLE, TCURRENCY, TDATE, TSTRING, TOBJECT,
49 ERROR_, TBOOLEAN, TVARIANT, TBYTE,
50 DATATYPE2 = TBYTE,
52 EACH, ELSE, ELSEIF, END, ERASE, EXIT,
53 FOR, FUNCTION,
54 GET, GLOBAL, GOSUB, GOTO,
55 IF, IN_, INPUT,
56 LET, LINE, LINEINPUT, LOCAL, LOOP, LPRINT, LSET,
57 NAME, NEW, NEXT,
58 ON, OPEN, OPTION, ATTRIBUTE, IMPLEMENTS,
59 PRINT, PRIVATE, PROPERTY, PUBLIC,
60 REDIM, REM, RESUME, RETURN, RSET,
61 SELECT, SET, SHARED, STATIC, STEP, STOP, SUB,
62 TEXT, THEN, TO, TYPE, ENUM,
63 UNTIL,
64 WEND, WHILE, WITH, WRITE,
65 ENDENUM, ENDIF, ENDFUNC, ENDPROPERTY, ENDSUB, ENDTYPE, ENDSELECT, ENDWITH,
66 // end of all keywords
67 LASTKWD = ENDWITH,
68 // statement end
69 EOS, EOLN,
70 // operators:
71 EXPON, NEG, MUL,
72 DIV, IDIV, MOD, PLUS, MINUS,
73 EQ, NE, LT, GT, LE, GE,
74 NOT, AND, OR, XOR, EQV,
75 IMP, CAT, LIKE, IS, TYPEOF,
76 // miscellaneous:
77 FIRSTEXTRA,
78 NUMBER=FIRSTEXTRA, FIXSTRING, SYMBOL, CDECL_, BYVAL, BYREF,
79 OUTPUT, RANDOM, APPEND, BINARY, ACCESS,
80 LOCK, READ, PRESERVE, BASE, ANY, LIB, OPTIONAL_, PTRSAFE,
81 BASIC_EXPLICIT, COMPATIBLE, CLASSMODULE, PARAMARRAY, WITHEVENTS,
83 // from here there are JavaScript-tokens (same enum so that same type)
84 FIRSTJAVA,
85 JS_BREAK=FIRSTJAVA, JS_CONTINUE, JS_FOR, JS_FUNCTION, JS_IF, JS_NEW,
86 JS_RETURN, JS_THIS, JS_VAR, JS_WHILE, JS_WITH,
88 // JavaScript-operators
89 // _ASS_ = Assignment
90 JS_COMMA, JS_ASSIGNMENT, JS_ASS_PLUS, JS_ASS_MINUS, JS_ASS_MUL,
91 JS_ASS_DIV, JS_ASS_MOD, JS_ASS_LSHIFT, JS_ASS_RSHIFT, JS_ASS_RSHIFT_Z,
92 JS_ASS_AND, JS_ASS_XOR, JS_ASS_OR,
93 JS_COND_QUEST, JS_COND_SEL, JS_LOG_OR, JS_LOG_AND, JS_BIT_OR,
94 JS_BIT_XOR, JS_BIT_AND, JS_EQ, JS_NE, JS_LT, JS_LE,
95 JS_GT, JS_GE, JS_LSHIFT, JS_RSHIFT, JS_RSHIFT_Z,
96 JS_PLUS, JS_MINUS, JS_MUL, JS_DIV, JS_MOD, JS_LOG_NOT, JS_BIT_NOT,
97 JS_INC, JS_DEC, JS_LPAREN, JS_RPAREN, JS_LINDEX, JS_RINDEX
98 , VBASUPPORT
101 class SbiTokenizer : public SbiScanner {
102 protected:
103 SbiToken eCurTok;
104 SbiToken ePush;
105 sal_uInt16 nPLine, nPCol1, nPCol2; // pushback location
106 bool bEof;
107 bool bEos;
108 bool bAs; // last keyword was AS
109 bool bErrorIsSymbol; // Handle Error token as Symbol, not keyword
110 public:
111 SbiTokenizer( const OUString&, StarBASIC* = nullptr );
113 bool IsEof() const { return bEof; }
114 bool IsEos() const { return bEos; }
116 void Push( SbiToken );
117 const OUString& Symbol( SbiToken ); // reconversion
119 SbiToken Peek(); // read the next token
120 SbiToken Next(); // read a token
121 bool MayBeLabel( bool= false );
123 void Error( ErrCode c ) { GenError( c ); }
124 void Error( ErrCode, SbiToken );
125 void Error( ErrCode, const OUString &);
127 static bool IsEoln( SbiToken t )
128 { return t == EOS || t == EOLN || t == REM; }
129 static bool IsKwd( SbiToken t )
130 { return t >= FIRSTKWD && t <= LASTKWD; }
131 static bool IsExtra( SbiToken t )
132 { return t >= FIRSTEXTRA; }
133 static OUString GetKeywordCase( const OUString& sKeyword );
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */