VirtualBox

Changeset 108280 in vbox


Ignore:
Timestamp:
Feb 19, 2025 9:28:41 AM (3 weeks ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
167622
Message:

Runtime/RTScriptLex*: Implement support for optionally returning parsed comments (single and multi line) as tokens when enabled in the lexer config, bugref:10321

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/script.h

    r108049 r108280  
    9898    /** Some punctuator. */
    9999    RTSCRIPTLEXTOKTYPE_PUNCTUATOR,
     100    /** A single line comment. */
     101    RTSCRIPTLEXTOKTYPE_COMMENT_SINGLE_LINE,
     102    /** A multi line comment. */
     103    RTSCRIPTLEXTOKTYPE_COMMENT_MULTI_LINE,
    100104    /** Special error token, conveying an error message from the lexer. */
    101105    RTSCRIPTLEXTOKTYPE_ERROR,
     
    212216            PCRTSCRIPTLEXTOKMATCH pPunctuator;
    213217        } Punctuator;
     218        /** Comment */
     219        struct
     220        {
     221            /** Pointer to the start of the comment (including the symbols starting the comment). */
     222            const char            *pszComment;
     223            /** Number of characters of the comment, including the null terminator. */
     224            size_t                cchComment;
     225        } Comment;
    214226        /** Error. */
    215227        struct
     
    316328 * as the lexer will convert everything to uppercase internally. */
    317329#define RTSCRIPT_LEX_CFG_F_CASE_INSENSITIVE_UPPER RT_BIT(1)
     330/** Comments are not skipped but passed back as tokens. */
     331#define RTSCRIPT_LEX_CFG_F_COMMENTS_AS_TOKENS     RT_BIT(2)
    318332
    319333
     
    369383 *                                 If not NULL the string cache must be freed by the caller when not used
    370384 *                                 anymore.
     385 * @param   phStrCacheComments     Where to store the pointer to the string cache containing all
     386 *                                 comments on success when RTSCRIPT_LEX_CFG_F_COMMENTS_AS_TOKENS
     387 *                                 is given, optional.
     388 *                                 If not NULL the string cache must be freed by the caller when not used
     389 *                                 anymore.
    371390 * @param   pCfg                   The lexer config to use for identifying the different tokens.
    372391 */
     
    374393                                        PFNRTSCRIPTLEXDTOR pfnDtor, void *pvUser,
    375394                                        size_t cchBuf, PRTSTRCACHE phStrCacheId, PRTSTRCACHE phStrCacheStringLit,
    376                                         PCRTSCRIPTLEXCFG pCfg);
     395                                        PRTSTRCACHE phStrCacheComments, PCRTSCRIPTLEXCFG pCfg);
    377396
    378397
     
    391410 *                                 If not NULL the string cache must be freed by the caller when not used
    392411 *                                 anymore.
     412 * @param   phStrCacheComments     Where to store the pointer to the string cache containing all
     413 *                                 comments on success when RTSCRIPT_LEX_CFG_F_COMMENTS_AS_TOKENS
     414 *                                 is given, optional.
     415 *                                 If not NULL the string cache must be freed by the caller when not used
     416 *                                 anymore.
    393417 * @param   pCfg                   The lexer config to use for identifying the different tokens.
    394418 */
    395419RTDECL(int) RTScriptLexCreateFromString(PRTSCRIPTLEX phScriptLex, const char *pszSrc, PRTSTRCACHE phStrCacheId,
    396                                         PRTSTRCACHE phStrCacheStringLit, PCRTSCRIPTLEXCFG pCfg);
     420                                        PRTSTRCACHE phStrCacheStringLit, PRTSTRCACHE phStrCacheComments,
     421                                        PCRTSCRIPTLEXCFG pCfg);
    397422
    398423
     
    411436 *                                 If not NULL the string cache must be freed by the caller when not used
    412437 *                                 anymore.
     438 * @param   phStrCacheComments     Where to store the pointer to the string cache containing all
     439 *                                 comments on success when RTSCRIPT_LEX_CFG_F_COMMENTS_AS_TOKENS
     440 *                                 is given, optional.
     441 *                                 If not NULL the string cache must be freed by the caller when not used
     442 *                                 anymore.
    413443 * @param   pCfg                   The lexer config to use for identifying the different tokens.
    414444 */
    415445RTDECL(int) RTScriptLexCreateFromFile(PRTSCRIPTLEX phScriptLex, const char *pszFilename, PRTSTRCACHE phStrCacheId,
    416                                       PRTSTRCACHE phStrCacheStringLit, PCRTSCRIPTLEXCFG pCfg);
     446                                      PRTSTRCACHE phStrCacheStringLit, PRTSTRCACHE phStrCacheComments,
     447                                      PCRTSCRIPTLEXCFG pCfg);
    417448
    418449
  • trunk/src/VBox/Disassembler/testcase/tstDisasmArmv8-1.cpp

    r108049 r108280  
    179179                                         NULL /*pfnDtor*/, &Rdr /*pvUser*/, cbSrc,
    180180                                         NULL /*phStrCacheId*/, NULL /*phStrCacheStringLit*/,
    181                                          &s_LexCfg);
     181                                         NULL /*phStrCacheComments*/, &s_LexCfg);
    182182    RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
    183183    if (RT_FAILURE(rc))
     
    233233                RTSCRIPTLEX hLexDis = NULL;
    234234                rc = RTScriptLexCreateFromString(&hLexDis, szOutput, NULL /*phStrCacheId*/,
    235                                                  NULL /*phStrCacheStringLit*/, &s_LexCfg);
     235                                                 NULL /*phStrCacheStringLit*/, NULL /*phStrCacheComments*/,
     236                                                 &s_LexCfg);
    236237                RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
    237238                if (RT_SUCCESS(rc))
     
    490491                                                 NULL /*pfnDtor*/, &Rdr /*pvUser*/, 0 /*cchBuf*/,
    491492                                                 NULL /*phStrCacheId*/, NULL /*phStrCacheStringLit*/,
    492                                                  &s_LexCfg);
     493                                                 NULL /*phStrCacheComments*/, &s_LexCfg);
    493494                RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
    494495
     
    496497                RTSCRIPTLEX hLexDis = NULL;
    497498                rc = RTScriptLexCreateFromString(&hLexDis, szOutput, NULL /*phStrCacheId*/,
    498                                                  NULL /*phStrCacheStringLit*/, &s_LexCfg);
     499                                                 NULL /*phStrCacheStringLit*/, NULL /*phStrCacheComments*/,
     500                                                 &s_LexCfg);
    499501                RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
    500502                if (RT_SUCCESS(rc))
  • trunk/src/VBox/Runtime/common/acpi/acpi-compiler.cpp

    r108235 r108280  
    29822982                                             NULL /*pfnDtor*/, pThis /*pvUser*/, 0 /*cchBuf*/,
    29832983                                             NULL /*phStrCacheId*/, NULL /*phStrCacheStringLit*/,
    2984                                              &s_AslLexCfg);
     2984                                             NULL /*phStrCacheComments*/, &s_AslLexCfg);
    29852985            if (RT_SUCCESS(rc))
    29862986            {
  • trunk/src/VBox/Runtime/common/script/scriptlex.cpp

    r108251 r108280  
    8282    /** String literal string cache. */
    8383    RTSTRCACHE           hStrCacheStringLit;
     84    /** Comment string cache. */
     85    RTSTRCACHE           hStrCacheComments;
    8486    /** Status code from the reader. */
    8587    int                  rcRdr;
     
    106108
    107109/** Free the identifier string cache literal on destruction. */
    108 #define RTSCRIPT_LEX_INT_F_STR_CACHE_ID_FREE      RT_BIT_32(0)
     110#define RTSCRIPT_LEX_INT_F_STR_CACHE_ID_FREE       RT_BIT_32(0)
    109111/** Free the string literal string cache literal on destruction. */
    110 #define RTSCRIPT_LEX_INT_F_STR_CACHE_STR_LIT_FREE RT_BIT_32(1)
     112#define RTSCRIPT_LEX_INT_F_STR_CACHE_STR_LIT_FREE  RT_BIT_32(1)
     113/** Free the comments string cache literal on destruction. */
     114#define RTSCRIPT_LEX_INT_F_STR_CACHE_COMMENTS_FREE RT_BIT_32(2)
    111115/** End of stream reached. */
    112 #define RTSCRIPT_LEX_INT_F_EOS                    RT_BIT_32(2)
     116#define RTSCRIPT_LEX_INT_F_EOS                     RT_BIT_32(3)
    113117
    114118
     
    267271
    268272
    269 DECLINLINE(bool) rtScriptLexIsNewlineConsume(PRTSCRIPTLEXINT pThis, char ch)
    270 {
    271     const char **papszNl = pThis->pCfg->pszWhitespace ? pThis->pCfg->papszNewline : g_aszNlDef;
    272 
    273     bool fMatched = rtScriptLexLocateSubStrInStrArrayMatchConsume(pThis, ch, papszNl, NULL);
     273DECLINLINE(bool) rtScriptLexIsNewlineConsumeEx(PRTSCRIPTLEXINT pThis, char ch, unsigned *pidx)
     274{
     275    const char **papszNl = pThis->pCfg->papszNewline ? pThis->pCfg->papszNewline : g_aszNlDef;
     276
     277    bool fMatched = rtScriptLexLocateSubStrInStrArrayMatchConsume(pThis, ch, papszNl, pidx);
    274278    if (fMatched)
    275279    {
     
    279283
    280284    return fMatched;
     285}
     286
     287
     288DECLINLINE(bool) rtScriptLexIsNewlineConsume(PRTSCRIPTLEXINT pThis, char ch)
     289{
     290    return rtScriptLexIsNewlineConsumeEx(pThis, ch, NULL);
     291}
     292
     293
     294/**
     295 * Checks whether the character is the beginning of a multi line comment.
     296 *
     297 * @returns Flag whether a comment was detected.
     298 * @param   hScriptLex             The lexer state.
     299 * @param   ch                     The character to check for.
     300 * @param   pidxMatch              Where to store the index of the matching substring if found,
     301 *                                 optional.
     302 * @note This consumes the start of the single line comment.
     303 */
     304DECLINLINE(bool) rtScriptLexIsMultiLineComment(PRTSCRIPTLEXINT pThis, char ch, unsigned *pidxMatch)
     305{
     306    const char **papszCommentMultiStart = pThis->pCfg->papszCommentMultiStart;
     307    if (   papszCommentMultiStart
     308        && rtScriptLexLocateSubStrInStrArrayMatchConsume(pThis, ch, papszCommentMultiStart, pidxMatch))
     309        return true;
     310
     311    return false;
    281312}
    282313
     
    292323DECLINLINE(bool) rtScriptLexIsMultiLineCommentConsume(PRTSCRIPTLEXINT pThis, char ch)
    293324{
    294     const char **papszCommentMultiStart = pThis->pCfg->papszCommentMultiStart;
    295325    unsigned idxComment = 0;
    296 
    297     if (   papszCommentMultiStart
    298         && rtScriptLexLocateSubStrInStrArrayMatchConsume(pThis, ch, papszCommentMultiStart,
    299                                                          &idxComment))
     326    if (rtScriptLexIsMultiLineComment(pThis, ch, &idxComment))
    300327    {
    301328        /* Look for the matching closing lexeme in the input consuming everything along the way. */
     
    327354
    328355/**
     356 * Checks whether the character is the beginning of a single line comment.
     357 *
     358 * @returns Flag whether a comment was detected.
     359 * @param   hScriptLex             The lexer state.
     360 * @param   ch                     The character to check for.
     361 * @param   pidxMatch              Where to store the index of the matching substring if found,
     362 *                                 optional.
     363 * @note This consumes the start of the single line comment.
     364 */
     365DECLINLINE(bool) rtScriptLexIsSingleLineComment(PRTSCRIPTLEXINT pThis, char ch, unsigned *pidxMatch)
     366{
     367    const char **papszCommentSingleStart = pThis->pCfg->papszCommentSingleStart;
     368    if (   papszCommentSingleStart
     369        && rtScriptLexLocateSubStrInStrArrayMatchConsume(pThis, ch, papszCommentSingleStart, pidxMatch))
     370        return true;
     371
     372    return false;
     373}
     374
     375
     376/**
    329377 * Checks whether the character is the beginning of a single line comment, skipping the whole
    330378 * comment if necessary.
     
    336384DECLINLINE(bool) rtScriptLexIsSingleLineCommentConsume(PRTSCRIPTLEXINT pThis, char ch)
    337385{
    338     const char **papszCommentSingleStart = pThis->pCfg->papszCommentSingleStart;
    339 
    340     if (   papszCommentSingleStart
    341         && rtScriptLexLocateSubStrInStrArrayMatchConsume(pThis, ch, papszCommentSingleStart,
    342                                                          NULL))
     386    if (rtScriptLexIsSingleLineComment(pThis, ch, NULL))
    343387    {
    344388        for (;;)
     
    457501    pTok->PosEnd = pThis->Pos;
    458502    return VINF_SUCCESS;
     503}
     504
     505
     506/**
     507 * Creates a single line comment token.
     508 *
     509 * @returns Flag whether a matching rule was found.
     510 * @param   pThis                  The lexer state.
     511 * @param   idxComment             The index into the single line comment token start array.
     512 * @param   pTok                   The token to fill.
     513 */
     514static void rtScriptLexProduceTokFromSingleLineComment(PRTSCRIPTLEXINT pThis, unsigned idxComment, PRTSCRIPTLEXTOKEN pTok)
     515{
     516    const char *pszCommentSingleStart = pThis->pCfg->papszCommentSingleStart[idxComment];
     517    AssertPtr(pszCommentSingleStart);
     518
     519    pTok->PosStart = pThis->Pos;
     520
     521    /** @todo Optimize */
     522    size_t cchTmp = 512;
     523    char *pszTmp = (char *)RTMemAlloc(cchTmp);
     524    if (pszTmp)
     525    {
     526        size_t cchComment = 0;
     527        while (*pszCommentSingleStart != '\0')
     528            pszTmp[cchComment++] = *pszCommentSingleStart++;
     529
     530        for (;;)
     531        {
     532            char chTmp = RTScriptLexGetCh(pThis);
     533
     534            if (   chTmp == '\0'
     535                || rtScriptLexIsNewlineConsume(pThis, chTmp))
     536            {
     537                pszTmp[cchComment++] = '\0';
     538                break;
     539            }
     540
     541            if (cchComment == cchTmp - 1)
     542            {
     543                char *pszNew = (char *)RTMemRealloc(pszTmp, cchTmp + 512);
     544                if (!pszNew)
     545                {
     546                    RTMemFree(pszTmp);
     547                    pszTmp = NULL;
     548                    RTScriptLexProduceTokError(pThis, pTok, VERR_NO_STR_MEMORY, "Lexer: Out of memory allocating temporary memory for a single line comment");
     549                    break;
     550                }
     551
     552                cchTmp += 512;
     553                pszTmp = pszNew;
     554            }
     555
     556            pszTmp[cchComment++] = chTmp;
     557            RTScriptLexConsumeCh(pThis);
     558        }
     559
     560        if (pszTmp)
     561        {
     562            pTok->enmType  = RTSCRIPTLEXTOKTYPE_COMMENT_SINGLE_LINE;
     563            pTok->PosEnd   = pThis->Pos;
     564            pTok->Type.Comment.pszComment = RTStrCacheEnterN(pThis->hStrCacheId, pszTmp, cchComment);
     565            pTok->Type.Comment.cchComment = cchComment;
     566            if (RT_UNLIKELY(!pTok->Type.Comment.pszComment))
     567                RTScriptLexProduceTokError(pThis, pTok, VERR_NO_STR_MEMORY, "Lexer: Out of memory inserting comment into comment cache");
     568
     569            RTMemFree(pszTmp);
     570        }
     571    }
     572    else
     573        RTScriptLexProduceTokError(pThis, pTok, VERR_NO_MEMORY, "Lexer: Out of memory allocating temporary memory for a single line comment");
     574}
     575
     576
     577/**
     578 * Ensures there is enough space in the given buffer for the given amount of bytes,
     579 * extending the buffer or creating an error token if this fails.
     580 *
     581 * @returns Flag whether there is enough space in the buffer.
     582 * @param   pThis                   The lexer state.
     583 * @param   ppchTmp                 Pointer to the pointer for the character buffer being checked.
     584 *                                  On successful return this might contain a different pointer if
     585 *                                  re-allocation was required.
     586 * @param   pcchTmp                 On input the size of the buffer in characters, on return the new
     587 *                                  size of the buffer if re-allocation was required.
     588 * @param   cchCur                  How much of the current buffer is used.
     589 * @param   cchAdd                  How many additional characters are required.
     590 * @param   pTok                    The token to fill in if re-allocating the buffer failed. 
     591 */
     592DECLINLINE(bool) rtScriptLexEnsureTmpBufSpace(PRTSCRIPTLEXINT pThis, char **ppchTmp, size_t *pcchTmp,
     593                                              size_t cchCur, size_t cchAdd, PRTSCRIPTLEXTOKEN pTok)
     594{
     595    if (RT_LIKELY(cchCur + cchAdd + 1 <= *pcchTmp)) /* Always keep room for the zero terminator. */
     596        return true;
     597
     598    size_t cchNew = *pcchTmp + _1K;
     599    char *pchNew = (char *)RTMemRealloc(*ppchTmp, cchNew);
     600    if (!pchNew)
     601    {
     602        RTMemFree(*ppchTmp);
     603        *ppchTmp = NULL;
     604        RTScriptLexProduceTokError(pThis, pTok, VERR_NO_STR_MEMORY, "Lexer: Out of memory allocating temporary memory for a multi line comment");
     605        return false;
     606    }
     607
     608    *ppchTmp = pchNew;
     609    *pcchTmp = cchNew;
     610    return true;
     611}
     612
     613
     614/**
     615 * Creates a multi line comment token.
     616 *
     617 * @returns Flag whether a matching rule was found.
     618 * @param   pThis                  The lexer state.
     619 * @param   idxComment             The index into the single line comment token start array.
     620 * @param   pTok                   The token to fill.
     621 */
     622static void rtScriptLexProduceTokFromMultiLineComment(PRTSCRIPTLEXINT pThis, unsigned idxComment, PRTSCRIPTLEXTOKEN pTok)
     623{
     624    const char *pszCommentMultiStart = pThis->pCfg->papszCommentMultiStart[idxComment];
     625    AssertPtr(pszCommentMultiStart);
     626
     627    pTok->PosStart = pThis->Pos;
     628
     629    /** @todo Optimize */
     630    size_t cchTmp = _1K;
     631    char *pszTmp = (char *)RTMemAlloc(cchTmp);
     632    if (pszTmp)
     633    {
     634        /* Look for the matching closing lexeme in the input consuming everything along the way. */
     635        const char *pszClosing = pThis->pCfg->papszCommentMultiEnd[idxComment];
     636
     637        size_t cchComment = 0;
     638        while (*pszCommentMultiStart != '\0')
     639            pszTmp[cchComment++] = *pszCommentMultiStart++;
     640
     641        for (;;)
     642        {
     643            char chTmp = RTScriptLexGetCh(pThis);
     644
     645            /* Check for new lines explicetly to advance the position information and copy it over. */
     646            unsigned idxNewLine = 0;
     647            if (rtScriptLexIsNewlineConsumeEx(pThis, chTmp, &idxNewLine))
     648            {
     649                const char *pszNl =   pThis->pCfg->papszNewline
     650                                    ? pThis->pCfg->papszNewline[idxNewLine]
     651                                    : g_aszNlDef[idxNewLine];
     652                if (!rtScriptLexEnsureTmpBufSpace(pThis, &pszTmp, &cchTmp, cchComment,
     653                                                  strlen(pszNl), pTok))
     654                    break;
     655
     656                while (*pszNl != '\0')
     657                    pszTmp[cchComment++] = *pszNl++;
     658                continue;
     659            }
     660
     661            /* Check for the closing lexeme. */
     662            if (rtScriptLexMatchStrConsume(pThis, chTmp, pszClosing, NULL))
     663            {
     664                /* Copy over the closing comment lexeme. */
     665                if (rtScriptLexEnsureTmpBufSpace(pThis, &pszTmp, &cchTmp, cchComment,
     666                                                 strlen(pszClosing), pTok))
     667                {
     668                    while (*pszClosing != '\0')
     669                        pszTmp[cchComment++] = *pszClosing++;
     670                    pszTmp[cchComment++] = '\0';
     671                }
     672                break;
     673            }
     674
     675            if (chTmp == '\0')
     676                break; /* End of stream before closing lexeme. */
     677
     678            if (!rtScriptLexEnsureTmpBufSpace(pThis, &pszTmp, &cchTmp, cchComment,
     679                                              strlen(pszClosing), pTok))
     680                break;
     681
     682            pszTmp[cchComment++] = chTmp;
     683            RTScriptLexConsumeCh(pThis);
     684        }
     685
     686        if (pszTmp)
     687        {
     688            pTok->enmType  = RTSCRIPTLEXTOKTYPE_COMMENT_MULTI_LINE;
     689            pTok->PosEnd   = pThis->Pos;
     690            pTok->Type.Comment.pszComment = RTStrCacheEnterN(pThis->hStrCacheId, pszTmp, cchComment);
     691            pTok->Type.Comment.cchComment = cchComment;
     692            if (RT_UNLIKELY(!pTok->Type.Comment.pszComment))
     693                RTScriptLexProduceTokError(pThis, pTok, VERR_NO_STR_MEMORY, "Lexer: Out of memory inserting comment into comment cache");
     694
     695            RTMemFree(pszTmp);
     696        }
     697    }
     698    else
     699        RTScriptLexProduceTokError(pThis, pTok, VERR_NO_MEMORY, "Lexer: Out of memory allocating temporary memory for a multi line comment");
    459700}
    460701
     
    542783    char ch = RTScriptLexGetCh(pThis);
    543784    PCRTSCRIPTLEXTOKMATCH pMatch = NULL;
     785    unsigned idxComment = 0;
    544786    if (ch == '\0')
    545787        rtScriptLexProduceTokEos(pThis, pTok);
     788    else if (  (pThis->pCfg->fFlags & RTSCRIPT_LEX_CFG_F_COMMENTS_AS_TOKENS)
     789             && rtScriptLexIsSingleLineComment(pThis, ch, &idxComment))
     790        rtScriptLexProduceTokFromSingleLineComment(pThis, idxComment, pTok);
     791    else if (  (pThis->pCfg->fFlags & RTSCRIPT_LEX_CFG_F_COMMENTS_AS_TOKENS)
     792             && rtScriptLexIsMultiLineComment(pThis, ch, &idxComment))
     793        rtScriptLexProduceTokFromMultiLineComment(pThis, idxComment, pTok);
    546794    else if (rtScriptLexLocateExactMatchConsume(pThis, ch, &pMatch))
    547795        rtScriptLexProduceTokFromExactMatch(pThis, pTok, pMatch);
     
    584832                                        PFNRTSCRIPTLEXDTOR pfnDtor, void *pvUser,
    585833                                        size_t cchBuf, PRTSTRCACHE phStrCacheId, PRTSTRCACHE phStrCacheStringLit,
    586                                         PCRTSCRIPTLEXCFG pCfg)
     834                                        PRTSTRCACHE phStrCacheComments, PCRTSCRIPTLEXCFG pCfg)
    587835{
    588836    AssertPtrReturn(phScriptLex, VERR_INVALID_POINTER);
     
    617865        pThis->hStrCacheId  = NULL;
    618866        pThis->hStrCacheStringLit  = NULL;
     867        pThis->hStrCacheComments   = NULL;
     868
     869        if (pCfg->fFlags & RTSCRIPT_LEX_CFG_F_COMMENTS_AS_TOKENS)
     870            rc = RTStrCacheCreate(&pThis->hStrCacheComments, "LEX-Comments");
    619871
    620872        rc = RTStrCacheCreate(&pThis->hStrCacheId, "LEX-Ide");
     
    639891                        pThis->fFlags |= RTSCRIPT_LEX_INT_F_STR_CACHE_STR_LIT_FREE;
    640892
     893                    if (pCfg->fFlags & RTSCRIPT_LEX_CFG_F_COMMENTS_AS_TOKENS)
     894                    {   
     895                        if (phStrCacheComments)
     896                            *phStrCacheComments = pThis->hStrCacheComments;
     897                        else
     898                            pThis->fFlags |= RTSCRIPT_LEX_INT_F_STR_CACHE_COMMENTS_FREE;
     899                    }
     900
    641901                    return VINF_SUCCESS;
    642902                }
     
    648908        }
    649909
     910        if (pThis->hStrCacheComments)
     911            RTStrCacheDestroy(pThis->hStrCacheComments);
    650912        RTMemFree(pThis);
    651913    }
     
    682944
    683945RTDECL(int) RTScriptLexCreateFromString(PRTSCRIPTLEX phScriptLex, const char *pszSrc, PRTSTRCACHE phStrCacheId,
    684                                         PRTSTRCACHE phStrCacheStringLit, PCRTSCRIPTLEXCFG pCfg)
     946                                        PRTSTRCACHE phStrCacheStringLit, PRTSTRCACHE phStrCacheComments, PCRTSCRIPTLEXCFG pCfg)
    685947{
    686948    return RTScriptLexCreateFromReader(phScriptLex, rtScriptLexReaderStr, NULL, (void *)pszSrc, 0,
    687                                        phStrCacheId, phStrCacheStringLit, pCfg);
     949                                       phStrCacheId, phStrCacheStringLit, phStrCacheComments, pCfg);
    688950}
    689951
     
    715977
    716978RTDECL(int) RTScriptLexCreateFromFile(PRTSCRIPTLEX phScriptLex, const char *pszFilename, PRTSTRCACHE phStrCacheId,
    717                                       PRTSTRCACHE phStrCacheStringLit, PCRTSCRIPTLEXCFG pCfg)
     979                                      PRTSTRCACHE phStrCacheStringLit, PRTSTRCACHE phStrCacheComments, PCRTSCRIPTLEXCFG pCfg)
    718980{
    719981    RTFILE hFile;
     
    722984    {
    723985        rc = RTScriptLexCreateFromReader(phScriptLex, rtScriptLexReaderFile, rtScriptLexDtorFile, (void *)hFile, 0,
    724                                          phStrCacheId, phStrCacheStringLit, pCfg);
     986                                         phStrCacheId, phStrCacheStringLit, phStrCacheComments, pCfg);
    725987        if (RT_FAILURE(rc))
    726988            RTFileClose(hFile);
     
    7431005    if (pThis->fFlags & RTSCRIPT_LEX_INT_F_STR_CACHE_STR_LIT_FREE)
    7441006        RTStrCacheDestroy(pThis->hStrCacheStringLit);
     1007    if (pThis->fFlags & RTSCRIPT_LEX_INT_F_STR_CACHE_COMMENTS_FREE)
     1008        RTStrCacheDestroy(pThis->hStrCacheComments);
    7451009
    7461010    if (pThis->pszStrLit)
     
    9021166
    9031167        if (   rtScriptLexLocateChInStrConsume(pThis, ch, pszWs)
    904             || rtScriptLexIsNewlineConsume(pThis, ch)
    905             || rtScriptLexIsMultiLineCommentConsume(pThis, ch)
    906             || rtScriptLexIsSingleLineCommentConsume(pThis, ch))
     1168            || rtScriptLexIsNewlineConsume(pThis, ch))
     1169            continue;
     1170
     1171        if (   !(pThis->pCfg->fFlags & RTSCRIPT_LEX_CFG_F_COMMENTS_AS_TOKENS)
     1172            && (   rtScriptLexIsMultiLineCommentConsume(pThis, ch)
     1173                || rtScriptLexIsSingleLineCommentConsume(pThis, ch)))
    9071174            continue;
    9081175
  • trunk/src/VBox/Runtime/testcase/tstRTAcpi.cpp

    r108115 r108280  
    164164                                         NULL /*pfnDtor*/, hVfsFileAslSrc /*pvUser*/, 0 /*cchBuf*/,
    165165                                         NULL /*phStrCacheId*/, NULL /*phStrCacheStringLit*/,
    166                                          &s_AslLexCfg);
     166                                         NULL /*phStrCacheComments*/, &s_AslLexCfg);
    167167    RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
    168168    if (RT_FAILURE(rc))
     
    173173                                     NULL /*pfnDtor*/, hVfsFileAslOut /*pvUser*/, 0 /*cchBuf*/,
    174174                                     NULL /*phStrCacheId*/, NULL /*phStrCacheStringLit*/,
    175                                      &s_AslLexCfg);
     175                                     NULL /*phStrCacheComments*/, &s_AslLexCfg);
    176176    RTTESTI_CHECK_RC(rc, VINF_SUCCESS);
    177177    if (RT_FAILURE(rc))
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette