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