1 | // -*- c-basic-offset: 2 -*-
|
---|
2 | /*
|
---|
3 | * This file is part of the KDE libraries
|
---|
4 | * Copyright (C) 1999-2000 Harri Porten ([email protected])
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Library General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Library General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Library General Public License
|
---|
17 | * along with this library; see the file COPYING.LIB. If not, write to
|
---|
18 | * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
---|
19 | * Boston, MA 02111-1307, USA.
|
---|
20 | *
|
---|
21 | */
|
---|
22 |
|
---|
23 | #ifndef _KJSLEXER_H_
|
---|
24 | #define _KJSLEXER_H_
|
---|
25 |
|
---|
26 | #include "ustring.h"
|
---|
27 |
|
---|
28 | namespace KJS {
|
---|
29 |
|
---|
30 | class RegExp;
|
---|
31 |
|
---|
32 | class Lexer {
|
---|
33 | public:
|
---|
34 | Lexer();
|
---|
35 | ~Lexer();
|
---|
36 | static Lexer *curr();
|
---|
37 |
|
---|
38 | void setCode(const UChar *c, unsigned int len);
|
---|
39 | int lex();
|
---|
40 |
|
---|
41 | int lineNo() const { return yylineno + 1; }
|
---|
42 |
|
---|
43 | bool prevTerminator() const { return terminator; }
|
---|
44 |
|
---|
45 | enum State { Start,
|
---|
46 | Identifier,
|
---|
47 | InIdentifier,
|
---|
48 | InSingleLineComment,
|
---|
49 | InMultiLineComment,
|
---|
50 | InNum,
|
---|
51 | InNum0,
|
---|
52 | InHex,
|
---|
53 | InOctal,
|
---|
54 | InDecimal,
|
---|
55 | InExponentIndicator,
|
---|
56 | InExponent,
|
---|
57 | Hex,
|
---|
58 | Octal,
|
---|
59 | Number,
|
---|
60 | String,
|
---|
61 | Eof,
|
---|
62 | InString,
|
---|
63 | InEscapeSequence,
|
---|
64 | InHexEscape,
|
---|
65 | InUnicodeEscape,
|
---|
66 | Other,
|
---|
67 | Bad };
|
---|
68 |
|
---|
69 | bool scanRegExp();
|
---|
70 | UString pattern, flags;
|
---|
71 |
|
---|
72 | private:
|
---|
73 | int yylineno;
|
---|
74 | bool done;
|
---|
75 | char *buffer8;
|
---|
76 | UChar *buffer16;
|
---|
77 | unsigned int size8, size16;
|
---|
78 | unsigned int pos8, pos16;
|
---|
79 | bool terminator;
|
---|
80 | bool restrKeyword;
|
---|
81 | // encountered delimiter like "'" and "}" on last run
|
---|
82 | bool delimited;
|
---|
83 | bool skipLF;
|
---|
84 | bool skipCR;
|
---|
85 | bool eatNextIdentifier;
|
---|
86 | int stackToken;
|
---|
87 | int lastToken;
|
---|
88 |
|
---|
89 | State state;
|
---|
90 | void setDone(State s);
|
---|
91 | unsigned int pos;
|
---|
92 | void shift(unsigned int p);
|
---|
93 | void nextLine();
|
---|
94 | int lookupKeyword(const char *);
|
---|
95 |
|
---|
96 | bool isWhiteSpace() const;
|
---|
97 | bool isLineTerminator();
|
---|
98 | bool isHexDigit(unsigned short c) const;
|
---|
99 | bool isOctalDigit(unsigned short c) const;
|
---|
100 |
|
---|
101 | int matchPunctuator(unsigned short c1, unsigned short c2,
|
---|
102 | unsigned short c3, unsigned short c4);
|
---|
103 | unsigned short singleEscape(unsigned short c) const;
|
---|
104 | unsigned short convertOctal(unsigned short c1, unsigned short c2,
|
---|
105 | unsigned short c3) const;
|
---|
106 | public:
|
---|
107 | static unsigned char convertHex(unsigned short c1);
|
---|
108 | static unsigned char convertHex(unsigned short c1, unsigned short c2);
|
---|
109 | static UChar convertUnicode(unsigned short c1, unsigned short c2,
|
---|
110 | unsigned short c3, unsigned short c4);
|
---|
111 | static bool isIdentLetter(unsigned short c);
|
---|
112 | static bool isDecimalDigit(unsigned short c);
|
---|
113 |
|
---|
114 | #ifdef KJS_DEBUG_MEM
|
---|
115 | /**
|
---|
116 | * Clear statically allocated resources
|
---|
117 | */
|
---|
118 | static void globalClear();
|
---|
119 | #endif
|
---|
120 | private:
|
---|
121 |
|
---|
122 | void record8(unsigned short c);
|
---|
123 | void record16(UChar c);
|
---|
124 |
|
---|
125 | const UChar *code;
|
---|
126 | unsigned int length;
|
---|
127 | int yycolumn;
|
---|
128 | #ifndef KJS_PURE_ECMA
|
---|
129 | int bol; // begin of line
|
---|
130 | #endif
|
---|
131 |
|
---|
132 | // current and following unicode characters
|
---|
133 | unsigned short current, next1, next2, next3;
|
---|
134 |
|
---|
135 | // for future extensions
|
---|
136 | class LexerPrivate;
|
---|
137 | LexerPrivate *priv;
|
---|
138 | };
|
---|
139 |
|
---|
140 | }; // namespace
|
---|
141 |
|
---|
142 | #endif
|
---|