Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit badbd87

Browse files
author
Vincent Cantin
committed
Fixed the program so it can compile and run again.
1 parent 828fecf commit badbd87

File tree

3 files changed

+37
-55
lines changed

3 files changed

+37
-55
lines changed

‎build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ configurations {
99
}
1010

1111
dependencies {
12-
compile 'org.antlr:antlr4-runtime:4.1'
13-
antlr4 'org.antlr:antlr4:4.1'
12+
compile 'org.antlr:antlr4-runtime:4.5'
13+
antlr4 'org.antlr:antlr4:4.5'
1414
}
1515

1616
ext.antlr4GeneratedSourceDir = new File(buildDir, 'generated-sources/antlr4')
@@ -25,8 +25,8 @@ sourceSets {
2525

2626
task generateGrammarSource {
2727
ext.grammarFile = new File(projectDir, 'src/main/antlr4/Java.g4')
28-
ext.outputPackage = 'com.lemoulinstudio.sdiff.java.tree.lex'
29-
ext.outputDir = new File(antlr4GeneratedSourceDir, outputPackage.replace('.' as char, File.pathSeparatorChar))
28+
ext.outputPackage = 'com.lemoulinstudio.sdiff.java.tree.parser'
29+
ext.outputDir = new File(antlr4GeneratedSourceDir, outputPackage.replace('.' as char, File.separatorChar))
3030

3131
inputs.file grammarFile
3232
inputs.property 'outputPackage', outputPackage

‎src/main/antlr4/Java.g4

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -242,18 +242,10 @@ arrayInitializer
242242
: '{' (variableInitializer (',' variableInitializer)* (',')? )? '}'
243243
;
244244

245-
packageOrTypeName
246-
: qualifiedName
247-
;
248-
249245
enumConstantName
250246
: Identifier
251247
;
252248

253-
typeName
254-
: qualifiedName
255-
;
256-
257249
type
258250
: classOrInterfaceType ('[' ']')*
259251
| primitiveType ('[' ']')*
@@ -477,7 +469,7 @@ forInit
477469
;
478470

479471
enhancedForControl
480-
: variableModifier* type Identifier ':' expression
472+
: variableModifier* type variableDeclaratorId ':' expression
481473
;
482474

483475
forUpdate
@@ -528,19 +520,19 @@ expression
528520
| expression '&&' expression
529521
| expression '||' expression
530522
| expression '?' expression ':' expression
531-
| expression
532-
( '='<assoc=right>
533-
| '+='<assoc=right>
534-
| '-='<assoc=right>
535-
| '*='<assoc=right>
536-
| '/='<assoc=right>
537-
| '&='<assoc=right>
538-
| '|='<assoc=right>
539-
| '^='<assoc=right>
540-
| '>>='<assoc=right>
541-
| '>>>='<assoc=right>
542-
| '<<='<assoc=right>
543-
| '%='<assoc=right>
523+
| <assoc=right> expression
524+
( '='
525+
| '+='
526+
| '-='
527+
| '*='
528+
| '/='
529+
| '&='
530+
| '|='
531+
| '^='
532+
| '>>='
533+
| '>>>='
534+
| '<<='
535+
| '%='
544536
)
545537
expression
546538
;

‎src/main/java/com/lemoulinstudio/sdiff/Main.java

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,36 @@
11
package com.lemoulinstudio.sdiff;
22

3-
import com.lemoulinstudio.sdiff.parser.java.JavaLexer;
4-
import com.lemoulinstudio.sdiff.parser.java.JavaParser;
3+
import com.lemoulinstudio.sdiff.java.tree.parser.JavaBaseListener;
4+
import com.lemoulinstudio.sdiff.java.tree.parser.JavaLexer;
5+
import com.lemoulinstudio.sdiff.java.tree.parser.JavaParser;
56
import java.io.BufferedInputStream;
67
import java.io.File;
78
import java.io.FileInputStream;
8-
import java.io.FileNotFoundException;
99
import java.io.InputStream;
1010
import org.antlr.v4.runtime.ANTLRInputStream;
1111
import org.antlr.v4.runtime.BufferedTokenStream;
1212
import org.antlr.v4.runtime.CharStream;
13-
import org.antlr.v4.runtime.ParserRuleContext;
1413
import org.antlr.v4.runtime.TokenStream;
15-
import org.antlr.v4.runtime.tree.ErrorNode;
1614
import org.antlr.v4.runtime.tree.ParseTree;
17-
import org.antlr.v4.runtime.tree.ParseTreeListener;
1815
import org.antlr.v4.runtime.tree.TerminalNode;
1916

2017
public class Main {
2118

2219
public static void main(String[] args) throws Exception {
2320
String filename = "src/main/resources/Foobar.java";
2421
JavaParser javaParser = getParser(filename);
25-
22+
2623
String filename2 = "src/main/resources/Foobar2.java";
2724
JavaParser javaParser2 = getParser(filename2);
28-
25+
2926
// Future<JDialog> future = javaParser.compilationUnit().inspect(javaParser);
3027
// future.get().setVisible(true);
3128
ParseTree a = javaParser.compilationUnit();
3229
ParseTree b = javaParser2.compilationUnit();
33-
30+
3431
boolean r = isSimilar(a, b);
35-
36-
System.out.print("Is similar ? "+ Boolean.toString(r));
32+
33+
System.out.print("Is similar ? "+ Boolean.toString(r));
3734

3835
}
3936

@@ -56,37 +53,30 @@ private static boolean isSimilar(ParseTree nodeA, ParseTree nodeB) {
5653
return false;
5754
}
5855
}
59-
56+
6057
return true;
6158
}
62-
59+
6360
private static JavaParser getParser(String filename) throws Exception {
64-
InputStream inputStream = new BufferedInputStream(new FileInputStream(new File(filename)));
61+
InputStream inputStream = new BufferedInputStream(new FileInputStream(new File(filename)));
6562

6663
CharStream charStream = new ANTLRInputStream(inputStream);
6764

6865
JavaLexer javaLexer = new JavaLexer(charStream);
69-
66+
7067
TokenStream tokenStream = new BufferedTokenStream(javaLexer);
7168
JavaParser javaParser = new JavaParser(tokenStream);
7269

73-
javaParser.addParseListener(new ParseTreeListener() {
70+
javaParser.addParseListener(new JavaBaseListener() {
7471
@Override
7572
public void visitTerminal(TerminalNode node) {
76-
System.out.print(node.getText() + " ");
77-
}
78-
79-
@Override
80-
public void visitErrorNode(ErrorNode node) {
81-
}
82-
83-
@Override
84-
public void enterEveryRule(ParserRuleContext ctx) {
85-
}
86-
87-
@Override
88-
public void exitEveryRule(ParserRuleContext ctx) {
73+
// Interval sourceInterval = node.getSourceInterval();
74+
// System.out.println(
75+
// "[" + sourceInterval.a + ", " + sourceInterval.b + "] " +
76+
// "\"" + node.getText() + "\"");
77+
System.out.print(node.getText());
8978
}
79+
9080
});
9181

9282
javaParser.setBuildParseTree(true);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /