• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kjs
 

kjs

  • kjs
lexer.h
1 // -*- c-basic-offset: 2 -*-
2 /*
3  * This file is part of the KDE libraries
4  * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
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 Street, 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 
29 namespace 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 UChar *c, unsigned int len);
42  int lex();
43 
44  int lineNo() const { return yylineno + 1; }
45 
46  bool prevTerminator() const { return terminator; }
47 
48  enum State { Start,
49  IdentifierOrKeyword,
50  Identifier,
51  InIdentifierOrKeyword,
52  InIdentifier,
53  InIdentifierUnicodeEscapeStart,
54  InIdentifierUnicodeEscape,
55  InSingleLineComment,
56  InMultiLineComment,
57  InNum,
58  InNum0,
59  InHex,
60  InOctal,
61  InDecimal,
62  InExponentIndicator,
63  InExponent,
64  Hex,
65  Octal,
66  Number,
67  String,
68  Eof,
69  InString,
70  InEscapeSequence,
71  InHexEscape,
72  InUnicodeEscape,
73  Other,
74  Bad };
75 
76  bool scanRegExp();
77  UString pattern, flags;
78  bool hadError() const { return foundBad; }
79 
80  static bool isWhiteSpace(unsigned short c);
81  static bool isIdentLetter(unsigned short c);
82  static bool isDecimalDigit(unsigned short c);
83  static bool isHexDigit(unsigned short c);
84  static bool isOctalDigit(unsigned short c);
85 
86  private:
87  int yylineno;
88  bool done;
89  char *buffer8;
90  UChar *buffer16;
91  unsigned int size8, size16;
92  unsigned int pos8, pos16;
93  bool terminator;
94  bool restrKeyword;
95  // encountered delimiter like "'" and "}" on last run
96  bool delimited;
97  bool skipLF;
98  bool skipCR;
99  bool convertNextIdentifier;
100  int stackToken;
101  int lastToken;
102  bool foundBad;
103 
104  State state;
105  void setDone(State s);
106  unsigned int pos;
107  void shift(unsigned int p);
108  void nextLine();
109  int lookupKeyword(const char *);
110 
111  int matchPunctuator(unsigned short c1, unsigned short c2,
112  unsigned short c3, unsigned short c4);
113  unsigned short singleEscape(unsigned short c) const;
114  unsigned short convertOctal(unsigned short c1, unsigned short c2,
115  unsigned short c3) const;
116  public:
117  static unsigned char convertHex(unsigned short c1);
118  static unsigned char convertHex(unsigned short c1, unsigned short c2);
119  static UChar convertUnicode(unsigned short c1, unsigned short c2,
120  unsigned short c3, unsigned short c4);
121 
122 #ifdef KJS_DEBUG_MEM
126  static void globalClear();
127 #endif
128 
129  void doneParsing();
130 
131  private:
132 
133  void record8(unsigned short c);
134  void record16(int c);
135  void record16(UChar c);
136 
137  KJS::Identifier *makeIdentifier(UChar *buffer, unsigned int pos);
138  UString *makeUString(UChar *buffer, unsigned int pos);
139 
140  const UChar *code;
141  unsigned int length;
142  int yycolumn;
143 #ifndef KJS_PURE_ECMA
144  int bol; // begin of line
145 #endif
146 
147  // current and following unicode characters (int to allow for -1 for end-of-file marker)
148  int current, next1, next2, next3;
149 
150  UString **strings;
151  unsigned int numStrings;
152  unsigned int stringsCapacity;
153 
154  KJS::Identifier **identifiers;
155  unsigned int numIdentifiers;
156  unsigned int identifiersCapacity;
157 
158  // for future extensions
159  class LexerPrivate;
160  LexerPrivate *priv;
161  };
162 
163 } // namespace
164 
165 #endif
KJS::Identifier
Represents an Identifier for a Javascript object.
Definition: identifier.h:32

kjs

Skip menu "kjs"
  • Main Page
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

kjs

Skip menu "kjs"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kjs by doxygen 1.9.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |