This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 0f7be0c3871bb4cda314b9abb424561233bdb893
Author: Paul King <[email protected]>
AuthorDate: Mon Aug 4 10:23:31 2025 +1000

    GROOVY-8162: Update Groovysh to JLine3 (tweak types regex)
---
 .../groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java    | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git 
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
 
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
index 109fe5a698..7aeda02138 100644
--- 
a/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
+++ 
b/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/jline/GroovyEngine.java
@@ -116,10 +116,10 @@ public class GroovyEngine implements ScriptEngine {
     private static final String BODY = "\\s*(.*?\\{.*?})(|;|\n)$";
     private static final String PARAMS = "\\(([\\p{L}\\p{N}_ ,]*)\\)";
     private static final Pattern PATTERN_METHOD_DEF = Pattern.compile(
-            "(?ms)" + ANNOTATIONS + MODIFIERS + "(?!record)" + REGEX_VAR + 
"\\s+(" + METHOD_REGEX_VAR + "\\s*" + PARAMS + ")" + BODY);
+            "(?ms)" + ANNOTATIONS + MODIFIERS + "(?!record\\s+)" + REGEX_VAR + 
"\\s+(" + METHOD_REGEX_VAR + "\\s*" + PARAMS + ")" + BODY);
     private static final Pattern PATTERN_VAR_DEF = Pattern.compile("^\\s*" + 
ANNOTATIONS + BASE_REGEX_VAR + "\\s+" + REGEX_VAR + "\\s*=[^=~].*");
     private static final Pattern PATTERN_TYPE_DEF =
-            Pattern.compile("(?ms)" + ANNOTATIONS + MODIFIERS + 
"((?:\\bclass|@?\\binterface|\\benum|\\btrait)\\s+" + REGEX_VAR + 
"|(?:\\brecord\\s+" + REGEX_VAR + "\\s*" + PARAMS + "))" + BODY);
+            Pattern.compile("(?ms)" + ANNOTATIONS + MODIFIERS + 
"((?:\\bclass|@?\\binterface|\\benum|\\btrait)(?:\\s+)" + REGEX_VAR + 
"|(?:\\brecord)(?:\\s+)" + REGEX_VAR + "\\s*" + PARAMS + ")" + BODY);
     private static final String REGEX_CLASS = "(.*?)\\.([A-Z_].*)";
     private static final Pattern PATTERN_CLASS = Pattern.compile(REGEX_CLASS);
     private static final String REGEX_PACKAGE = "([a-z][a-z_0-9]*\\.)*";
@@ -437,8 +437,9 @@ public class GroovyEngine implements ScriptEngine {
             classLoader.purgeClassCache();
             Matcher matcher = PATTERN_TYPE_DEF.matcher(statement);
             if (matcher.matches()) {
-                types.put(matcher.group(2), addSnippet(SnippetType.TYPE, 
removeTrailingSemi(matcher.group(0))));
-                addToNameClass(matcher.group(2));
+                String name = matcher.group(2) != null ? matcher.group(2) : 
matcher.group(3);
+                types.put(name, addSnippet(SnippetType.TYPE, 
removeTrailingSemi(matcher.group(0))));
+                addToNameClass(name);
             }
             matcher = PATTERN_VAR_DEF.matcher(statement);
             if (matcher.matches()) {

Reply via email to