1
0
blueloveTH 3 жил өмнө
parent
commit
5e1226b9ac
2 өөрчлөгдсөн 10 нэмэгдсэн , 20 устгасан
  1. 5 17
      src/compiler.h
  2. 5 3
      src/parser.h

+ 5 - 17
src/compiler.h

@@ -98,29 +98,17 @@ public:
     }
 
     _Str eatStringUntil(char quote, bool raw) {
-        bool quote3 = false;
-        std::string_view sv = parser->lookahead(2);
-        if(sv.size() == 2 && sv[0] == quote && sv[1] == quote) {
-            quote3 = true;
-            parser->eatchar();
-            parser->eatchar();
-        }
-
+        bool quote3 = parser->match_n_chars(2, quote);
         std::vector<char> buff;
         while (true) {
             char c = parser->eatchar_include_newLine();
             if (c == quote){
-                if(quote3){
-                    sv = parser->lookahead(2);
-                    if(sv.size() == 2 && sv[0] == quote && sv[1] == quote) {
-                        parser->eatchar();
-                        parser->eatchar();
-                        break;
-                    }
+                if(!quote3) break;
+                if(parser->match_n_chars(2, quote)) {
+                    break;
+                }else{
                     buff.push_back(c);
                     continue;
-                } else {
-                    break;
                 }
             }
             if (c == '\0'){

+ 5 - 3
src/parser.h

@@ -117,13 +117,15 @@ struct Parser {
 
     inline char peekchar() const{ return *curr_char; }
 
-    std::string_view lookahead(int n) const{
+    bool match_n_chars(int n, char c0){
         const char* c = curr_char;
         for(int i=0; i<n; i++){
-            if(*c == '\0') return std::string_view(curr_char, i);
+            if(*c == '\0') return false;
+            if(*c != c0) return false;
             c++;
         }
-        return std::string_view(curr_char, n);
+        for(int i=0; i<n; i++) eatchar_include_newLine();
+        return true;
     }
 
     int eat_spaces(){