1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
5 * Copyright (C) 2007 Apple Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
29 #include <wtf/Vector.h>
30 #include "SourceRange.h"
37 class Lexer : Noncopyable {
39 void setCode(int startingLineNumber, PassRefPtr<SourceProvider> source);
40 int lex(void* lvalp, void* llocp);
42 int lineNo() const { return yylineno; }
44 bool prevTerminator() const { return m_terminator; }
50 InIdentifierOrKeyword,
52 InIdentifierStartUnicodeEscapeStart,
53 InIdentifierStartUnicodeEscape,
54 InIdentifierPartUnicodeEscapeStart,
55 InIdentifierPartUnicodeEscape,
79 const UString& pattern() const { return m_pattern; }
80 const UString& flags() const { return m_flags; }
82 static unsigned char convertHex(int);
83 static unsigned char convertHex(int c1, int c2);
84 static UChar convertUnicode(int c1, int c2, int c3, int c4);
85 static bool isIdentStart(int);
86 static bool isIdentPart(int);
87 static bool isHexDigit(int);
89 bool sawError() const { return m_error; }
92 SourceRange sourceRange(int openBrace, int closeBrace) { return SourceRange(m_source, openBrace + 1, closeBrace); }
95 friend class JSGlobalData;
100 void shift(unsigned int p);
102 int lookupKeyword(const char *);
104 bool isWhiteSpace() const;
105 bool isLineTerminator();
106 static bool isOctalDigit(int);
108 int matchPunctuator(int& charPos, int c1, int c2, int c3, int c4);
109 static unsigned short singleEscape(unsigned short);
110 static unsigned short convertOctal(int c1, int c2, int c3);
114 void record16(UChar);
116 KJS::Identifier* makeIdentifier(const Vector<UChar>& buffer);
117 UString* makeUString(const Vector<UChar>& buffer);
123 Vector<char> m_buffer8;
124 Vector<UChar> m_buffer16;
127 bool m_delimited; // encountered delimiter like "'" and "}" on last run
130 bool m_eatNextIdentifier;
135 unsigned int m_position;
136 RefPtr<SourceProvider> m_source;
138 unsigned int m_length;
142 // current and following unicode characters (int to allow for -1 for end-of-file marker)
153 Vector<UString*> m_strings;
154 Vector<KJS::Identifier*> m_identifiers;
156 JSGlobalData* m_globalData;
161 const HashTable m_mainTable;