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

Last change on this file since 10412 was 9768, checked in by ggaren, 20 years ago

-rolled in patches for http://bugzilla.opendarwin.org/show_bug.cgi?id=3945
[PATCH] Safe merges of comments and other trivialities from KDE's kjs

-patch by Martijn Klingens <[email protected]>

  • kjs/array_instance.h:
  • kjs/array_object.cpp:
  • kjs/array_object.h:
  • kjs/bool_object.cpp:
  • kjs/bool_object.h:
  • kjs/collector.cpp:
  • kjs/collector.h:
  • kjs/completion.h:
  • kjs/context.h:
  • kjs/date_object.cpp:
  • kjs/date_object.h:
  • kjs/debugger.cpp:
  • kjs/debugger.h:
  • kjs/dtoa.h:
  • kjs/error_object.cpp:
  • kjs/error_object.h:
  • kjs/function.cpp:
  • kjs/function.h:
  • kjs/function_object.cpp:
  • kjs/function_object.h:
  • kjs/grammar.y:
  • kjs/identifier.cpp:
  • kjs/identifier.h:
  • kjs/internal.cpp:
  • kjs/internal.h:
  • kjs/interpreter.cpp:
  • kjs/interpreter.h:
  • kjs/interpreter_map.cpp:
  • kjs/interpreter_map.h:
  • kjs/lexer.cpp:
  • kjs/lexer.h:
  • kjs/list.cpp:
  • kjs/list.h:
  • kjs/lookup.cpp:
  • kjs/lookup.h:
  • kjs/math_object.cpp:
  • kjs/math_object.h:
  • kjs/nodes.cpp:
  • kjs/nodes.h:
  • kjs/nodes2string.cpp:
  • kjs/number_object.cpp:
  • kjs/number_object.h:
  • kjs/object.cpp:
  • kjs/object.h:
  • kjs/object_object.cpp:
  • kjs/object_object.h:
  • kjs/operations.cpp:
  • kjs/operations.h:
  • kjs/property_map.cpp:
  • kjs/property_map.h:
  • kjs/reference.cpp:
  • kjs/reference.h:
  • kjs/reference_list.cpp:
  • kjs/reference_list.h:
  • kjs/regexp.cpp:
  • kjs/regexp.h:
  • kjs/regexp_object.cpp:
  • kjs/regexp_object.h:
  • kjs/scope_chain.cpp:
  • kjs/scope_chain.h:
  • kjs/simple_number.h:
  • kjs/string_object.cpp:
  • kjs/string_object.h:
  • kjs/testkjs.cpp:
  • kjs/types.h:
  • kjs/ustring.cpp:
  • kjs/ustring.h:
  • kjs/value.cpp:
  • kjs/value.h:
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 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 Identifier,
51 InIdentifier,
52 InSingleLineComment,
53 InMultiLineComment,
54 InNum,
55 InNum0,
56 InHex,
57 InOctal,
58 InDecimal,
59 InExponentIndicator,
60 InExponent,
61 Hex,
62 Octal,
63 Number,
64 String,
65 Eof,
66 InString,
67 InEscapeSequence,
68 InHexEscape,
69 InUnicodeEscape,
70 Other,
71 Bad };
72
73 bool scanRegExp();
74 UString pattern, flags;
75
76 private:
77 int yylineno;
78 UString m_sourceURL;
79 bool done;
80 char *buffer8;
81 UChar *buffer16;
82 unsigned int size8, size16;
83 unsigned int pos8, pos16;
84 bool terminator;
85 bool restrKeyword;
86 // encountered delimiter like "'" and "}" on last run
87 bool delimited;
88 bool skipLF;
89 bool skipCR;
90 bool eatNextIdentifier;
91 int stackToken;
92 int lastToken;
93
94 State state;
95 void setDone(State s);
96 unsigned int pos;
97 void shift(unsigned int p);
98 void nextLine();
99 int lookupKeyword(const char *);
100
101 bool isWhiteSpace() const;
102 bool isLineTerminator();
103 bool isOctalDigit(unsigned short c) const;
104
105 int matchPunctuator(unsigned short c1, unsigned short c2,
106 unsigned short c3, unsigned short c4);
107 unsigned short singleEscape(unsigned short c) const;
108 unsigned short convertOctal(unsigned short c1, unsigned short c2,
109 unsigned short c3) const;
110 public:
111 static unsigned char convertHex(unsigned short c1);
112 static unsigned char convertHex(unsigned short c1, unsigned short c2);
113 static UChar convertUnicode(unsigned short c1, unsigned short c2,
114 unsigned short c3, unsigned short c4);
115 static bool isIdentLetter(unsigned short c);
116 static bool isDecimalDigit(unsigned short c);
117 static bool isHexDigit(unsigned short c);
118
119#ifdef KJS_DEBUG_MEM
120 /**
121 * Clear statically allocated resources
122 */
123 static void globalClear();
124#endif
125
126 bool sawError() const { return error; }
127 void doneParsing();
128
129 private:
130
131 void record8(unsigned short c);
132 void record16(UChar c);
133
134 KJS::Identifier *makeIdentifier(UChar *buffer, unsigned int pos);
135 UString *makeUString(UChar *buffer, unsigned int pos);
136
137 const UChar *code;
138 unsigned int length;
139 int yycolumn;
140#ifndef KJS_PURE_ECMA
141 int bol; // begin of line
142#endif
143 bool error;
144
145 // current and following unicode characters
146 unsigned short current, next1, next2, next3;
147
148 UString **strings;
149 unsigned int numStrings;
150 unsigned int stringsCapacity;
151
152 KJS::Identifier **identifiers;
153 unsigned int numIdentifiers;
154 unsigned int identifiersCapacity;
155
156 // for future extensions
157 class LexerPrivate;
158 LexerPrivate *priv;
159 };
160
161} // namespace
162
163#endif
Note: See TracBrowser for help on using the repository browser.