read: Allow to unget up to 3 characters
Some parsers need to unget more than one characters, so add support for this. X-Universal-CTags-Commit-ID: 956af0555d3a8ef33304c5ae6ed873f22b4e4284
This commit is contained in:
parent
944bffb967
commit
b975c2652d
@ -428,7 +428,12 @@ readnext:
|
||||
|
||||
extern void fileUngetc (int c)
|
||||
{
|
||||
File.ungetch = c;
|
||||
const size_t len = sizeof File.ungetchBuf / sizeof File.ungetchBuf[0];
|
||||
|
||||
Assert (File.ungetchIdx < len);
|
||||
/* we cannot rely on the assertion that might be disabled in non-debug mode */
|
||||
if (File.ungetchIdx < len)
|
||||
File.ungetchBuf[File.ungetchIdx++] = c;
|
||||
}
|
||||
|
||||
static vString *iFileGetLine (void)
|
||||
@ -468,10 +473,9 @@ extern int fileGetc (void)
|
||||
* other processing on it, though, because we already did that the
|
||||
* first time it was read through fileGetc ().
|
||||
*/
|
||||
if (File.ungetch != '\0')
|
||||
if (File.ungetchIdx > 0)
|
||||
{
|
||||
c = File.ungetch;
|
||||
File.ungetch = '\0';
|
||||
c = File.ungetchBuf[--File.ungetchIdx];
|
||||
return c; /* return here to avoid re-calling debugPutc () */
|
||||
}
|
||||
do
|
||||
|
@ -70,7 +70,8 @@ typedef struct sInputFile {
|
||||
MIO *mio; /* stream used for reading the file */
|
||||
unsigned long lineNumber; /* line number in the input file */
|
||||
MIOPos filePosition; /* file position of current line */
|
||||
int ungetch; /* a single character that was ungotten */
|
||||
unsigned int ungetchIdx;
|
||||
int ungetchBuf[3]; /* characters that were ungotten */
|
||||
boolean eof; /* have we reached the end of file? */
|
||||
boolean newLine; /* will the next character begin a new line? */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user