Răsfoiți Sursa

fix annotation detection with escape

Lyon 2 ani în urmă
părinte
comite
71670cd395
3 a modificat fișierele cu 23 adăugiri și 12 ștergeri
  1. 2 2
      port/linux/.vscode/launch.json
  2. 20 9
      src/PikaParser.c
  3. 1 1
      src/PikaVersion.h

+ 2 - 2
port/linux/.vscode/launch.json

@@ -22,11 +22,11 @@
                 // "--gtest_filter=VM.comprehension"
                 // "--gtest_filter=zlib.zlib1"
                 // "--gtest_filter=builtin.big_list"
-                // "--gtest_filter=parser.big_list"
                 // "--gtest_filter=VM.list_base"
                 // "--gtest_filter=vm.issue_dict_update"
                 // "--gtest_filter=builtin.tuple"
-                "--gtest_filter=pikaMain.num_issue1"
+                // "--gtest_filter=pikaMain.num_issue1"
+                "--gtest_filter=parser.byte_issue"
             ],
             "stopAtEntry": false,
             "cwd": "${workspaceFolder}",

+ 20 - 9
src/PikaParser.c

@@ -1995,12 +1995,24 @@ char* Parser_removeComment(char* sLine) {
     pika_bool bAnnotationExit = 0;
     pika_bool bInSingleQuotes = 0;
     pika_bool bInDoubleQuotesDeepth = 0;
+    pika_bool bPrevCharWasBackslash = 0;
+
     for (uint32_t i = 0; i < strGetSize(sLine); i++) {
-        if ('\'' == sLine[i]) {
+        if (bPrevCharWasBackslash) {
+            bPrevCharWasBackslash = 0;
+            continue;
+        }
+
+        if ('\\' == sLine[i]) {
+            bPrevCharWasBackslash = 1;
+            continue;
+        }
+
+        if ('\'' == sLine[i] && !bInDoubleQuotesDeepth) {
             bInSingleQuotes = !bInSingleQuotes;
             continue;
         }
-        if ('"' == sLine[i]) {
+        if ('"' == sLine[i] && !bInSingleQuotes) {
             bInDoubleQuotesDeepth = !bInDoubleQuotesDeepth;
             continue;
         }
@@ -2008,24 +2020,23 @@ char* Parser_removeComment(char* sLine) {
             continue;
         }
         if ('#' == sLine[i]) {
-            /* end the line */
             sLine[i] = 0;
             bAnnotationExit = 1;
             break;
         }
     }
-    /* no annotation, exit */
+
     if (!bAnnotationExit) {
         return sLine;
     }
-    /* check empty line */
+
     for (uint32_t i = 0; i < strGetSize(sLine); i++) {
         if (' ' != sLine[i]) {
             return sLine;
         }
     }
-    /* is an emply line */
-    sLine = "@annontation";
+
+    sLine = "@annotation";
     return sLine;
 }
 
@@ -2698,7 +2709,7 @@ char* parser_line2Target(Parser* self, char* sLine) {
         /* preprocess error */
         goto __exit;
     }
-    if (strEqu("@annontation", sLine)) {
+    if (strEqu("@annotation", sLine)) {
         sOut = "";
         goto __exit;
     }
@@ -2820,7 +2831,7 @@ char* parser_lines2Target(Parser* self, char* sPyLines) {
         if (bIsLineConnection) {
             if (bIsLineConnectionForBracket) {
                 sLine = Parser_removeComment(sLine);
-                if (strEqu(sLine, "@annontation")) {
+                if (strEqu(sLine, "@annotation")) {
                     sLine = "";
                 }
             }

+ 1 - 1
src/PikaVersion.h

@@ -2,4 +2,4 @@
 #define PIKA_VERSION_MINOR 12
 #define PIKA_VERSION_MICRO 4
 
-#define PIKA_EDIT_TIME "2023/08/01 13:16:15"
+#define PIKA_EDIT_TIME "2023/08/01 18:52:21"