Skip to content

Commit fdee5e9

Browse files
committed
Bug 700381 - error state 21 with fortran code (fixed format)
Problem is caused by similar quotes inside quotes, in Fortran it is possible to "escape" quotes by doubling them.
1 parent 295a467 commit fdee5e9

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/fortranscanner.l

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static bool endScope(Entry *scope, bool isGlobalRoot=FALSE);
214214
//static bool isTypeName(QCString name);
215215
static void resolveModuleProcedures(QList<Entry> &moduleProcedures, Entry *current_root);
216216
static int getAmpersandAtTheStart(const char *buf, int length);
217-
static int getAmpOrExclAtTheEnd(const char *buf, int length);
217+
static int getAmpOrExclAtTheEnd(const char *buf, int length, char ch);
218218
static void truncatePrepass(int index);
219219
static void pushBuffer(QCString &buffer);
220220
static void popBuffer();
@@ -328,7 +328,7 @@ SCOPENAME ({ID}{BS}"::"{BS})*
328328
DBG_CTX((stderr, "---%s", yytext));
329329

330330
int indexStart = getAmpersandAtTheStart(yytext, (int)yyleng);
331-
int indexEnd = getAmpOrExclAtTheEnd(yytext, (int)yyleng);
331+
int indexEnd = getAmpOrExclAtTheEnd(yytext, (int)yyleng, '\0');
332332
if (indexEnd>=0 && yytext[indexEnd]!='&') //we are only interested in amp
333333
indexEnd=-1;
334334

@@ -1273,13 +1273,15 @@ static int getAmpersandAtTheStart(const char *buf, int length)
12731273
}
12741274

12751275
/* Returns ampersand index, comment start index or -1 if neither exist.*/
1276-
static int getAmpOrExclAtTheEnd(const char *buf, int length)
1276+
static int getAmpOrExclAtTheEnd(const char *buf, int length, char ch)
12771277
{
12781278
// Avoid ampersands in string and comments
12791279
int parseState = Start;
12801280
char quoteSymbol = 0;
12811281
int ampIndex = -1;
12821282
int commentIndex = -1;
1283+
quoteSymbol = ch;
1284+
if (ch != '\0') parseState = String;
12831285

12841286
for(int i=0; i<length && parseState!=Comment; i++)
12851287
{
@@ -1410,6 +1412,8 @@ static const char* prepassFixedForm(const char* contents)
14101412
int column=0;
14111413
int prevLineLength=0;
14121414
int prevLineAmpOrExclIndex=-1;
1415+
char prevQuote = '\0';
1416+
char thisQuote = '\0';
14131417
bool emptyLabel=TRUE;
14141418
bool commented=FALSE;
14151419
bool inSingle=FALSE;
@@ -1429,11 +1433,12 @@ static const char* prepassFixedForm(const char* contents)
14291433
switch(c) {
14301434
case '\n':
14311435
prevLineLength=column;
1432-
prevLineAmpOrExclIndex=getAmpOrExclAtTheEnd(&contents[i-prevLineLength+1], prevLineLength);
1436+
prevLineAmpOrExclIndex=getAmpOrExclAtTheEnd(&contents[i-prevLineLength+1], prevLineLength,prevQuote);
14331437
column=0;
14341438
emptyLabel=TRUE;
14351439
commented=FALSE;
14361440
newContents[j]=c;
1441+
prevQuote = thisQuote;
14371442
break;
14381443
case ' ':
14391444
case '\t':
@@ -1464,12 +1469,22 @@ static const char* prepassFixedForm(const char* contents)
14641469
}
14651470
else if (c == '\'')
14661471
{
1467-
if (!inDouble) inSingle = !inSingle;
1472+
if (!inDouble)
1473+
{
1474+
inSingle = !inSingle;
1475+
if (inSingle) thisQuote = c;
1476+
else thisQuote = '\0';
1477+
}
14681478
break;
14691479
}
14701480
else if (c == '"')
14711481
{
1472-
if (!inSingle) inDouble = !inDouble;
1482+
if (!inSingle)
1483+
{
1484+
inDouble = !inDouble;
1485+
if (inDouble) thisQuote = c;
1486+
else thisQuote = '\0';
1487+
}
14731488
break;
14741489
}
14751490
}

0 commit comments

Comments
 (0)