Changeset 108014 in vbox for trunk/src/VBox/Runtime/common/script/scriptlex.cpp
- Timestamp:
- Feb 1, 2025 7:20:09 PM (4 weeks ago)
- svn:sync-xref-src-repo-rev:
- 167286
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/script/scriptlex.cpp
r106061 r108014 422 422 423 423 424 /** 425 * Produce an error token with the given error message. 426 * 427 * @returns IPRT status code. 428 * @param pThis The lexer state. 429 * @param pTok The token to fill. 430 * @param rc The status code to use in the message. 431 * @param pszMsg The format string for the error message. 432 * @param ... Arguments to the format string. 433 */ 434 static int rtScriptLexProduceTokError(PRTSCRIPTLEXINT pThis, PRTSCRIPTLEXTOKEN pTok, 435 int rc, const char *pszMsg, ...) 436 { 424 RTDECL(int) RTScriptLexProduceTokError(RTSCRIPTLEX hScriptLex, PRTSCRIPTLEXTOKEN pTok, 425 int rc, const char *pszMsg, ...) 426 { 427 PRTSCRIPTLEXINT pThis = hScriptLex; 428 437 429 va_list va; 438 430 va_start(va, pszMsg); … … 447 439 448 440 return rc; 441 } 442 443 444 RTDECL(int) RTScriptLexProduceTokIde(RTSCRIPTLEX hScriptLex, PRTSCRIPTLEXTOKEN pTok, const char *pszIde, size_t cchIde) 445 { 446 PRTSCRIPTLEXINT pThis = hScriptLex; 447 448 /* Insert into string cache. */ 449 pTok->enmType = RTSCRIPTLEXTOKTYPE_IDENTIFIER; 450 pTok->Type.Id.pszIde = RTStrCacheEnterN(pThis->hStrCacheId, pszIde, cchIde); 451 if (RT_UNLIKELY(!pTok->Type.Id.pszIde)) 452 return RTScriptLexProduceTokError(hScriptLex, pTok, VERR_NO_STR_MEMORY, "Lexer: Out of memory inserting identifier into string cache"); 453 454 pTok->PosEnd = pThis->Pos; 455 return VINF_SUCCESS; 449 456 } 450 457 … … 476 483 break; 477 484 default: 478 rtScriptLexProduceTokError(pThis, pTok, VERR_INVALID_PARAMETER,485 RTScriptLexProduceTokError(pThis, pTok, VERR_INVALID_PARAMETER, 479 486 "Lexer: The match contains an invalid token type: %d\n", 480 487 pTok->enmType); … … 541 548 pThis->rcRdr = pThis->pCfg->pfnProdDef(pThis, ch, pTok, pThis->pCfg->pvProdDefUser); 542 549 else 543 rtScriptLexProduceTokError(pThis, pTok, VERR_INVALID_PARAMETER,550 RTScriptLexProduceTokError(pThis, pTok, VERR_INVALID_PARAMETER, 544 551 "Lexer: Invalid character found in input: %c\n", 545 552 ch); … … 974 981 if ( idx == sizeof(aszIde) - 1 975 982 && rtScriptLexLocateChInStrConsume(hScriptLex, ch, pszCharSet)) 976 return rtScriptLexProduceTokError(hScriptLex, pTok, VERR_BUFFER_OVERFLOW, "Lexer: Identifier exceeds the allowed length");983 return RTScriptLexProduceTokError(hScriptLex, pTok, VERR_BUFFER_OVERFLOW, "Lexer: Identifier exceeds the allowed length"); 977 984 978 985 /* Insert into string cache. */ … … 980 987 pTok->Type.Id.pszIde = RTStrCacheEnterN(pThis->hStrCacheId, &aszIde[0], idx); 981 988 if (RT_UNLIKELY(!pTok->Type.Id.pszIde)) 982 return rtScriptLexProduceTokError(hScriptLex, pTok, VERR_NO_STR_MEMORY, "Lexer: Out of memory inserting identifier into string cache");989 return RTScriptLexProduceTokError(hScriptLex, pTok, VERR_NO_STR_MEMORY, "Lexer: Out of memory inserting identifier into string cache"); 983 990 984 991 pTok->PosEnd = pThis->Pos; … … 1034 1041 int rc = rtScriptLexScanStringLiteralChAdd(pThis, '\0', idxChCur); 1035 1042 if (RT_FAILURE(rc)) 1036 return rtScriptLexProduceTokError(hScriptLex, pTok, rc, "Lexer: Error adding character to string literal");1043 return RTScriptLexProduceTokError(hScriptLex, pTok, rc, "Lexer: Error adding character to string literal"); 1037 1044 1038 1045 ch = RTScriptLexGetCh(hScriptLex); … … 1040 1047 { 1041 1048 if (ch == '\0') 1042 return rtScriptLexProduceTokError(hScriptLex, pTok, VERR_EOF, "Lexer: End of stream before closing string literal terminal");1049 return RTScriptLexProduceTokError(hScriptLex, pTok, VERR_EOF, "Lexer: End of stream before closing string literal terminal"); 1043 1050 else if (ch == '\"') 1044 1051 { 1052 RTScriptLexConsumeCh(hScriptLex); 1053 1045 1054 /* End of string, add it to the string literal cache and build the token. */ 1046 1055 pTok->enmType = RTSCRIPTLEXTOKTYPE_STRINGLIT; … … 1048 1057 pTok->Type.StringLit.pszString = RTStrCacheEnterN(pThis->hStrCacheStringLit, pThis->pszStrLit, idxChCur); 1049 1058 if (RT_UNLIKELY(!pTok->Type.StringLit.pszString)) 1050 return rtScriptLexProduceTokError(hScriptLex, pTok, VERR_NO_STR_MEMORY, "Lexer: Error adding string literal to the cache");1059 return RTScriptLexProduceTokError(hScriptLex, pTok, VERR_NO_STR_MEMORY, "Lexer: Error adding string literal to the cache"); 1051 1060 else 1052 1061 break; … … 1104 1113 default: 1105 1114 /* Not supported for now. */ 1106 return rtScriptLexProduceTokError(hScriptLex, pTok, VERR_NOT_SUPPORTED, "Lexer: Invalid/unsupported escape sequence");1115 return RTScriptLexProduceTokError(hScriptLex, pTok, VERR_NOT_SUPPORTED, "Lexer: Invalid/unsupported escape sequence"); 1107 1116 } 1108 1117 } … … 1112 1121 idxChCur++; 1113 1122 else 1114 return rtScriptLexProduceTokError(hScriptLex, pTok, rc, "Lexer: Error adding character to string literal");1123 return RTScriptLexProduceTokError(hScriptLex, pTok, rc, "Lexer: Error adding character to string literal"); 1115 1124 1116 1125 ch = RTScriptLexConsumeChEx(hScriptLex, RTSCRIPT_LEX_CONV_F_NOTHING); … … 1132 1141 int rc = rtScriptLexScanStringLiteralChAdd(pThis, '\0', idxChCur); 1133 1142 if (RT_FAILURE(rc)) 1134 return rtScriptLexProduceTokError(hScriptLex, pTok, rc, "Lexer: Error adding character to string literal");1143 return RTScriptLexProduceTokError(hScriptLex, pTok, rc, "Lexer: Error adding character to string literal"); 1135 1144 1136 1145 ch = RTScriptLexGetChEx(hScriptLex, RTSCRIPT_LEX_CONV_F_NOTHING); … … 1138 1147 { 1139 1148 if (ch == '\0') 1140 return rtScriptLexProduceTokError(hScriptLex, pTok, VERR_EOF, "Lexer: End of stream before closing string literal terminal");1149 return RTScriptLexProduceTokError(hScriptLex, pTok, VERR_EOF, "Lexer: End of stream before closing string literal terminal"); 1141 1150 else if (ch == '\'') 1142 1151 { … … 1153 1162 pTok->Type.StringLit.pszString = RTStrCacheEnterN(pThis->hStrCacheStringLit, pThis->pszStrLit, idxChCur); 1154 1163 if (RT_UNLIKELY(!pTok->Type.StringLit.pszString)) 1155 return rtScriptLexProduceTokError(hScriptLex, pTok, VERR_NO_STR_MEMORY, "Lexer: Error adding string literal to the cache");1164 return RTScriptLexProduceTokError(hScriptLex, pTok, VERR_NO_STR_MEMORY, "Lexer: Error adding string literal to the cache"); 1156 1165 else 1157 1166 break; … … 1164 1173 idxChCur++; 1165 1174 else 1166 return rtScriptLexProduceTokError(hScriptLex, pTok, rc, "Lexer: Error adding character to string literal");1175 return RTScriptLexProduceTokError(hScriptLex, pTok, rc, "Lexer: Error adding character to string literal"); 1167 1176 ch = RTScriptLexConsumeChEx(hScriptLex, RTSCRIPT_LEX_CONV_F_NOTHING); 1168 1177 }
Note:
See TracChangeset
for help on using the changeset viewer.