]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3input.h
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.databoard / cpp / DataBoardTest / libantlr3c-3.2 / include / antlr3input.h
diff --git a/bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3input.h b/bundles/org.simantics.databoard/cpp/DataBoardTest/libantlr3c-3.2/include/antlr3input.h
new file mode 100644 (file)
index 0000000..62287c9
--- /dev/null
@@ -0,0 +1,270 @@
+/** \file\r
+ * Defines the basic structures used to manipulate character\r
+ * streams from any input source. The first implementation of\r
+ * this stream was ASCII 8 bit, but any character size and encoding\r
+ * can in theory be used, so long as they can return a 32 bit Integer\r
+ * representation of their characters amd efficiently mark and revert\r
+ * to specific offsets into their input streams.\r
+ */\r
+#ifndef        _ANTLR3_INPUT_H\r
+#define        _ANTLR3_INPUT_H\r
+\r
+// [The "BSD licence"]\r
+// Copyright (c) 2005-2009 Jim Idle, Temporal Wave LLC\r
+// http://www.temporal-wave.com\r
+// http://www.linkedin.com/in/jimidle\r
+//\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions\r
+// are met:\r
+// 1. Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+// 2. Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the distribution.\r
+// 3. The name of the author may not be used to endorse or promote products\r
+//    derived from this software without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\r
+// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES\r
+// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.\r
+// IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
+// NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
+// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#include    <antlr3defs.h>\r
+#include    <antlr3string.h>\r
+#include    <antlr3commontoken.h>\r
+#include    <antlr3intstream.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/// Master context structure for an ANTLR3 C runtime based input stream.\r
+/// \ingroup apistructures\r
+///\r
+typedef        struct  ANTLR3_INPUT_STREAM_struct\r
+{\r
+    /** Interfaces that provide streams must all provide\r
+     *  a generic ANTLR3_INT_STREAM interface and an ANTLR3_INPUT_STREAM\r
+     *  is no different.\r
+     */\r
+    pANTLR3_INT_STREAM istream;\r
+\r
+    /** Whatever super structure is providing the INPUT stream needs a pointer to itself\r
+     *  so that this can be passed back to it whenever the api functions\r
+     *  are called back from this interface.\r
+     */\r
+    void             * super;\r
+\r
+       /// Indicates the size, in 8 bit units, of a single character. Note that\r
+       /// the C runtime does not deal with surrogates and UTF8 directly as this would be\r
+       /// slow and complicated. Variable character width inputs are expected to be converted\r
+       /// into fixed width formats, so that would be a UTF32 format for anything that cannot\r
+       /// work with a UCS2 encoding, such as UTF-8. Generally you are best\r
+       /// working internally with 32 bit characters.\r
+       ///\r
+       ANTLR3_UINT8    charByteSize;\r
+\r
+    /** Pointer the start of the input string, characters may be\r
+     *  taken as offsets from here and in original input format encoding.\r
+     */\r
+    void             * data;\r
+\r
+    /** Indicates if the data pointer was allocated by us, and so should be freed\r
+     *  when the stream dies.\r
+     */\r
+    int                        isAllocated;\r
+\r
+    /** String factory for this input stream\r
+     */\r
+    pANTLR3_STRING_FACTORY  strFactory;\r
+\r
+\r
+    /** Pointer to the next character to be consumed from the input data\r
+     *  This is cast to point at the encoding of the original file that\r
+     *  was read by the functions installed as pointer in this input stream\r
+     *  context instance at file/string/whatever load time.\r
+     */\r
+    void             * nextChar;\r
+\r
+    /** Number of characters that can be consumed at this point in time.\r
+     *  Mostly this is just what is left in the pre-read buffer, but if the\r
+     *  input source is a stream such as a socket or something then we may\r
+     *  call special read code to wait for more input.\r
+     */\r
+    ANTLR3_UINT32      sizeBuf;\r
+\r
+    /** The line number we are traversing in the input file. This gets incremented\r
+     *  by a newline() call in the lexer grammar actions.\r
+     */\r
+    ANTLR3_UINT32      line;\r
+\r
+    /** Pointer into the input buffer where the current line\r
+     *  started.\r
+     */\r
+    void             * currentLine;\r
+\r
+    /** The offset within the current line of the current character\r
+     */\r
+    ANTLR3_INT32       charPositionInLine;\r
+\r
+    /** Tracks how deep mark() calls are nested\r
+     */\r
+    ANTLR3_UINT32      markDepth;\r
+\r
+    /** List of mark() points in the input stream\r
+     */\r
+    pANTLR3_VECTOR     markers;\r
+\r
+    /** File name string, set to pointer to memory if\r
+     * you set it manually as it will be free()d\r
+     */\r
+    pANTLR3_STRING     fileName;\r
+\r
+       /** File number, needs to be set manually to some file index of your devising.\r
+        */\r
+       ANTLR3_UINT32   fileNo;\r
+\r
+    /** Character that automatically causes an internal line count\r
+     *  increment.\r
+     */\r
+    ANTLR3_UCHAR       newlineChar;\r
+\r
+    /* API */\r
+\r
+\r
+   /** Pointer to function that closes the input stream\r
+     */\r
+    void               (*close)        (struct ANTLR3_INPUT_STREAM_struct * input);\r
+    void               (*free)         (struct ANTLR3_INPUT_STREAM_struct * input);\r
+\r
+    /** Pointer to function that resets the input stream\r
+     */\r
+    void               (*reset)        (struct ANTLR3_INPUT_STREAM_struct * input);\r
+\r
+       /**\r
+        * Pinter to function that installs a version of LA that always\r
+        * returns upper case. Only valid for character streams and creates a case\r
+        * insensitive lexer if the lexer tokens are described in upper case. The\r
+        * tokens will preserve case in the token text.\r
+        */\r
+       void            (*setUcaseLA)           (pANTLR3_INPUT_STREAM input, ANTLR3_BOOLEAN flag);\r
+\r
+    /** Pointer to function to return input stream element at 1 based\r
+     *  offset from nextChar. Same as _LA for char stream, but token\r
+     *  streams etc. have one of these that does other stuff of course.\r
+     */\r
+    void *             (*_LT)          (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_INT32 lt);\r
+\r
+    /** Pointer to function to return the total size of the input buffer. For streams\r
+     *  this may be just the total we have available so far. This means of course that\r
+     *  the input stream must be careful to accumulate enough input so that any backtracking\r
+     *  can be satisfied.\r
+     */\r
+    ANTLR3_UINT32      (*size)         (struct ANTLR3_INPUT_STREAM_struct * input);\r
+\r
+    /** Pointer to function to return a substring of the input stream. String is returned in allocated\r
+     *  memory and is in same encoding as the input stream itself, NOT internal ANTLR3_UCHAR form.\r
+     */\r
+    pANTLR3_STRING     (*substr)       (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_MARKER start, ANTLR3_MARKER stop);\r
+\r
+    /** Pointer to function to return the current line number in the input stream\r
+     */\r
+    ANTLR3_UINT32      (*getLine)      (struct ANTLR3_INPUT_STREAM_struct * input);\r
+\r
+    /** Pointer to function to return the current line buffer in the input stream\r
+     *  The pointer returned is directly into the input stream so you must copy\r
+     *  it if you wish to manipulate it without damaging the input stream. Encoding\r
+     *  is obviously in the same form as the input stream.\r
+     *  \remark\r
+     *    - Note taht this function wil lbe inaccurate if setLine is called as there\r
+     *      is no way at the moment to position the input stream at a particular line \r
+     *     number offset.\r
+     */\r
+    void         *     (*getLineBuf)   (struct ANTLR3_INPUT_STREAM_struct * input);\r
+\r
+    /** Pointer to function to return the current offset in the current input stream line\r
+     */\r
+    ANTLR3_UINT32      (*getCharPositionInLine)  (struct ANTLR3_INPUT_STREAM_struct * input);\r
+\r
+    /** Pointer to function to set the current line number in the input stream\r
+     */\r
+    void               (*setLine)                (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_UINT32 line);\r
+\r
+    /** Pointer to function to set the current position in the current line.\r
+     */\r
+    void               (*setCharPositionInLine)  (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_UINT32 position);\r
+\r
+    /** Pointer to function to override the default newline character that the input stream\r
+     *  looks for to trigger the line and offset and line buffer recording information.\r
+     *  \remark\r
+     *   - By default the chracter '\n' will be instaleldas tehe newline trigger character. When this\r
+     *     character is seen by the consume() function then the current line number is incremented and the\r
+     *     current line offset is reset to 0. The Pointer for the line of input we are consuming\r
+     *     is updated to point to the next character after this one in the input stream (which means it\r
+     *     may become invlaid if the last newline character in the file is seen (so watch out).\r
+     *   - If for some reason you do not want teh counters and pointesr to be restee, yu can set the \r
+     *     chracter to some impossible charater such as '\0' or whatever.\r
+     *   - This is a single character only, so choose the last chracter in a sequence of two or more.\r
+     *   - This is only a simple aid to error reporting - if you have a complicated binary inptu structure\r
+     *     it may not be adequate, but you can always override every function in the input stream with your\r
+     *     own of course, and can even write your own complete input stream set if you like.\r
+     *   - It is your responsiblity to set a valid cahracter for the input stream type. Ther is no point \r
+     *     setting this to 0xFFFFFFFF if the input stream is 8 bit ASCII as this will just be truncated and never\r
+     *    trigger as the comparison will be (INT32)0xFF == (INT32)0xFFFFFFFF\r
+     */\r
+    void               (*SetNewLineChar)           (struct ANTLR3_INPUT_STREAM_struct * input, ANTLR3_UINT32 newlineChar);\r
+\r
+}\r
+\r
+    ANTLR3_INPUT_STREAM;\r
+\r
+\r
+/** \brief Structure for track lex input states as part of mark()\r
+ *  and rewind() of lexer.\r
+ */\r
+typedef        struct  ANTLR3_LEX_STATE_struct\r
+{\r
+        /** Pointer to the next character to be consumed from the input data\r
+     *  This is cast to point at the encoding of the original file that\r
+     *  was read by the functions installed as pointer in this input stream\r
+     *  context instance at file/string/whatever load time.\r
+     */\r
+    void             * nextChar;\r
+\r
+    /** The line number we are traversing in the input file. This gets incremented\r
+     *  by a newline() call in the lexer grammer actions.\r
+     */\r
+    ANTLR3_UINT32      line;\r
+\r
+    /** Pointer into the input buffer where the current line\r
+     *  started.\r
+     */\r
+    void             * currentLine;\r
+\r
+    /** The offset within the current line of the current character\r
+     */\r
+    ANTLR3_INT32       charPositionInLine;\r
+\r
+}\r
+    ANTLR3_LEX_STATE;\r
+\r
+    /* Prototypes \r
+     */\r
+    void           antlr3AsciiSetupStream      (pANTLR3_INPUT_STREAM input, ANTLR3_UINT32 type);\r
+    void           antlr3UCS2SetupStream       (pANTLR3_INPUT_STREAM input, ANTLR3_UINT32 type);\r
+    void           antlr3GenericSetupStream    (pANTLR3_INPUT_STREAM input, ANTLR3_UINT32 type);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* _ANTLR3_INPUT_H  */\r