From: Thomas Walker Lynch Date: Fri, 6 Sep 2024 15:38:48 +0000 (+0000) Subject: ah, missed the arg/opt parser for one of the files, adding it X-Git-Url: https://git.reasoningtechnology.com/fossil/style.css?a=commitdiff_plain;h=8d40b1ff3ce4d95faf840b21262d1a1099a30275;p=GQL-to-Cypher ah, missed the arg/opt parser for one of the files, adding it --- diff --git a/developer/javac/Synthesize_SyntaxAnnotate_PrintVisitor.java b/developer/javac/Synthesize_SyntaxAnnotate_PrintVisitor.java index 0c3bf7c..ae508b0 100644 --- a/developer/javac/Synthesize_SyntaxAnnotate_PrintVisitor.java +++ b/developer/javac/Synthesize_SyntaxAnnotate_PrintVisitor.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; import java.util.Arrays; +import java.util.ArrayList; import java.util.List; import java.io.PrintWriter; @@ -11,52 +12,57 @@ public class Synthesize_SyntaxAnnotate_PrintVisitor { // Constant for the usage message private static final String USAGE_MESSAGE = "Usage: Synthesize_SyntaxAnnotate_PrintVisitor" - +"[-version]" - +" [indentLevel]" + +" [-version]" + +" [indent-level (default 0)]" ; public static void main(String[] args) throws IOException { - if (args.length == 0) { + if (args.length == 0) { System.err.println(USAGE_MESSAGE); System.exit(1); } - - String grammarFilePath = null; - String outputFile = null; + boolean error = false; + boolean version = false; int indentLevel = 0; - - // Parse the arguments + List argList = new ArrayList<>(); for (int i = 0; i < args.length; i++) { String arg = args[i]; if (arg.startsWith("-")) { switch (arg) { case "-version": - System.out.println("Version 0.1"); - System.exit(0); + version = true; break; default: System.err.println("Unrecognized option: " + arg); - System.err.println(USAGE_MESSAGE); - System.exit(1); + error = true; } } else { - if (grammarFilePath == null) { - grammarFilePath = arg; - } else if (outputFile == null) { - outputFile = arg; - } else { - indentLevel = Integer.parseInt(arg); - } + argList.add(arg); } } - - // Ensure there are exactly two or three arguments - if (grammarFilePath == null || outputFile == null) { + if (version) { + System.out.println("Version 0.1"); + if (error) { + System.exit(1); + } else { + System.exit(0); + } + } + if (argList.size() < 2 || argList.size() > 3) { + System.err.println("Expected two or three non-option arguments."); + error = true; + } + if (error) { System.err.println(USAGE_MESSAGE); System.exit(1); } - // Extract the grammar name from the file name + String grammarFilePath = argList.get(0); + String outputFile = argList.get(1); + if (argList.size() == 3) { + indentLevel = Integer.parseInt(argList.get(2)); + } + String grammarName = Paths.get(grammarFilePath).getFileName().toString().replace(".g4", ""); String parserName = grammarName + "Parser"; String visitorClassName = grammarName + "_SyntaxAnnotate_PrintVisitor";