Skip to content

Commit 30358b5

Browse files
committed
fix: more parser fixes
Signed-off-by: Chao Wang <chaowan@redhat.com>
1 parent e8ea910 commit 30358b5

9 files changed

Lines changed: 102 additions & 87 deletions

File tree

src/main/gen/org/jboss/tools/intellij/componentanalysis/golang/build/lexer/GoModLexer.java

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,13 @@ private static int zzUnpackcmap_blocks(String packed, int offset, int [] result)
9797
private static final int [] ZZ_ACTION = zzUnpackAction();
9898

9999
private static final String ZZ_ACTION_PACKED_0 =
100-
"\1\0\1\1\1\2\1\3\1\1\1\4\1\5\1\1"+
101-
"\1\6\1\1\7\7\1\10\3\0\1\11\1\7\1\12"+
102-
"\3\7\3\6\13\7\1\6\7\7\1\13\2\7\1\14"+
103-
"\1\7\1\15\1\16\1\17";
100+
"\1\0\1\1\1\2\1\3\1\1\1\4\1\5\2\1"+
101+
"\1\6\1\1\7\7\1\0\1\10\3\0\1\11\1\7"+
102+
"\1\12\3\7\3\6\13\7\1\6\7\7\1\13\2\7"+
103+
"\1\14\1\7\1\15\1\16\1\17";
104104

