⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 antlr3inputstream.c

📁 antlr最新版本V3源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
    input   = ((pANTLR3_INPUT_STREAM) (is->super));    return  (ANTLR3_INT64)(((pANTLR3_UINT8)input->nextChar) - ((pANTLR3_UINT8)input->data));}/** \brief Return the size of the current input stream, as an Ascii file *   which in this case is the total input. Other implementations may provide *   more sophisticated implemenatins to deal with non-recoverable streams  *   and so on. * * \param[in] input Input stream context pointer */static	ANTLR3_UINT64 antlr3AsciiSize(pANTLR3_INPUT_STREAM input){    return  input->sizeBuf;}/** \brief Mark the current input point in an Ascii 8 bit stream *  such as a file stream, where all the input is available in the *  buffer. * * \param[in] input Input stream context pointer */static ANTLR3_UINT64antlr3AsciiMark	(pANTLR3_INT_STREAM is){    pANTLR3_LEX_STATE	    state;    pANTLR3_INPUT_STREAM    input;    input   = ((pANTLR3_INPUT_STREAM) (is->super));    /* New mark point      */    input->markDepth++;    /* See if we are revisiting a mark as we can just reuse the hashtable     * entry if we are, otherwise, we need a new one     */    if	(input->markDepth > input->markers->count)    {		state	= ANTLR3_MALLOC(sizeof(ANTLR3_LEX_STATE));	/* Add it to the table	 */	input->markers->add(input->markers, state, ANTLR3_FREE_FUNC);	/* No special structure, just free() on delete */    }    else    {	state	= (pANTLR3_LEX_STATE)input->markers->get(input->markers, input->markDepth);	/* Assume no errors for speed, it will just blow up if the table failed	 * for some reasons, hence lots of unit tests on the tables ;-)	 */    }    /* We have created or retrieved the state, so update it with the current     * elements of the lexer state.     */    state->charPositionInLine	= input->charPositionInLine;    state->currentLine		= input->currentLine;    state->line			= input->line;    state->nextChar		= input->nextChar;    is->lastMarker  = input->markDepth;    /* And that's it     */    return  input->markDepth;}/** \brief Rewind the lexer input to the state specified by the last produced mark. *  * \param[in] input Input stream context pointer * * \remark * Assumes ASCII (or at least, 8 Bit) input stream. */static voidantlr3AsciiRewindLast	(pANTLR3_INT_STREAM is){    is->rewind(is, is->lastMarker);}/** \brief Rewind the lexer input to the state specified by the supplied mark. *  * \param[in] input Input stream context pointer * * \remark * Assumes ASCII (or at least, 8 Bit) input stream. */static voidantlr3AsciiRewind	(pANTLR3_INT_STREAM is, ANTLR3_UINT64 mark){    pANTLR3_LEX_STATE	state;    pANTLR3_INPUT_STREAM input;    input   = ((pANTLR3_INPUT_STREAM) is->super);    /* Perform any clean up of the marks     */    input->istream->release(input->istream, mark);    /* Find the supplied mark state      */    state   = (pANTLR3_LEX_STATE)input->markers->get(input->markers, mark);    /* Seek input pointer to the requested point (note we supply the void *pointer     * to whatever is implementing the int stream to seek).     */    antlr3AsciiSeek(is, ANTLR3_UINT64_CAST(state->nextChar));    /* Reset to the reset of the information in the mark     */    input->charPositionInLine	= state->charPositionInLine;    input->currentLine		= state->currentLine;    input->line			= state->line;    input->nextChar		= state->nextChar;    /* And we are done     */}/** \brief Rewind the lexer input to the state specified by the supplied mark. *  * \param[in] input Input stream context pointer * * \remark * Assumes ASCII (or at least, 8 Bit) input stream. */static voidantlr3AsciiRelease	(pANTLR3_INT_STREAM is, ANTLR3_UINT64 mark){    pANTLR3_INPUT_STREAM input;    input   = ((pANTLR3_INPUT_STREAM) (is->super));    /* We don't do much here in fact as we never free any higher marks in     * the hashtable as we just resuse any memory allocated for them.     */    input->markDepth	= mark - 1;}/** \brief Rewind the lexer input to the state specified by the supplied mark. *  * \param[in] input Input stream context pointer * * \remark * Assumes ASCII (or at least, 8 Bit) input stream. */static ANTLR3_INLINE voidantlr3AsciiSeek	(pANTLR3_INT_STREAM is, ANTLR3_UINT64 seekPoint){    ANTLR3_INT64   count;    pANTLR3_INPUT_STREAM input;    input   = ((pANTLR3_INPUT_STREAM) is->super);    /* If the requested seek point is less than the current     * input point, then we assume that we are reseting from a mark     * and do not need to scan, but can just set to there.     */    if	(seekPoint <= ANTLR3_UINT64_CAST(input->nextChar))    {	input->nextChar	= ((pANTLR3_UINT8) seekPoint);    }    else    {	count	= seekPoint - ANTLR3_UINT64_CAST(((pANTLR3_UINT8)(input->nextChar)));	while (count--)	{	    is->consume(is);	}    }}/** \brief Retrun a substring of the ASCII (8 bit) input stream in *  newly allocated memory. * * \param input Input stream context pointer * \param start Offset in input stream where the string starts * \param stop  Offset in the input stream where the string ends. */static pANTLR3_STRINGantlr3AsciiSubstr		(pANTLR3_INPUT_STREAM input, ANTLR3_INT64 start, ANTLR3_INT64 stop){    return  input->strFactory->newPtr(input->strFactory, (pANTLR3_UINT8)(input->data)+start, (ANTLR3_UINT32)(stop - start + 1));}/** \brief Return the line number as understood by the 8 bit/ASCII input stream. * * \param input Input stream context pointer * \return	Line number in input stream that we belive we are working on. */static ANTLR3_UINT64   antlr3AsciiGetLine		(pANTLR3_INPUT_STREAM input){    return  input->line;}/** \ Brief return a pointer into the input stream that points at the start *    of the current input line as triggered by the end of line character installed *    for the stream ('\n' unless told differently). * * \param input  */static void	  * antlr3AsciiGetLineBuf	(pANTLR3_INPUT_STREAM input){    return  input->currentLine;}/** \Brief return the current offset in to the current line in the input stream. * * \param input Input stream context pointer * \return      Current line offset */static ANTLR3_UINT32antlr3AsciiGetCharPosition	(pANTLR3_INPUT_STREAM input){    return  input->charPositionInLine;}/** \ Brief Set the current line number as understood by the input stream. * * \param input Input stream context pointer * \param line  Line number to tell the input stream we are on * * \remark *  This function does not change any pointers, it just allows the programmer to set the *  line number according to some external criterion, such as finding a lexed directive *  like: #nnn "file.c" for instance, such that error reporting and so on in is in sync *  with some oringial source format. */static voidantlr3AsciiSetLine		(pANTLR3_INPUT_STREAM input, ANTLR3_UINT32 line){    input->line	= line;}/** \Brief Set the current offset in the current line to be a paricular setting. * * \param[in] input    Input stream context pointer * \param[in] position New setting for current offset. * * \remark * This does not set the actaul pointers in the input stream, it is purely for reporting * purposes and so on as per antlr3AsciiSetLine(); */static voidantlr3AsciiSetCharPosition	(pANTLR3_INPUT_STREAM input, ANTLR3_UINT32 position){    input->charPositionInLine = position;}/** \brief set the newline trigger chacter in the input stream to the supplied paramter. * * \param[in] input	    Input stream context pointer * \param[in] newlineChar   Character to set to be the newline trigger. * * \remark *  - The supplied newLineChar is in UTF32 encoding (which means ASCII and latin1 etc *    are the same encodings), but the input stream catered to by this function is 8 bit *    only, so it is up to the programmer ti ensure that the character supplied is valid. */static void antlr3AsciiSetNewLineChar	(pANTLR3_INPUT_STREAM input, ANTLR3_UINT32 newlineChar){    input->newlineChar	= newlineChar;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -