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

Last change on this file since 11879 was 11879, checked in by ggaren, 19 years ago

Patch by [email protected], reviewed by darin, tweaked by me.

  • kjs/function_object.cpp: (FunctionObjectImp::construct):
  • kjs/lexer.cpp: (Lexer::shift): (Lexer::lex): (Lexer::isWhiteSpace): (Lexer::isLineTerminator): (Lexer::isIdentStart): (Lexer::isIdentPart): (isDecimalDigit): (Lexer::scanRegExp):
  • kjs/lexer.h: (KJS::Lexer::):
  • tests/mozilla/expected.html: Updated test results.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.5 KB
Line 
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., 51 Franklin Steet, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef _KJSLEXER_H_
24#define _KJSLEXER_H_
25
26#include "ustring.h"
27
28
29namespace KJS {
30
31 class Identifier;
32
33 class RegExp;
34
35 class Lexer {
36 public:
37 Lexer();
38 ~Lexer();
39 static Lexer *curr();
40
41 void setCode(const UString &sourceURL, int startingLineNumber, const UChar *c, unsigned int len);
42 int lex();
43
44 int lineNo() const { return yylineno; }
45 UString sourceURL() const { return m_sourceURL; }
46
47 bool prevTerminator() const { return terminator; }
48
49 enum State { Start,
50 IdentifierOrKeyword,
51 Identifier,
52 InIdentifierOrKeyword,
53 InIdentifier,
54 InIdentifierUnicodeEscapeStart,
55 InIdentifierUnicodeEscape,
56 InSingleLineComment,
57 InMultiLineComment,
58 InNum,
59 InNum0,
60 InHex,
61 InOctal,
62 InDecimal,
63 InExponentIndicator,
64 InExponent,
65 Hex,
66 Octal,
67 Number,
68 String,
69 Eof,
70 InString,
71 InEscapeSequence,
72 InHexEscape,
73 InUnicodeEscape,
74 Other,
75 Bad };
76
77 bool scanRegExp();
78 UString pattern, flags;
79
80 private:
81 int yylineno;
82 UString m_sourceURL;
83 bool done;
84 char *buffer8;
85 UChar *buffer16;
86 unsigned int size8, size16;
87 unsigned int pos8, pos16;
88 bool terminator;
89 bool restrKeyword;
90 // encountered delimiter like "'" and "}" on last run
91 bool delimited;
92 bool skipLF;
93 bool skipCR;
94 bool eatNextIdentifier;
95 int stackToken;
96 int lastToken;
97
98 State state;
99 void setDone(State s);
100 unsigned int pos;
101 void shift(unsigned int p);
102 void nextLine();
103 int lookupKeyword(const char *);
104
105 bool isWhiteSpace() const;
106 bool isLineTerminator();
107 bool isOctalDigit(unsigned short c) const;
108
109 int matchPunctuator(unsigned short c1, unsigned short c2,
110 unsigned short c3, unsigned short c4);
111 unsigned short singleEscape(unsigned short c) const;
112 unsigned short convertOctal(unsigned short c1, unsigned short c2,
113 unsigned short c3) const;
114 public:
115 static unsigned char convertHex(unsigned short c1);
116 static unsigned char convertHex(unsigned short c1, unsigned short c2);
117 static UChar convertUnicode(unsigned short c1, unsigned short c2,
118 unsigned short c3, unsigned short c4);
119 static bool isIdentStart(unsigned short c);
120 static bool isIdentPart(unsigned short c);
121 static bool isHexDigit(unsigned short c);
122
123#ifdef KJS_DEBUG_MEM
124 /**
125 * Clear statically allocated resources
126 */
127 static void globalClear();
128#endif
129
130 bool sawError() const { return error; }
131 void doneParsing();
132
133 private:
134
135 void record8(unsigned short c);
136 void record16(UChar c);
137
138 KJS::Identifier *makeIdentifier(UChar *buffer, unsigned int pos);
139 UString *makeUString(UChar *buffer, unsigned int pos);
140
141 const UChar *code;
142 unsigned int length;
143 int yycolumn;
144#ifndef KJS_PURE_ECMA
145 int bol; // begin of line
146#endif
147 bool error;
148
149 // current and following unicode characters
150 unsigned short current, next1, next2, next3;
151
152 UString **strings;
153 unsigned int numStrings;
154 unsigned int stringsCapacity;
155
156 KJS::Identifier **identifiers;
157 unsigned int numIdentifiers;
158 unsigned int identifiersCapacity;
159
160 // for future extensions
161 class LexerPrivate;
162 LexerPrivate *priv;
163 };
164
165} // namespace
166
167#endif
Note: See TracBrowser for help on using the repository browser.