105105
private static int [] zzUnpackAction() {
106-
int [] result = new int[57];
106+
int [] result = new int[59];
107107
int offset = 0;
108108
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
109109
return result;
@@ -130,15 +130,15 @@ private static int zzUnpackAction(String packed, int offset, int [] result) {
130130
private static final String ZZ_ROWMAP_PACKED_0 =
131131
"\0\0\0\37\0\76\0\37\0\135\0\37\0\37\0\174"+
132132
"\0\233\0\272\0\331\0\370\0\u0117\0\u0136\0\u0155\0\u0174"+
133-
"\0\u0193\0\u01b2\0\u01d1\0\u01f0\0\u020f\0\37\0\u022e\0\331"+
134-
"\0\u024d\0\u026c\0\u028b\0\u02aa\0\u01d1\0\u02c9\0\u02e8\0\u0307"+
133+
"\0\u0193\0\u01b2\0\u01d1\0\u01f0\0\u020f\0\u022e\0\u024d\0\37"+
134+
"\0\u026c\0\370\0\u028b\0\u02aa\0\u02c9\0\u02e8\0\u020f\0\u0307"+
135135
"\0\u0326\0\u0345\0\u0364\0\u0383\0\u03a2\0\u03c1\0\u03e0\0\u03ff"+
136136
"\0\u041e\0\u043d\0\u045c\0\u047b\0\u049a\0\u04b9\0\u04d8\0\u04f7"+
137-
"\0\u0516\0\331\0\u0535\0\u0554\0\331\0\u0573\0\331\0\331"+
138-
"\0\331";
137+
"\0\u0516\0\u0535\0\u0554\0\370\0\u0573\0\u0592\0\370\0\u05b1"+
138+
"\0\370\0\370\0\370";
139139

140140
private static int [] zzUnpackRowMap() {
141-
int [] result = new int[57];
141+
int [] result = new int[59];
142142
int offset = 0;
143143
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
144144
return result;
@@ -161,42 +161,44 @@ private static int zzUnpackRowMap(String packed, int offset, int [] result) {
161161
private static final int [] ZZ_TRANS = zzUnpacktrans();
162162

163163
private static final String ZZ_TRANS_PACKED_0 =
164-
"\1\2\1\3\1\4\1\5\1\6\1\7\3\2\1\10"+
165-
"\1\11\1\12\1\2\4\13\1\14\1\15\1\16\1\13"+
166-
"\1\17\4\13\1\20\2\13\1\21\1\13\40\0\1\3"+
167-
"\37\0\1\4\45\0\1\22\33\0\1\23\1\24\1\25"+
168-
"\1\0\1\11\40\0\1\26\31\0\4\13\2\0\22\13"+
169-
"\7\0\4\13\2\0\21\13\1\27\7\0\4\13\2\0"+
170-
"\12\13\1\30\7\13\7\0\4\13\2\0\11\13\1\31"+
171-
"\10\13\7\0\4\13\2\0\12\13\1\32\7\13\7\0"+
172-
"\4\13\2\0\4\13\1\33\15\13\7\0\3\13\1\34"+
173-
"\2\0\22\13\2\22\2\0\33\22\7\0\2\35\1\0"+
174-
"\1\35\2\0\22\35\7\0\2\36\1\0\1\36\2\0"+
175-
"\22\36\12\0\1\11\33\0\4\13\2\0\2\13\1\37"+
176-
"\17\13\7\0\4\13\2\0\3\13\1\40\16\13\7\0"+
177-
"\4\13\2\0\3\13\1\41\16\13\7\0\4\13\2\0"+
178-
"\13\13\1\42\1\43\5\13\6\0\1\23\1\44\1\21"+
179-
"\1\13\1\34\2\0\22\13\6\0\1\23\2\36\1\0"+
180-
"\1\36\2\0\22\36\7\0\4\13\2\0\7\13\1\45"+
181-
"\12\13\7\0\4\13\2\0\6\13\1\46\13\13\7\0"+
182-
"\4\13\2\0\17\13\1\47\2\13\7\0\4\13\2\0"+
183-
"\7\13\1\50\12\13\7\0\4\13\2\0\17\13\1\51"+
184-
"\2\13\7\0\2\52\1\13\1\52\2\0\22\52\7\0"+
185-
"\4\13\2\0\17\13\1\53\2\13\7\0\4\13\2\0"+
186-
"\15\13\1\54\4\13\7\0\4\13\2\0\7\13\1\55"+
187-
"\12\13\7\0\4\13\2\0\1\13\1\56\20\13\7\0"+
188-
"\4\13\2\0\6\13\1\57\13\13\6\0\1\23\2\52"+
189-
"\1\13\1\52\2\0\22\52\7\0\4\13\2\0\3\13"+
190-
"\1\60\16\13\7\0\4\13\2\0\4\13\1\61\15\13"+
191-
"\7\0\4\13\2\0\4\13\1\62\15\13\7\0\4\13"+
192-
"\2\0\2\13\1\63\17\13\7\0\4\13\2\0\15\13"+
193-
"\1\64\4\13\7\0\4\13\2\0\4\13\1\65\15\13"+
194-
"\7\0\4\13\2\0\2\13\1\66\17\13\7\0\4\13"+
195-
"\2\0\4\13\1\67\15\13\7\0\4\13\2\0\4\13"+
196-
"\1\70\15\13\7\0\4\13\2\0\16\13\1\71\3\13";
164+
"\1\2\1\3\1\4\1\5\1\6\1\7\2\2\1\10"+
165+
"\1\11\1\12\1\13\1\2\4\14\1\15\1\16\1\17"+
166+
"\1\14\1\20\4\14\1\21\2\14\1\22\1\14\40\0"+
167+
"\1\3\37\0\1\4\44\0\1\23\35\0\2\14\1\24"+
168+
"\1\14\2\0\22\14\6\0\1\25\1\26\1\27\1\0"+
169+
"\1\12\40\0\1\30\31\0\4\14\2\0\22\14\7\0"+
170+
"\4\14\2\0\21\14\1\31\7\0\4\14\2\0\12\14"+
171+
"\1\32\7\14\7\0\4\14\2\0\11\14\1\33\10\14"+
172+
"\7\0\4\14\2\0\12\14\1\34\7\14\7\0\4\14"+
173+
"\2\0\4\14\1\35\15\14\7\0\3\14\1\36\2\0"+
174+
"\22\14\11\0\1\14\25\0\2\24\2\0\33\24\7\0"+
175+
"\2\37\1\0\1\37\2\0\22\37\7\0\2\40\1\0"+
176+
"\1\40\2\0\22\40\12\0\1\12\33\0\4\14\2\0"+
177+
"\2\14\1\41\17\14\7\0\4\14\2\0\3\14\1\42"+
178+
"\16\14\7\0\4\14\2\0\3\14\1\43\16\14\7\0"+
179+
"\4\14\2\0\13\14\1\44\1\45\5\14\6\0\1\25"+
180+
"\1\46\1\22\1\14\1\36\2\0\22\14\6\0\1\25"+
181+
"\2\40\1\0\1\40\2\0\22\40\7\0\4\14\2\0"+
182+
"\7\14\1\47\12\14\7\0\4\14\2\0\6\14\1\50"+
183+
"\13\14\7\0\4\14\2\0\17\14\1\51\2\14\7\0"+
184+
"\4\14\2\0\7\14\1\52\12\14\7\0\4\14\2\0"+
185+
"\17\14\1\53\2\14\7\0\2\54\1\14\1\54\2\0"+
186+
"\22\54\7\0\4\14\2\0\17\14\1\55\2\14\7\0"+
187+
"\4\14\2\0\15\14\1\56\4\14\7\0\4\14\2\0"+
188+
"\7\14\1\57\12\14\7\0\4\14\2\0\1\14\1\60"+
189+
"\20\14\7\0\4\14\2\0\6\14\1\61\13\14\6\0"+
190+
"\1\25\2\54\1\14\1\54\2\0\22\54\7\0\4\14"+
191+
"\2\0\3\14\1\62\16\14\7\0\4\14\2\0\4\14"+
192+
"\1\63\15\14\7\0\4\14\2\0\4\14\1\64\15\14"+
193+
"\7\0\4\14\2\0\2\14\1\65\17\14\7\0\4\14"+
194+
"\2\0\15\14\1\66\4\14\7\0\4\14\2\0\4\14"+
195+
"\1\67\15\14\7\0\4\14\2\0\2\14\1\70\17\14"+
196+
"\7\0\4\14\2\0\4\14\1\71\15\14\7\0\4\14"+
197+
"\2\0\4\14\1\72\15\14\7\0\4\14\2\0\16\14"+
198+
"\1\73\3\14";
197199

198200
private static int [] zzUnpacktrans() {
199-
int [] result = new int[1426];
201+
int [] result = new int[1488];
200202
int offset = 0;
201203
offset = zzUnpacktrans(ZZ_TRANS_PACKED_0, offset, result);
202204
return result;
@@ -234,11 +236,11 @@ private static int zzUnpacktrans(String packed, int offset, int [] result) {
234236
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
235237

236238
private static final String ZZ_ATTRIBUTE_PACKED_0 =
237-
"\1\0\1\11\1\1\1\11\1\1\2\11\13\1\3\0"+
238-
"\1\11\43\1";
239+
"\1\0\1\11\1\1\1\11\1\1\2\11\13\1\1\0"+
240+
"\1\1\3\0\1\11\43\1";
239241

240242
private static int [] zzUnpackAttribute() {
241-
int [] result = new int[57];
243+
int [] result = new int[59];
242244
int offset = 0;
243245
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
244246
return result;

src/main/gen/org/jboss/tools/intellij/componentanalysis/golang/build/parser/GoModParser.java

Lines changed: 21 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/gen/org/jboss/tools/intellij/componentanalysis/golang/build/psi/GoModReplaceSpec.java

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/gen/org/jboss/tools/intellij/componentanalysis/golang/build/psi/impl/GoModReplaceSpecImpl.java

Lines changed: 0 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/org/jboss/tools/intellij/componentanalysis/golang/GoCAAnnotator.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import static org.jboss.tools.intellij.componentanalysis.CAUtil.EXHORT_IGNORE;
3232

3333
public class GoCAAnnotator extends CAAnnotator {
34-
private static final Pattern REQUIRE_PATTERN = Pattern.compile("^\\s*([a-zA-Z0-9._/-]+)\\s+(v?[0-9]+\\.[0-9]+\\.[0-9]+\\S*)(?:\\s*//.*)?$");
35-
private static final Pattern REPLACE_PATTERN = Pattern.compile("^\\s*([a-zA-Z0-9._/-]+)\\s*=>\\s*([a-zA-Z0-9._/-]+)\\s+(v?[0-9]+\\.[0-9]+\\.[0-9]+\\S*)(?:\\s*//.*)?$");
34+
public static final Pattern REQUIRE_PATTERN = Pattern.compile("^\\s*([a-zA-Z0-9._/-]+)\\s+(v?[0-9]+(?:\\.[0-9]+)*[0-9a-zA-Z\\-+._]*)(?:\\s*//.*)?$");
35+
public static final Pattern REPLACE_PATTERN = Pattern.compile("^\\s*([a-zA-Z0-9._/-]+)\\s+(?:(v?[0-9]+(?:\\.[0-9]+)*[0-9a-zA-Z\\-+._]*)\\s+)?=>\\s*([a-zA-Z0-9._/:-]+|\\.\\.?/[a-zA-Z0-9._/-]*|/[a-zA-Z0-9._/-]*)(?:\\s+(v?[0-9]+(?:\\.[0-9]+)*[0-9a-zA-Z\\-+._]*))?(?:\\s*//.*)?$");
3636

3737
@Override
3838
protected String getInspectionShortName() {
@@ -89,10 +89,13 @@ protected Map<Dependency, List<PsiElement>> getDependencies(PsiFile file) {
8989
} else if (inReplaceBlock) {
9090
Matcher replaceMatcher = REPLACE_PATTERN.matcher(line);
9191
if (replaceMatcher.matches()) {
92-
String targetPath = replaceMatcher.group(2);
93-
String version = replaceMatcher.group(3);
94-
Dependency dependency = createDependency(targetPath, version);
95-
resultMap.computeIfAbsent(dependency, k -> new LinkedList<>()).add(lineElement);
92+
String targetPath = replaceMatcher.group(3);
93+
String version = replaceMatcher.group(4) != null ? replaceMatcher.group(4) : replaceMatcher.group(2);
94+
// Only analyze if target is not a local path and has a version
95+
if (version != null && !targetPath.startsWith("./") && !targetPath.startsWith("../") && !targetPath.startsWith("/")) {
96+
Dependency dependency = createDependency(targetPath, version);
97+
resultMap.computeIfAbsent(dependency, k -> new LinkedList<>()).add(lineElement);
98+
}
9699
}
97100
} else {
98101
// Single line require/replace
@@ -109,10 +112,13 @@ protected Map<Dependency, List<PsiElement>> getDependencies(PsiFile file) {
109112
String replaceLine = line.substring(8).trim();
110113
Matcher replaceMatcher = REPLACE_PATTERN.matcher(replaceLine);
111114
if (replaceMatcher.matches()) {
112-
String targetPath = replaceMatcher.group(2);
113-
String version = replaceMatcher.group(3);
114-
Dependency dependency = createDependency(targetPath, version);
115-
resultMap.computeIfAbsent(dependency, k -> new LinkedList<>()).add(lineElement);
115+
String targetPath = replaceMatcher.group(3);
116+
String version = replaceMatcher.group(4) != null ? replaceMatcher.group(4) : replaceMatcher.group(2);
117+
// Only analyze if target is not a local path and has a version
118+
if (version != null && !targetPath.startsWith("./") && !targetPath.startsWith("../") && !targetPath.startsWith("/")) {
119+
Dependency dependency = createDependency(targetPath, version);
120+
resultMap.computeIfAbsent(dependency, k -> new LinkedList<>()).add(lineElement);
121+
}
116122
}
117123
}
118124
}
@@ -148,7 +154,7 @@ private PsiElement findElementAtLine(PsiFile file, int lineNumber) {
148154
String line = lines[lineNumber];
149155

150156
// Find version in the line using regex to get precise position
151-
Matcher versionMatcher = Pattern.compile("(v?[0-9]+\\.[0-9]+\\.[0-9]+\\S*)").matcher(line);
157+
Matcher versionMatcher = Pattern.compile("(v?[0-9]+(?:\\.[0-9]+)*[0-9a-zA-Z\\-+._]*)").matcher(line);
152158
if (versionMatcher.find()) {
153159
int versionStart = lineStartOffset + versionMatcher.start();
154160
int versionEnd = lineStartOffset + versionMatcher.end();

src/main/java/org/jboss/tools/intellij/componentanalysis/golang/GoCAIntentionAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.regex.Pattern;
2929

3030
public final class GoCAIntentionAction extends CAIntentionAction {
31-
private static final Pattern VERSION_PATTERN = Pattern.compile("(\\s+)(v?[0-9]+\\.[0-9]+\\.[0-9]+\\S*)");
31+
public static final Pattern VERSION_PATTERN = Pattern.compile("(\\s+)(v?[0-9]+\\.[0-9]+\\.[0-9]+\\S*)");
3232

3333
GoCAIntentionAction(PsiElement element, VulnerabilitySource source, DependencyReport report) {
3434
super(element, source, report);

src/main/java/org/jboss/tools/intellij/componentanalysis/golang/build/goMod.bnf

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,23 @@
1313
tokenTypeClass="org.jboss.tools.intellij.componentanalysis.golang.build.psi.GoModTokenType"
1414

1515
tokens=[
16-
COMMENT='regexp://.*'
17-
16+
COMMENT
17+
1818
MODULE='module'
1919
GO='go'
2020
REQUIRE='require'
2121
REPLACE='replace'
2222
EXCLUDE='exclude'
2323
INDIRECT='indirect'
24-
24+
2525
LPAREN='('
2626
RPAREN=')'
2727
ARROW='=>'
28-
29-
IDENTIFIER='regexp:[a-zA-Z_][a-zA-Z0-9_./\-]*'
30-
VERSION='regexp:v?[0-9]+(\.[0-9]+)*(\-[a-zA-Z0-9\-_.]+)?(\+[a-zA-Z0-9\-_.]+)?'
31-
32-
WHITESPACE='regexp:\s+'
33-
NEWLINE='regexp:\r?\n'
28+
29+
IDENTIFIER
30+
VERSION
31+
32+
NEWLINE
3433
]
3534
}
3635

@@ -54,7 +53,7 @@ replaceStatement ::= REPLACE (replaceSpec | replaceBlock)
5453

5554
replaceBlock ::= LPAREN (replaceSpec | COMMENT | NEWLINE)* RPAREN
5655

57-
replaceSpec ::= IDENTIFIER ARROW IDENTIFIER VERSION (COMMENT)*
56+
replaceSpec ::= IDENTIFIER VERSION? ARROW IDENTIFIER VERSION? (COMMENT)*
5857

5958
excludeStatement ::= EXCLUDE (excludeSpec | excludeBlock)
6059

src/main/java/org/jboss/tools/intellij/componentanalysis/golang/build/goMod.flex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ LPAREN = "("
3939
RPAREN = ")"
4040
ARROW = "=>"
4141

42-
// Identifiers and versions
43-
IDENTIFIER = [a-zA-Z_][a-zA-Z0-9_./\-]*
44-
VERSION = v?[0-9]+(\.[0-9]+)*(\-[a-zA-Z0-9\-_.]+)?(\+[a-zA-Z0-9\-_.]+)?
42+
// Identifiers and versions - VERSION must come before IDENTIFIER to avoid conflicts
43+
VERSION = v?[0-9]+(\.[0-9]+)*(-[0-9a-zA-Z\-_.]+)?(\+[0-9a-zA-Z\-_.]+)?
44+
IDENTIFIER = (\.\.\/[a-zA-Z0-9_\.\/\-]*|\/[a-zA-Z0-9_\.\/\-]+|[a-zA-Z_][a-zA-Z0-9_\.\/\-]*)
4545

4646
%%
4747

@@ -56,7 +56,7 @@ VERSION = v?[0-9]+(\.[0-9]+)*(\-[a-zA-Z0-9\-_.]+)?(\+[a-zA-Z0-9\-_.]+)?
5656
{REPLACE} { return GoModTypes.REPLACE; }
5757
{EXCLUDE} { return GoModTypes.EXCLUDE; }
5858
{INDIRECT} { return GoModTypes.INDIRECT; }
59-
59+
6060
{LPAREN} { return GoModTypes.LPAREN; }
6161
{RPAREN} { return GoModTypes.RPAREN; }
6262
{ARROW} { return GoModTypes.ARROW; }

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@
411411

412412
<change-notes><![CDATA[
413413
<p><b>1.2.0</b></p>
414-
<p>Go Plugin dependency removal. Golang projects now can be analyzed with IntelliJ Community Edition.</p>
414+
<p>Go Plugin dependency removal. Golang projects now can be analyzed with IntelliJ Community Edition (no longer requires Ultimate Edition).</p>
415415
<p>Add support for user-configurable patterns/globs for excluding manifests from Component Analysis.</p>
416416
<p><b>1.1.0</b></p>
417417
<p>Added support for Gradle manifest files.</p>

0 commit comments

Comments
 (0)