@@ -56,6 +56,7 @@ struct preprocess gl_pp;
5656
5757// used for error messages
5858AST * last_ast ;
59+ AST * prev_last_ast ;
5960
6061// accumulated comments
6162static AST * comment_chain ;
@@ -1030,6 +1031,7 @@ parseSpinIdentifier(LexStream *L, AST **ast_ptr, const char *prefix)
10301031 if (sym -> kind == SYM_TYPEDEF ) {
10311032 ast = (AST * )sym -> v .ptr ;
10321033 * ast_ptr = ast ;
1034+ prev_last_ast = last_ast ;
10331035 last_ast = AstIdentifier (idstr );
10341036 return SP_TYPENAME ;
10351037 }
@@ -1044,6 +1046,7 @@ parseSpinIdentifier(LexStream *L, AST **ast_ptr, const char *prefix)
10441046 open_obj = NULL ;
10451047 if (typ -> kind == AST_TYPEDEF ) {
10461048 * ast_ptr = typ ;
1049+ prev_last_ast = last_ast ;
10471050 last_ast = AstIdentifier (idstr );
10481051 return SP_TYPENAME ;
10491052 }
@@ -1082,6 +1085,22 @@ parseSpinIdentifier(LexStream *L, AST **ast_ptr, const char *prefix)
10821085 return SP_IDENTIFIER ;
10831086}
10841087
1088+ /* helper function for syntax errors; see if a string might be
1089+ a reserved keyword in some version of Spin2
1090+ */
1091+ bool Spin2NewKeyword (LexStream * L , const char * idstr ) {
1092+ Symbol * sym ;
1093+
1094+ if (L -> language != LANG_SPIN_SPIN2 )
1095+ return false;
1096+ sym = FindSymbol (& spin2SoftReservedWords , idstr );
1097+ if (!sym ) {
1098+ return false;
1099+ }
1100+ /* could do a more sophisticated check here... */
1101+ return true;
1102+ }
1103+
10851104/* parse the rest of the line as a string */
10861105static void
10871106parseLineAsString (LexStream * L , AST * * ast_ptr )
@@ -2012,6 +2031,7 @@ getSpinToken(LexStream *L, AST **ast_ptr)
20122031 case BACKTICK_STATE_ESCAPE_PREFIX :
20132032 lexungetc (L , c );
20142033 L -> backtick_state = BACKTICK_STATE_PREFIX_COMMA_DONE ;
2034+ prev_last_ast = last_ast ;
20152035 * ast_ptr = last_ast = NULL ;
20162036 return ',' ;
20172037 case BACKTICK_STATE_PREFIX_COMMA_DONE :
@@ -2020,6 +2040,7 @@ getSpinToken(LexStream *L, AST **ast_ptr)
20202040 parseBacktickInBacktick (L , & ast );
20212041 c = SP_IDENTIFIER ;
20222042 L -> backtick_state = BACKTICK_STATE_ESCAPE_PARAMS ;
2043+ prev_last_ast = last_ast ;
20232044 * ast_ptr = last_ast = ast ;
20242045 return c ;
20252046 case BACKTICK_STATE_ESCAPE_PARAMS :
@@ -2030,28 +2051,33 @@ getSpinToken(LexStream *L, AST **ast_ptr)
20302051 if (c == ')' ) {
20312052 // done with the backtick escape
20322053 L -> backtick_state = BACKTICK_STATE_INSERT_COMMA ;
2054+ prev_last_ast = last_ast ;
20332055 * ast_ptr = last_ast = NULL ;
20342056 return c ;
20352057 }
20362058 break ;
20372059 case BACKTICK_STATE_INSERT_COMMA :
20382060 if (c == ')' ) {
20392061 L -> backtick_state = BACKTICK_STATE_NONE ;
2062+ prev_last_ast = last_ast ;
20402063 * ast_ptr = last_ast = NULL ;
20412064 return c ;
20422065 }
20432066 lexungetc (L , c );
2067+ prev_last_ast = last_ast ;
20442068 * ast_ptr = last_ast = NULL ;
20452069 L -> backtick_state = BACKTICK_STATE_STRING ;
20462070 return ',' ;
20472071 case BACKTICK_STATE_STRING :
20482072 if (c == ')' ) {
20492073 L -> backtick_state = BACKTICK_STATE_NONE ;
2074+ prev_last_ast = last_ast ;
20502075 * ast_ptr = last_ast = NULL ;
20512076 return c ;
20522077 }
20532078 lexungetc (L , c );
20542079 c = parseBacktickString (L , & ast , 0 );
2080+ prev_last_ast = last_ast ;
20552081 * ast_ptr = last_ast = ast ;
20562082 return c ;
20572083 case BACKTICK_STATE_NONE :
@@ -2072,6 +2098,7 @@ getSpinToken(LexStream *L, AST **ast_ptr)
20722098
20732099// printf("L->linecounter=%d\n", L->lineCounter);
20742100 if (c >= 127 ) {
2101+ prev_last_ast = last_ast ;
20752102 * ast_ptr = last_ast = ast ;
20762103 return c ;
20772104 } else if (safe_isdigit (c ) || (c == '.' && safe_isdigit (lexpeekc (L )))) {
@@ -2256,6 +2283,7 @@ getSpinToken(LexStream *L, AST **ast_ptr)
22562283 } else if (c == ')' ) {
22572284 PopExprState (L );
22582285 }
2286+ prev_last_ast = last_ast ;
22592287 * ast_ptr = last_ast = ast ;
22602288
22612289 if (c != SP_TYPENAME && c != SP_IDENTIFIER && c != '.' )
@@ -5260,3 +5288,4 @@ cgramyylex(CGRAMYYSTYPE *yval)
52605288 return 0 ;
52615289 return c ;
52625290}
5291+
0 commit comments