beta-0.89.2
[luatex.git] / source / libs / poppler / poppler-src / poppler / Lexer.h
blob02b6cdc69234cad235893fd41a8e36c1e5d8ea62
1 //========================================================================
2 //
3 // Lexer.h
4 //
5 // Copyright 1996-2003 Glyph & Cog, LLC
6 //
7 //========================================================================
9 //========================================================================
11 // Modified under the Poppler project - http://poppler.freedesktop.org
13 // All changes made under the Poppler project to this file are licensed
14 // under GPL version 2 or later
16 // Copyright (C) 2006, 2007, 2010, 2013 Albert Astals Cid <aacid@kde.org>
17 // Copyright (C) 2006 Krzysztof Kowalczyk <kkowalczyk@gmail.com>
18 // Copyright (C) 2013 Adrian Johnson <ajohnson@redneon.com>
19 // Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
21 // To see a description of the changes please see the Changelog file that
22 // came with your tarball or type make ChangeLog if you are building from git
24 //========================================================================
26 #ifndef LEXER_H
27 #define LEXER_H
29 #ifdef USE_GCC_PRAGMAS
30 #pragma interface
31 #endif
33 #include "Object.h"
34 #include "Stream.h"
36 class XRef;
38 #define tokBufSize 128 // size of token buffer
40 //------------------------------------------------------------------------
41 // Lexer
42 //------------------------------------------------------------------------
44 class Lexer {
45 public:
47 // Construct a lexer for a single stream. Deletes the stream when
48 // lexer is deleted.
49 Lexer(XRef *xrefA, Stream *str);
51 // Construct a lexer for a stream or array of streams (assumes obj
52 // is either a stream or array of streams).
53 Lexer(XRef *xrefA, Object *obj);
55 // Destructor.
56 ~Lexer();
58 // Get the next object from the input stream.
59 Object *getObj(Object *obj, int objNum = -1);
60 Object *getObj(Object *obj, const char *cmdA, int objNum);
62 // Skip to the beginning of the next line in the input stream.
63 void skipToNextLine();
65 // Skip over one character.
66 void skipChar() { getChar(); }
68 // Get stream.
69 Stream *getStream()
70 { return curStr.isStream() ? curStr.getStream() : (Stream *)NULL; }
72 // Get current position in file. This is only used for error
73 // messages.
74 Goffset getPos()
75 { return curStr.isStream() ? curStr.streamGetPos() : -1; }
77 // Set position in file.
78 void setPos(Goffset pos, int dir = 0)
79 { if (curStr.isStream()) curStr.streamSetPos(pos, dir); }
81 // Returns true if <c> is a whitespace character.
82 static GBool isSpace(int c);
85 // often (e.g. ~30% on PDF Refernce 1.6 pdf file from Adobe site) getChar
86 // is called right after lookChar. In order to avoid expensive re-doing
87 // getChar() of underlying stream, we cache the last value found by
88 // lookChar() in lookCharLastValueCached. A special value
89 // LOOK_VALUE_NOT_CACHED that should never be part of stream indicates
90 // that no value was cached
91 static const int LOOK_VALUE_NOT_CACHED = -3;
92 int lookCharLastValueCached;
94 private:
96 int getChar(GBool comesFromLook = gFalse);
97 int lookChar();
99 Array *streams; // array of input streams
100 int strPtr; // index of current stream
101 Object curStr; // current stream
102 GBool freeArray; // should lexer free the streams array?
103 char tokBuf[tokBufSize]; // temporary token buffer
105 XRef *xref;
108 #endif