mirror of
https://github.com/processing/processing4.git
synced 2026-01-30 11:51:54 +01:00
Fix nested type constructors raising error
Replace non-capturing groups by positive lookahead and lookbehind, because they don't consume the source String and allow for first and last group to overlap when two constructors are directly nested. Fixes #4652
This commit is contained in:
@@ -55,8 +55,12 @@ public class SourceUtils {
|
||||
|
||||
|
||||
|
||||
// Positive lookahead and lookbehind are needed to match all type constructors
|
||||
// in code like `int(byte(245))` where first bracket matches as last
|
||||
// group in "^int(" but also as a first group in "(byte(". Lookahead and
|
||||
// lookbehind won't consume the shared character.
|
||||
public static final Pattern TYPE_CONSTRUCTOR_REGEX =
|
||||
Pattern.compile("(?:^|\\W)(int|char|float|boolean|byte)(?:\\s*\\()",
|
||||
Pattern.compile("(?<=^|\\W)(int|char|float|boolean|byte)(?=\\s*\\()",
|
||||
Pattern.MULTILINE);
|
||||
|
||||
public static List<Edit> replaceTypeConstructors(CharSequence source) {
|
||||
|
||||
Reference in New Issue
Block a user