Initial revision
[swftools.git] / pdf2swf / xpdf / Lexer.h
1 //========================================================================
2 //
3 // Lexer.h
4 //
5 // Copyright 1996 Derek B. Noonburg
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 #define tokBufSize 128          // size of token buffer
20
21 //------------------------------------------------------------------------
22 // Lexer
23 //------------------------------------------------------------------------
24
25 class Lexer {
26 public:
27
28   // Construct a lexer for a single stream.  Deletes the stream when
29   // lexer is deleted.
30   Lexer(Stream *str);
31
32   // Construct a lexer for a stream or array of streams (assumes obj
33   // is either a stream or array of streams).
34   Lexer(Object *obj);
35
36   // Destructor.
37   ~Lexer();
38
39   // Get the next object from the input stream.
40   Object *getObj(Object *obj);
41
42   // Skip to the beginning of the next line in the input stream.
43   void skipToNextLine();
44
45   // Skip over one character.
46   void skipChar() { getChar(); }
47
48   // Get stream.
49   Stream *getStream()
50     { return curStr.isNone() ? (Stream *)NULL : curStr.getStream(); }
51
52   // Get current position in file.
53   int getPos()
54     { return curStr.isNone() ? -1 : curStr.streamGetPos(); }
55
56   // Set position in file.
57   void setPos(int pos)
58     { if (!curStr.isNone()) curStr.streamSetPos(pos); }
59
60 private:
61
62   int getChar();
63   int lookChar();
64
65   Array *streams;               // array of input streams
66   int strPtr;                   // index of current stream
67   Object curStr;                // current stream
68   GBool freeArray;              // should lexer free the streams array?
69   char tokBuf[tokBufSize];      // temporary token buffer
70 };
71
72 #endif