]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | //======================================================================== |
2 | // | |
3 | // Lexer.h | |
4 | // | |
5 | // Copyright 1996-2003 Glyph & Cog, LLC | |
6 | // | |
7 | //======================================================================== | |
8 | ||
9 | #ifndef LEXER_H | |
10 | #define LEXER_H | |
11 | ||
12 | #include <config.h> | |
13 | ||
14 | #ifdef USE_GCC_PRAGMAS | |
15 | #pragma interface | |
16 | #endif | |
17 | ||
18 | #include "Object.h" | |
19 | #include "Stream.h" | |
20 | ||
21 | class XRef; | |
22 | ||
23 | #define tokBufSize 128 // size of token buffer | |
24 | ||
25 | //------------------------------------------------------------------------ | |
26 | // Lexer | |
27 | //------------------------------------------------------------------------ | |
28 | ||
29 | class Lexer { | |
30 | public: | |
31 | ||
32 | // Construct a lexer for a single stream. Deletes the stream when | |
33 | // lexer is deleted. | |
34 | Lexer(XRef *xref, Stream *str); | |
35 | ||
36 | // Construct a lexer for a stream or array of streams (assumes obj | |
37 | // is either a stream or array of streams). | |
38 | Lexer(XRef *xref, Object *obj); | |
39 | ||
40 | // Destructor. | |
41 | ~Lexer(); | |
42 | ||
43 | // Get the next object from the input stream. | |
44 | Object *getObj(Object *obj); | |
45 | ||
46 | // Skip to the beginning of the next line in the input stream. | |
47 | void skipToNextLine(); | |
48 | ||
49 | // Skip over one character. | |
50 | void skipChar() { getChar(); } | |
51 | ||
52 | // Get stream. | |
53 | Stream *getStream() | |
54 | { return curStr.isNone() ? (Stream *)NULL : curStr.getStream(); } | |
55 | ||
56 | // Get current position in file. This is only used for error | |
57 | // messages, so it returns an int instead of a Guint. | |
58 | int getPos() | |
59 | { return curStr.isNone() ? -1 : (int)curStr.streamGetPos(); } | |
60 | ||
61 | // Set position in file. | |
62 | void setPos(Guint pos, int dir = 0) | |
63 | { if (!curStr.isNone()) curStr.streamSetPos(pos, dir); } | |
64 | ||
65 | // Returns true if <c> is a whitespace character. | |
66 | static GBool isSpace(int c); | |
67 | ||
68 | private: | |
69 | ||
70 | int getChar(); | |
71 | int lookChar(); | |
72 | ||
73 | Array *streams; // array of input streams | |
74 | int strPtr; // index of current stream | |
75 | Object curStr; // current stream | |
76 | GBool freeArray; // should lexer free the streams array? | |
77 | char tokBuf[tokBufSize]; // temporary token buffer | |
78 | }; | |
79 | ||
80 | #endif |