package de.dhbwstuttgart.parser; import de.dhbwstuttgart.environment.CompilationEnvironment; import de.dhbwstuttgart.parser.SyntaxTreeGenerator.SyntaxTreeGenerator; import de.dhbwstuttgart.parser.antlr.Java17Lexer; import de.dhbwstuttgart.parser.antlr.Java17Parser; import de.dhbwstuttgart.parser.scope.JavaClassRegistry; import de.dhbwstuttgart.syntaxtree.SourceFile; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStreams; import org.antlr.v4.runtime.CommonTokenStream; import java.io.*; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; public class JavaTXParser { public static Java17Parser.SourceFileContext parse(File source) throws IOException, java.lang.ClassNotFoundException { InputStream stream = new FileInputStream(source); // DEPRECATED: ANTLRInputStream input = new ANTLRInputStream(stream); CharStream input = CharStreams.fromStream(stream); Java17Lexer lexer = new Java17Lexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); Java17Parser parser = new Java17Parser(tokens); return parser.sourceFile(); /* * SyntaxTreeGenerator generator = new SyntaxTreeGenerator(environment.getRegistry(source)); return generator.convert(tree); */ } /* * Für das Typsystem ist es notwendig, dass sich der Source in einer Datei befindet: public SourceFile parse(String fileContent) throws IOException, java.lang.ClassNotFoundException { return this.parse(new ByteArrayInputStream(fileContent.getBytes(StandardCharsets.UTF_8))); } */ }