drccrd commented on code in PR #4083:
URL: 
https://github.com/apache/incubator-kie-tools/pull/4083#discussion_r4662849238


##########
packages/drools-lsp/drools-completion/src/main/java/org/drools/completion/DRLLintHelper.java:
##########
@@ -101,17 +104,85 @@ public final class DRLLintHelper {
             
Pattern.compile("(?<![\\w.$])([A-Z][A-Za-z0-9_$]*(?:\\.[A-Za-z0-9_$]+)+)");
 
     private static final Pattern RULE_KEYWORD =
-            Pattern.compile("^\\s*(rule|query)\\b", Pattern.CASE_INSENSITIVE);
+            Pattern.compile("^\\s*(rule|query)\\b");
     private static final Pattern DECLARE_KEYWORD =
-            Pattern.compile("^\\s*declare\\b", Pattern.CASE_INSENSITIVE);
+            Pattern.compile("^\\s*declare\\b");
     private static final Pattern END_AT_START =
-            Pattern.compile("^end\\b", Pattern.CASE_INSENSITIVE);
+            Pattern.compile("^end\\b");
     private static final Pattern END_AT_END =
-            Pattern.compile("(?:^|\\s)end$", Pattern.CASE_INSENSITIVE);
+            Pattern.compile("(?:^|\\s)end$");
     private static final Pattern WHEN_KEYWORD =
-            Pattern.compile("^\\s*when\\b", Pattern.CASE_INSENSITIVE);
+            Pattern.compile("^\\s*when\\b");
     private static final Pattern THEN_KEYWORD =
-            Pattern.compile("^\\s*then\\b", Pattern.CASE_INSENSITIVE);
+            Pattern.compile("^\\s*then\\b");
+
+    /** Represents a scanned rule or query block and whether it was properly 
closed. */
+    public static final class RuleBlock {
+        public final int startLine;
+        public final int endLine; // -1 if unclosed
+        public final int startCol;
+        public final boolean isQuery;
+
+        public RuleBlock(int startLine, int endLine, int startCol, boolean 
isQuery) {
+            this.startLine = startLine;
+            this.endLine = endLine;
+            this.startCol = startCol;
+            this.isQuery = isQuery;
+        }
+
+        public boolean isClosed() {
+            return endLine >= 0;
+        }
+    }
+
+    /**
+     * Scans {@code sanitized} text for rule and query blocks, tracking 
unclosed rules
+     * with a stack so unclosed rules do not prematurely swallow subsequent 
blocks.
+     */
+    public static List<RuleBlock> scanRuleBlocks(String sanitized) {
+        String[] lines = sanitized.split("\r?\n", -1);
+        List<RuleBlock> completed = new ArrayList<>();
+        List<RuleBlock> openRules = new ArrayList<>();
+        boolean inDeclare = false;
+
+        for (int i = 0; i < lines.length; i++) {
+            String raw = lines[i];
+            String trimmed = raw.trim();
+            if (trimmed.isEmpty()) {
+                continue;
+            }
+
+            Matcher rm = RULE_KEYWORD.matcher(trimmed);
+            if (rm.find()) {
+                inDeclare = false;

Review Comment:
   the special handling for `declare` was moved here from `lintMissingRuleEnds' 
but the corresponding javadoc comment was not



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to