source: webkit/trunk/JavaScriptCore/kjs/lexer.h@ 6

Last change on this file since 6 was 6, checked in by kocienda, 24 years ago

Imported sources from kde-2.2 distribution

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