]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Do not consider a READLINES block opening with fewer indents
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 26 Feb 2021 10:36:50 +0000 (10:36 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 26 Feb 2021 10:36:50 +0000 (10:36 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser/scanner.l

index 5b6ac0a7ee4e606683ccca80c7d4b2b3a2bc0701..373be3b796f24f03215a9e719b3b04861862954e 100644 (file)
@@ -231,19 +231,31 @@ scriptlet                         script(let)?
 <READLINES>.                   {
                                                        yyless(0);
 
+                                                       // This is the first line
                                                        if (!readline_indent) {
-                                                               readline_indent = current_indent;
-                                                               return T_INDENT;
+                                                               // If indentation is above indent level,
+                                                               // we are good to continue
+                                                               if (current_indent > indent_level) {
+                                                                       readline_indent = current_indent;
+                                                                       return T_INDENT;
+
+                                                               // If we found the same or less indentation we go back
+                                                               // to the previous state and continue parsing there
+                                                               } else {
+                                                                       yy_pop_state();
+                                                               }
                                                        }
 
                                                        // <-- ?
-                                                       if (current_indent < readline_indent) {
+                                                       else if (current_indent < readline_indent) {
                                                                readline_indent = 0;
                                                                yy_pop_state();
                                                                return T_OUTDENT;
-                                                       }
 
-                                                       yy_push_state(READLINE);
+                                                       // The indentation stayed the same, read the next line
+                                                       } else {
+                                                               yy_push_state(READLINE);
+                                                       }
                                                }
 
 <INDENT>\t                             { current_indent++; }