]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3input.h
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / libantlr3c-3.2 / include / antlr3input.h
1 /** \file
2  * Defines the basic structures used to manipulate character
3  * streams from any input source. The first implementation of
4  * this stream was ASCII 8 bit, but any character size and encoding
5  * can in theory be used, so long as they can return a 32 bit Integer
6  * representation of their characters amd efficiently mark and revert
7  * to specific offsets into their input streams.
8  */
9 #ifndef _ANTLR3_INPUT_H
10 #define _ANTLR3_INPUT_H
11
12 // [The "BSD licence"]
13 // Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC
14 // http://www.temporal-wave.com
15 // http://www.linkedin.com/in/jimidle
16 //
17 // All rights reserved.
18 //
19 // Redistribution and use in source and binary forms, with or without
20 // modification, are permitted provided that the following conditions
21 // are met:
22 // 1. Redistributions of source code must retain the above copyright
23 //    notice, this list of conditions and the following disclaimer.
24 // 2. Redistributions in binary form must reproduce the above copyright
25 //    notice, this list of conditions and the following disclaimer in the
26 //    documentation and/or other materials provided with the distribution.
27 // 3. The name of the author may not be used to endorse or promote products
28 //    derived from this software without specific prior written permission.
29 //
30 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
31 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
33 // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
34 // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35 // NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
39 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40
41 #include    <antlr3defs.h>
42 #include    <antlr3string.h>
43 #include    <antlr3commontoken.h>
44 #include    <antlr3intstream.h>
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 /// Master context structure for an ANTLR3 C runtime based input stream.
51 /// \ingroup apistructures
52 ///
53 typedef struct  ANTLR3_INPUT_STREAM_struct
54 {
55     /** Interfaces that provide streams must all provide
56      *  a generic ANTLR3_INT_STREAM interface and an ANTLR3_INPUT_STREAM
57      *  is no different.
58      */
59     pANTLR3_INT_STREAM  istream;
60
61     /** Whatever super structure is providing the INPUT stream needs a pointer to itself
62      *  so that this can be passed back to it whenever the api functions
63      *  are called back from this interface.
64      */
65     void              * super;
66
67         /// Indicates the size, in 8 bit units, of a single character. Note that
68         /// the C runtime does not deal with surrogates and UTF8 directly as this would be
69         /// slow and complicated. Variable character width inputs are expected to be converted
70         /// into fixed width formats, so that would be a UTF32 format for anything that cannot
71         /// work with a UCS2 encoding, such as UTF-8. Generally you are best
72         /// working internally with 32 bit characters.
73         ///
74         ANTLR3_UINT8    charByteSize;
75
76     /** Pointer the start of the input string, characters may be
77      *  taken as offsets from here and in original input format encoding.
78      */
79     void              * data;
80
81     /** Indicates if the data pointer was allocated by us, and so should be freed
82      *  when the stream dies.
83      */
84     int                 isAllocated;
85
86     /** String factory for this input stream
87      */
88     pANTLR3_STRING_FACTORY  strFactory;
89
90
91     /** Pointer to the next character to be consumed from the input data
92      *  This is cast to point at the encoding of the original file that
93      *  was read by the functions installed as pointer in this input stream
94      *  context instance at file/string/whatever load time.
95      */
96     void              * nextChar;
97
98     /** Number of characters that can be consumed at this point in time.
99      *  Mostly this is just what is left in the pre-read buffer, but if the
100      *  input source is a stream such as a socket or something then we may
101      *  call special read code to wait for more input.
102      */
103     ANTLR3_UINT32       sizeBuf;
104
105     /** The line number we are traversing in the input file. This gets incremented
106      *  by a newline() call in the lexer grammar actions.
107      */
108     ANTLR3_UINT32       line;
109
110     /** Pointer into the input buffer where the current line
111      *  started.
112      */
113     void              * currentLine;
114
115     /** The offset within the current line of the current character
116      */
117     ANTLR3_INT32        charPositionInLine;
118
119     /** Tracks how deep mark() calls are nested
120      */
121     ANTLR3_UINT32       markDepth;
122
123     /** List of mark() points in the input stream
124      */
125     pANTLR3_VECTOR      markers;
126
127     /** File name string, set to pointer to memory if
128      * you set it manually as it will be free()d
129      */
130     pANTLR3_STRING      fileName;
131
132         /** File number, needs to be set manually to some file index of your devising.
133          */
134         ANTLR3_UINT32   fileNo;
135
136     /** Character that automatically causes an internal line count
137      *  increment.
138      */
139     ANTLR3_UCHAR        newlineChar;
140
141     /* API */
142
143
144    /** Pointer to function that closes the input stream
145      */
146     void                (*close)        (struct ANTLR3_INPUT_STREAM_struct * input);
147     void                (*free)         (struct ANTLR3_INPUT_STREAM_struct * input);
148
149     /** Pointer to function that resets the input stream
150      */
151     void                (*reset)        (struct ANTLR3_INPUT_STREAM_struct * input);
152
153         /**
154          * Pinter to function that installs a version of LA that always
155          * returns upper case. Only valid for character streams and creates a case
156          * insensitive lexer if the lexer tokens are described in upper case. The
157          * tokens will preserve case in the token text.
158          */
159         void            (*setUcaseLA)           (pANTLR3_INPUT_STREAM input, ANTLR3_BOOLEAN flag);
160
161     /** Pointer to function to return input stream element at 1 based
162      *  offset from nextChar. Same as _LA for char stream, but token
163      *  streams etc. have one of these that does other stuff of course.
164      */
165     void *              (*_LT)          (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_INT32 lt);
166
167     /** Pointer to function to return the total size of the input buffer. For streams
168      *  this may be just the total we have available so far. This means of course that
169      *  the input stream must be careful to accumulate enough input so that any backtracking
170      *  can be satisfied.
171      */
172     ANTLR3_UINT32       (*size)         (struct ANTLR3_INPUT_STREAM_struct * input);
173
174     /** Pointer to function to return a substring of the input stream. String is returned in allocated
175      *  memory and is in same encoding as the input stream itself, NOT internal ANTLR3_UCHAR form.
176      */
177     pANTLR3_STRING      (*substr)       (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_MARKER start, ANTLR3_MARKER stop);
178
179     /** Pointer to function to return the current line number in the input stream
180      */
181     ANTLR3_UINT32       (*getLine)      (struct ANTLR3_INPUT_STREAM_struct * input);
182
183     /** Pointer to function to return the current line buffer in the input stream
184      *  The pointer returned is directly into the input stream so you must copy
185      *  it if you wish to manipulate it without damaging the input stream. Encoding
186      *  is obviously in the same form as the input stream.
187      *  \remark
188      *    - Note taht this function wil lbe inaccurate if setLine is called as there
189      *      is no way at the moment to position the input stream at a particular line 
190      *      number offset.
191      */
192     void          *     (*getLineBuf)   (struct ANTLR3_INPUT_STREAM_struct * input);
193
194     /** Pointer to function to return the current offset in the current input stream line
195      */
196     ANTLR3_UINT32       (*getCharPositionInLine)  (struct ANTLR3_INPUT_STREAM_struct * input);
197
198     /** Pointer to function to set the current line number in the input stream
199      */
200     void                (*setLine)                (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_UINT32 line);
201
202     /** Pointer to function to set the current position in the current line.
203      */
204     void                (*setCharPositionInLine)  (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_UINT32 position);
205
206     /** Pointer to function to override the default newline character that the input stream
207      *  looks for to trigger the line and offset and line buffer recording information.
208      *  \remark
209      *   - By default the chracter '\n' will be instaleldas tehe newline trigger character. When this
210      *     character is seen by the consume() function then the current line number is incremented and the
211      *     current line offset is reset to 0. The Pointer for the line of input we are consuming
212      *     is updated to point to the next character after this one in the input stream (which means it
213      *     may become invlaid if the last newline character in the file is seen (so watch out).
214      *   - If for some reason you do not want teh counters and pointesr to be restee, yu can set the 
215      *     chracter to some impossible charater such as '\0' or whatever.
216      *   - This is a single character only, so choose the last chracter in a sequence of two or more.
217      *   - This is only a simple aid to error reporting - if you have a complicated binary inptu structure
218      *     it may not be adequate, but you can always override every function in the input stream with your
219      *     own of course, and can even write your own complete input stream set if you like.
220      *   - It is your responsiblity to set a valid cahracter for the input stream type. Ther is no point 
221      *     setting this to 0xFFFFFFFF if the input stream is 8 bit ASCII as this will just be truncated and never
222      *     trigger as the comparison will be (INT32)0xFF == (INT32)0xFFFFFFFF
223      */
224     void                (*SetNewLineChar)           (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_UINT32 newlineChar);
225
226 }
227
228     ANTLR3_INPUT_STREAM;
229
230
231 /** \brief Structure for track lex input states as part of mark()
232  *  and rewind() of lexer.
233  */
234 typedef struct  ANTLR3_LEX_STATE_struct
235 {
236         /** Pointer to the next character to be consumed from the input data
237      *  This is cast to point at the encoding of the original file that
238      *  was read by the functions installed as pointer in this input stream
239      *  context instance at file/string/whatever load time.
240      */
241     void              * nextChar;
242
243     /** The line number we are traversing in the input file. This gets incremented
244      *  by a newline() call in the lexer grammer actions.
245      */
246     ANTLR3_UINT32       line;
247
248     /** Pointer into the input buffer where the current line
249      *  started.
250      */
251     void              * currentLine;
252
253     /** The offset within the current line of the current character
254      */
255     ANTLR3_INT32        charPositionInLine;
256
257 }
258     ANTLR3_LEX_STATE;
259
260     /* Prototypes 
261      */
262     void            antlr3AsciiSetupStream      (pANTLR3_INPUT_STREAM input, ANTLR3_UINT32 type);
263     void            antlr3UCS2SetupStream       (pANTLR3_INPUT_STREAM input, ANTLR3_UINT32 type);
264     void            antlr3GenericSetupStream    (pANTLR3_INPUT_STREAM input, ANTLR3_UINT32 type);
265
266 #ifdef __cplusplus
267 }
268 #endif
269
270 #endif  /* _ANTLR3_INPUT_H  */