1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: token.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
34 #include "scanner.hxx"
36 #include <basic/sbdef.hxx>
40 #define SbiTokenSHAREDTMPUNDEF
44 // Der Tokenizer ist stand-alone, d.h. er kann von ueberallher verwendet
45 // werden. Eine BASIC-Instanz ist fuer Fehlermeldungen notwendig. Ohne
46 // BASIC werden die Fehler nur gezaehlt. Auch ist Basic notwendig, wenn
47 // eine erweiterte SBX-Variable zur Erkennung von Datentypen etc. verwendet
52 // Token zwischen 0x20 und 0x3F sind Literale:
53 LPAREN
= '(', RPAREN
= ')', COMMA
= ',', DOT
= '.', EXCLAM
= '!',
54 HASH
= '#', SEMICOLON
= ';',
58 AS
= FIRSTKWD
, ALIAS
, ASSIGN
,
59 CALL
, CASE
, CLOSE
, COMPARE
, _CONST_
,
62 // in der Reihenfolge der Datentyp-Enums!
63 DEFINT
, DEFLNG
, DEFSNG
, DEFDBL
, DEFCUR
, DEFDATE
, DEFSTR
, DEFOBJ
,
64 DEFERR
, DEFBOOL
, DEFVAR
,
65 // in der Reihenfolge der Datentyp-Enums!
68 TLONG
, TSINGLE
, TDOUBLE
, TCURRENCY
, TDATE
, TSTRING
, TOBJECT
,
69 _ERROR_
, TBOOLEAN
, TVARIANT
, TBYTE
,
72 EACH
, ELSE
, ELSEIF
, END
, ERASE
, EXIT
,
74 GET
, GLOBAL
, GOSUB
, GOTO
,
76 LET
, LINE
, LINEINPUT
, LOCAL
, LOOP
, LPRINT
, LSET
,
78 ON
, OPEN
, OPTION
, ATTRIBUTE
, IMPLEMENTS
,
79 PRINT
, PRIVATE
, PROPERTY
, PUBLIC
,
80 REDIM
, REM
, RESUME
, RETURN
, RSET
,
81 SELECT
, SET
, SHARED
, STATIC
, STEP
, STOP
, SUB
,
82 TEXT
, THEN
, TO
, TYPE
, ENUM
,
84 WEND
, WHILE
, WITH
, WRITE
,
85 ENDENUM
, ENDIF
, ENDFUNC
, ENDPROPERTY
, ENDSUB
, ENDTYPE
, ENDSELECT
, ENDWITH
,
86 // Ende aller Keywords
92 DIV
, IDIV
, MOD
, PLUS
, MINUS
,
93 EQ
, NE
, LT
, GT
, LE
, GE
,
94 NOT
, AND
, OR
, XOR
, EQV
,
95 IMP
, CAT
, LIKE
, IS
, TYPEOF
,
98 NUMBER
=FIRSTEXTRA
, FIXSTRING
, SYMBOL
, _CDECL_
, BYVAL
, BYREF
,
99 OUTPUT
, RANDOM
, APPEND
, BINARY
, ACCESS
,
100 LOCK
, READ
, PRESERVE
, BASE
, ANY
, LIB
, _OPTIONAL_
,
101 EXPLICIT
, COMPATIBLE
, CLASSMODULE
, PARAMARRAY
,
103 // Ab hier kommen JavaScript-Tokens (gleiches enum, damit gleicher Typ)
105 JS_BREAK
=FIRSTJAVA
, JS_CONTINUE
, JS_FOR
, JS_FUNCTION
, JS_IF
, JS_NEW
,
106 JS_RETURN
, JS_THIS
, JS_VAR
, JS_WHILE
, JS_WITH
,
108 // JavaScript-Operatoren
109 // _ASS_ = Assignment
110 JS_COMMA
, JS_ASSIGNMENT
, JS_ASS_PLUS
, JS_ASS_MINUS
, JS_ASS_MUL
,
111 JS_ASS_DIV
, JS_ASS_MOD
, JS_ASS_LSHIFT
, JS_ASS_RSHIFT
, JS_ASS_RSHIFT_Z
,
112 JS_ASS_AND
, JS_ASS_XOR
, JS_ASS_OR
,
113 JS_COND_QUEST
, JS_COND_SEL
, JS_LOG_OR
, JS_LOG_AND
, JS_BIT_OR
,
114 JS_BIT_XOR
, JS_BIT_AND
, JS_EQ
, JS_NE
, JS_LT
, JS_LE
,
115 JS_GT
, JS_GE
, JS_LSHIFT
, JS_RSHIFT
, JS_RSHIFT_Z
,
116 JS_PLUS
, JS_MINUS
, JS_MUL
, JS_DIV
, JS_MOD
, JS_LOG_NOT
, JS_BIT_NOT
,
117 JS_INC
, JS_DEC
, JS_LPAREN
, JS_RPAREN
, JS_LINDEX
, JS_RINDEX
121 #ifdef SbiTokenSHAREDTMPUNDEF
123 #undef SbiTokenSHAREDTMPUNDEF
126 class SbiTokenizer
: public SbiScanner
{
128 SbiToken eCurTok
; // aktuelles Token
129 SbiToken ePush
; // Pushback-Token
130 USHORT nPLine
, nPCol1
, nPCol2
; // Pushback-Location
131 BOOL bEof
; // TRUE bei Dateiende
132 BOOL bEos
; // TRUE bei Statement-Ende
133 BOOL bKeywords
; // TRUE, falls Keywords geparst werden
134 BOOL bAs
; // letztes Keyword war AS
135 BOOL bErrorIsSymbol
; // Handle Error token as Symbol, not keyword
137 SbiTokenizer( const ::rtl::OUString
&, StarBASIC
* = NULL
);
140 inline BOOL
IsEof() { return bEof
; }
141 inline BOOL
IsEos() { return bEos
; }
143 void Push( SbiToken
); // Pushback eines Tokens
144 const String
& Symbol( SbiToken
);// Rueckumwandlung
146 SbiToken
Peek(); // das naechste Token lesen
147 SbiToken
Next(); // Ein Token lesen
148 BOOL
MayBeLabel( BOOL
= FALSE
); // Kann es ein Label sein?
150 void Hilite( SbTextPortions
& ); // Syntax-Highlighting
152 void Error( SbError c
) { GenError( c
); }
153 void Error( SbError
, SbiToken
);
154 void Error( SbError
, const char* );
155 void Error( SbError
, String
);
157 void Keywords( BOOL b
) { bKeywords
= b
; }
159 static BOOL
IsEoln( SbiToken t
)
160 { return BOOL( t
== EOS
|| t
== EOLN
|| t
== REM
); }
161 static BOOL
IsKwd( SbiToken t
)
162 { return BOOL( t
>= FIRSTKWD
&& t
<= LASTKWD
); }
163 static BOOL
IsExtra( SbiToken t
)
164 { return BOOL( t
>= FIRSTEXTRA
); }
166 // process somthing like dim Name as String
167 virtual BOOL
IsSymbol( SbiToken
)