| # kjs Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# lexer.h

    00001 // -*- c-basic-offset: 2 -*-
    00002 /*
    00003  *  This file is part of the KDE libraries
    00004  *  Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
    00005  *
    00006  *  This library is free software; you can redistribute it and/or
    00007  *  modify it under the terms of the GNU Lesser General Public
    00008  *  License as published by the Free Software Foundation; either
    00009  *  version 2 of the License, or (at your option) any later version.
    00010  *
    00011  *  This library is distributed in the hope that it will be useful,
    00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014  *  Lesser General Public License for more details.
    00015  *
    00016  *  You should have received a copy of the GNU Lesser General Public License
    00017  *  along with this library; see the file COPYING.LIB.  If not, write to
    00018  *  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00019  *  Boston, MA 02111-1307, USA.
    00020  *
    00021  *  $Id: lexer.h,v 1.22.2.1 2003/05/17 11:19:24 mueller Exp $
    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     // encountered delimiter like "'" and "}" on last run
    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;     // begin of line
    00130 #endif
    00131
    00132     // current and following unicode characters
    00133     unsigned short current, next1, next2, next3;
    00134
    00135     // for future extensions
    00136     class LexerPrivate;
    00137     LexerPrivate *priv;
    00138   };
    00139
    00140 } // namespace
    00141
    00142 #endif

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:08:28 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001