All Downloads are FREE. Search and download functionalities are using the official Maven repository.

beaver.comp.run.Make Maven / Gradle / Ivy

There is a newer version: 0.2.0
Show newest version
package beaver.comp.run;

import org.extendj.neobeaver.NeoBeaver;
import org.extendj.neobeaver.ProblemLogger;
import org.extendj.neobeaver.TraceHandler;

import java.io.IOException;
import java.nio.file.Paths;
import java.util.Collections;
import java.util.Set;

public class Make {
  public static void main(String[] args) throws IOException {
    System.out.println("Welcome to NeoBeaver classic frontend!");
    ProblemLogger problems = new ProblemLogger();

    String destDirName = "";
    String filename = "";

    for (int i = 0; i < args.length; ++i) {
      String arg = args[i];
      switch (arg) {
        case "-h":
          System.out.println("Usage: nbfront [OPTIONS] ");
          System.out.println("Options:");
          System.out.println("  -d     Generate parser in the named directory, DIR.");
          System.out.println("  -h          Print help and exit.");
          System.exit(0);
          return;
        case "-d":
          if (args.length > i + 1) {
            destDirName = args[i + 1];
            i += 1;
          } else {
            System.err.println("Error: missing path argument to -d option.");
          }
          break;
        case "-t":
          // Generate terminal names.
          // TODO: implement (always on right now).
          break;
        case "-c":
          // Suppress parsing table compression.
          // TODO: implement.
          break;
        case "-w":
          // Use switch to invoke reduce actions.
          // TODO: implement.
          break;
        default:
          if (arg.startsWith("-")) {
            problems.warnf("ignoring option '%s'. It is probably an unsupported Beaver flag.", arg);
          } else {
            if (filename.isEmpty()) {
              filename = arg;
            } else {
              problems.warnf("multiple filenames specified. Ignoring file: %s", arg);
            }
          }
      }
    }

    if (filename.isEmpty()) {
      problems.error("no parser specification filename specified!");
    }

    if (!problems.errored()) {
      TraceHandler trace = NeoBeaver.nullTrace();
      Set options = Collections.singleton("--beaver");
      NeoBeaver.process(trace, problems, filename, Paths.get(destDirName), options);
    }

    problems.report();
    if (problems.errored()) {
      System.exit(1);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy