/// \brief Common function to setup function interface for a 16 bit "UCS2" input stream. /// /// \param input Input stream context pointer /// /// \remark /// - Strictly speaking, there is no such thing as a UCS2 input stream as the term /// tends to confuse the notions of character encoding, unicode and so on. However /// because there will possibly be a need for a UTF-16 stream, I needed to identify 16 bit /// streams that do not support surrogate encodings and UCS2 is how it is mostly referred to. /// For instance Java, Oracle and others use a 16 bit encoding of characters and so this type /// of stream is very common. /// Take it to mean, therefore, a straight 16 bit uncomplicated encoding of Unicode code points. /// void antlr3UCS2SetupStream (pANTLR3_INPUT_STREAM input, ANTLR3_UINT32 type) { // Build a string factory for this stream. This is a 16 bit string "UCS2" factory which is a standard // part of the ANTLR3 string. The string factory is then passed through the whole chain of lexer->parser->tree->treeparser // and so on. // input->strFactory = antlr3UCS2StringFactoryNew(); // Install function pointers for an 8 bit ASCII input, which are good for almost // all input stream functions. We will then override those that won't work for 16 bit characters. // antlr3GenericSetupStream (input, type); // Intstream API overrides for UCS2 // input->istream->consume = antlr3UCS2Consume; // Consume the next 16 bit character in the buffer input->istream->_LA = antlr3UCS2LA; // Return the UTF32 character at offset n (1 based) input->istream->index = antlr3UCS2Index; // Calculate current index in input stream, 16 bit based input->istream->seek = antlr3UCS2Seek; // How to seek to a specific point in the stream // Charstream API overrides for UCS2 // input->substr = antlr3UCS2Substr; // Return a string from the input stream input->charByteSize = 2; // Size in bytes of characters in this stream. }
/// \brief Common function to setup function interface for an 8 bit ASCII input stream. /// /// \param input Input stream context pointer /// /// \remark /// - Many of the 8 bit ASCII oriented file stream handling functions will be usable /// by any or at least some other input streams. Therefore it is perfectly acceptable /// to call this function to install the ASCII handler then override just those functions /// that would not work for the particular input encoding, such as consume for instance. /// void antlr3AsciiSetupStream (pANTLR3_INPUT_STREAM input, ANTLR3_UINT32 type) { // Build a string factory for this stream // input->strFactory = antlr3StringFactoryNew(); // Default stream set up is for ASCII, therefore there is nothing else // to do but set it up as such // antlr3GenericSetupStream(input, type); }
static pANTLR3_INPUT_STREAM antlr3CreateLineBufferedStream(std::istream& in) { // Pointer to the input stream we are going to create // pANTLR3_INPUT_STREAM input; if (!in) { return NULL; } // Allocate memory for the input stream structure // input = (pANTLR3_INPUT_STREAM) ANTLR3_CALLOC(1, sizeof(ANTLR3_LINE_BUFFERED_INPUT_STREAM)); if (input == NULL) { return NULL; } // Structure was allocated correctly, now we can install the pointer // input->data = malloc(1024); input->isAllocated = ANTLR3_FALSE; ((pANTLR3_LINE_BUFFERED_INPUT_STREAM)input)->in = ∈ // Call the common 8 bit input stream handler // initialization. // #ifdef CVC4_ANTLR3_OLD_INPUT_STREAM antlr3AsciiSetupStream(input, ANTLR3_CHARSTREAM); #else /* CVC4_ANTLR3_OLD_INPUT_STREAM */ antlr38BitSetupStream(input); // In some libantlr3c 3.4-beta versions, this call is not included in the above. // This is probably an erroneously-deleted line in the libantlr3c source since 3.2. antlr3GenericSetupStream(input); #endif /* CVC4_ANTLR3_OLD_INPUT_STREAM */ return input; }