lexer.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef _KJSLEXER_H_
00025 #define _KJSLEXER_H_
00026
00027 #include "ustring.h"
00028
00029 namespace KJS {
00030
00031 class RegExp;
00032
00033 class Lexer {
00034 public:
00035 Lexer();
00036 ~Lexer();
00037 static Lexer *curr();
00038
00039 void setCode(const UChar *c, unsigned int len);
00040 int lex();
00041
00042 int lineNo() const { return yylineno + 1; }
00043
00044 bool prevTerminator() const { return terminator; }
00045
00046 enum State { Start,
00047 Identifier,
00048 InIdentifier,
00049 InSingleLineComment,
00050 InMultiLineComment,
00051 InNum,
00052 InNum0,
00053 InHex,
00054 InOctal,
00055 InDecimal,
00056 InExponentIndicator,
00057 InExponent,
00058 Hex,
00059 Octal,
00060 Number,
00061 String,
00062 Eof,
00063 InString,
00064 InEscapeSequence,
00065 InHexEscape,
00066 InUnicodeEscape,
00067 Other,
00068 Bad };
00069
00070 bool scanRegExp();
00071 UString pattern, flags;
00072
00073 private:
00074 int yylineno;
00075 bool done;
00076 char *buffer8;
00077 UChar *buffer16;
00078 unsigned int size8, size16;
00079 unsigned int pos8, pos16;
00080 bool terminator;
00081 bool restrKeyword;
00082
00083 bool delimited;
00084 bool skipLF;
00085 bool skipCR;
00086 bool eatNextIdentifier;
00087 int stackToken;
00088 int lastToken;
00089
00090 State state;
00091 void setDone(State s);
00092 unsigned int pos;
00093 void shift(unsigned int p);
00094 void nextLine();
00095 int lookupKeyword(const char *);
00096
00097 bool isWhiteSpace() const;
00098 bool isHexDigit(unsigned short c) const;
00099 bool isOctalDigit(unsigned short c) const;
00100
00101 int matchPunctuator(unsigned short c1, unsigned short c2,
00102 unsigned short c3, unsigned short c4);
00103 unsigned short singleEscape(unsigned short c) const;
00104 unsigned short convertOctal(unsigned short c1, unsigned short c2,
00105 unsigned short c3) const;
00106 public:
00107 static unsigned char convertHex(unsigned short c1);
00108 static unsigned char convertHex(unsigned short c1, unsigned short c2);
00109 static UChar convertUnicode(unsigned short c1, unsigned short c2,
00110 unsigned short c3, unsigned short c4);
00111 static bool isIdentLetter(unsigned short c);
00112 static bool isDecimalDigit(unsigned short c);
00113
00114 #ifdef KJS_DEBUG_MEM
00115
00118 static void globalClear();
00119 #endif
00120 private:
00121
00122 void record8(unsigned short c);
00123 void record16(UChar c);
00124
00125 const UChar *code;
00126 unsigned int length;
00127 int yycolumn;
00128 #ifndef KJS_PURE_ECMA
00129 int bol;
00130 #endif
00131
00132
00133 unsigned short current, next1, next2, next3;
00134
00135
00136 class LexerPrivate;
00137 LexerPrivate *priv;
00138 };
00139
00140 }
00141
00142 #endif
This file is part of the documentation for kdelibs Version 3.1.4.