From 6a716f96d3985a1baae0085756adf58c25e1acda Mon Sep 17 00:00:00 2001 From: Piotr Fusik Date: Thu, 21 Mar 2024 14:58:32 +0100 Subject: [PATCH] [fut] Update Java fut. --- Fut.java | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/Fut.java b/Fut.java index 2e168f3d..820a1ccf 100644 --- a/Fut.java +++ b/Fut.java @@ -30,9 +30,11 @@ import java.util.ArrayList; import java.util.Locale; -class FileResourceSema extends FuSema +class FileGenHost extends FuConsoleHost { private final ArrayList resourceDirs = new ArrayList(); + private File filename; + private FileWriter currentFile; public void addResourceDir(String path) { @@ -64,7 +66,7 @@ private ArrayList readResource(String name, FuPrefixExpr expr) File path = new File(name); if (path.isFile()) return readAllBytes(path); - reportError(expr, String.format("File %s not found", name)); + reportStatementError(expr, String.format("File %s not found", name)); return new ArrayList(); } @@ -77,12 +79,6 @@ private ArrayList readResource(String name, FuPrefixExpr expr) } return content.size(); } -} - -class FileGenHost extends FuConsoleHost -{ - private File filename; - private FileWriter currentFile; public @Override Appendable createFile(String directory, String filename) { @@ -135,21 +131,21 @@ private static void usage() System.out.println("--version Display version information"); } - private static FuProgram parseAndResolve(FuParser parser, FuSystem system, FuScope parent, ArrayList files, FileResourceSema sema, FuConsoleHost host) throws IOException + private static FuProgram parseAndResolve(FuParser parser, FuSystem system, FuScope parent, ArrayList files, FuSema sema, FuConsoleHost host) throws IOException { - parser.program = new FuProgram(); - parser.program.parent = parent; - parser.program.system = system; + host.program = new FuProgram(); + host.program.parent = parent; + host.program.system = system; for (String file : files) { byte[] input = Files.readAllBytes(Paths.get(file)); parser.parse(file, input, input.length); } if (host.hasErrors) System.exit(1); - sema.process(parser.program); + sema.process(); if (host.hasErrors) System.exit(1); - return parser.program; + return host.program; } private static void emit(FuProgram program, String lang, String namespace, String outputFile, FileGenHost host) @@ -207,10 +203,10 @@ private static void emit(FuProgram program, String lang, String namespace, Strin public static void main(String[] args) { Locale.setDefault(Locale.US); + final FileGenHost host = new FileGenHost(); final FuParser parser = new FuParser(); final ArrayList inputFiles = new ArrayList(); final ArrayList referencedFiles = new ArrayList(); - final FileResourceSema sema = new FileResourceSema(); String lang = null; String outputFile = null; String namespace = ""; @@ -249,7 +245,7 @@ else if (arg.length() == 2 && i + 1 < args.length) { referencedFiles.add(args[++i]); break; case 'I': - sema.addResourceDir(args[++i]); + host.addResourceDir(args[++i]); break; default: System.err.format("fut: ERROR: Unknown option: %s\n", arg); @@ -266,7 +262,7 @@ else if (arg.length() == 2 && i + 1 < args.length) { System.exit(1); } - final FileGenHost host = new FileGenHost(); + final FuSema sema = new FuSema(); parser.setHost(host); sema.setHost(host); final FuSystem system = FuSystem.new_();