summaryrefslogtreecommitdiff
path: root/src/ParseAll.java
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2024-05-28 11:09:49 +0200
committerSanto Cariotti <santo@dcariotti.me>2024-05-28 11:11:06 +0200
commit4dc413b059983a1b50bd781fd88e0999044f66c8 (patch)
tree8e488b1e9c01a4de0f9304fd8b3cabb62d00bc6d /src/ParseAll.java
parent4de1659abf7fb73487632a8f3ee9d5febc5ee43e (diff)
Format
Diffstat (limited to 'src/ParseAll.java')
-rw-r--r--src/ParseAll.java26
1 files changed, 11 insertions, 15 deletions
diff --git a/src/ParseAll.java b/src/ParseAll.java
index 2a88afa..0d6f0d1 100644
--- a/src/ParseAll.java
+++ b/src/ParseAll.java
@@ -1,31 +1,28 @@
-import java.io.IOException;
import java.io.BufferedReader;
+import java.io.File;
import java.io.FileReader;
-import java.util.Objects;
+import java.io.IOException;
import java.util.Arrays;
-import java.io.File;
-
-import org.antlr.v4.runtime.*;
-import org.antlr.v4.gui.TreeViewer;
-
+import java.util.Objects;
import javax.swing.*;
-
+import org.antlr.v4.gui.TreeViewer;
+import org.antlr.v4.runtime.*;
public class ParseAll {
public static void main(String[] args) {
- for (File file: Objects.requireNonNull(new File("./progs").listFiles())) {
+ for (File file : Objects.requireNonNull(new File("./progs").listFiles())) {
String fileStr = file.getPath();
-// fileStr = "./progs/wrong.py";
+ // fileStr = "./progs/wrong.py";
try {
- if (!file.isFile() || !getExtension(file.getName()).equals("py")){
+ if (!file.isFile() || !getExtension(file.getName()).equals("py")) {
System.err.println("Wont parse: " + fileStr);
continue;
} else {
System.out.println(fileStr);
}
-// System.out.println(readFile(fileStr));
+ // System.out.println(readFile(fileStr));
CharStream cs = CharStreams.fromFileName(fileStr);
Python3Lexer lexer = new Python3Lexer(cs);
@@ -34,7 +31,7 @@ public class ParseAll {
Python3Parser.RootContext tree = parser.root();
String treeStr = tree.toStringTree();
-// System.out.println(treeStr);
+ // System.out.println(treeStr);
TreeViewer viewer = new TreeViewer(Arrays.asList(parser.getRuleNames()), tree);
viewer.setScale(1.5);
@@ -70,6 +67,7 @@ public class ParseAll {
frame.setSize(800, 600);
frame.setVisible(true);
}
+
private static void saveTree(TreeViewer viewer, String name) {
try {
viewer.save(name);
@@ -96,6 +94,4 @@ public class ParseAll {
return fileName.substring(extensionIndex + 1);
}
}
-
}
-