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.
28 #include <wtf/Vector.h>
35 class Lexer
: Noncopyable
{
37 void setCode(int startingLineNumber
, const UChar
*c
, unsigned int len
);
40 int lineNo() const { return yylineno
; }
42 bool prevTerminator() const { return terminator
; }
47 InIdentifierOrKeyword
,
49 InIdentifierStartUnicodeEscapeStart
,
50 InIdentifierStartUnicodeEscape
,
51 InIdentifierPartUnicodeEscapeStart
,
52 InIdentifierPartUnicodeEscape
,
75 const UString
& pattern() const { return m_pattern
; }
76 const UString
& flags() const { return m_flags
; }
78 static unsigned char convertHex(int);
79 static unsigned char convertHex(int c1
, int c2
);
80 static UChar
convertUnicode(int c1
, int c2
, int c3
, int c4
);
81 static bool isIdentStart(int);
82 static bool isIdentPart(int);
83 static bool isHexDigit(int);
85 bool sawError() const { return error
; }
90 friend Lexer
& lexer();
95 Vector
<char> m_buffer8
;
96 Vector
<UChar
> m_buffer16
;
99 // encountered delimiter like "'" and "}" on last run
103 bool eatNextIdentifier
;
110 void shift(unsigned int p
);
112 int lookupKeyword(const char *);
114 bool isWhiteSpace() const;
115 bool isLineTerminator();
116 static bool isOctalDigit(int);
118 int matchPunctuator(int c1
, int c2
, int c3
, int c4
);
119 static unsigned short singleEscape(unsigned short);
120 static unsigned short convertOctal(int c1
, int c2
, int c3
);
124 void record16(UChar
);
126 KJS::Identifier
* makeIdentifier(const Vector
<UChar
>& buffer
);
127 UString
* makeUString(const Vector
<UChar
>& buffer
);
135 // current and following unicode characters (int to allow for -1 for end-of-file marker)
136 int current
, next1
, next2
, next3
;
138 Vector
<UString
*> m_strings
;
139 Vector
<KJS::Identifier
*> m_identifiers
;
145 Lexer
& lexer(); // Returns the singletone JavaScript lexer.