Package org.rascalmpl.interpreter.staticErrors

Examples of org.rascalmpl.interpreter.staticErrors.CommandlineError


      }
     
      AbstractFunction main = func.getFunctions().get(0);
     
      if (func.getFunctions().size() > 1) {
        throw new CommandlineError("should only have one main function", main);
      }
     
      if (main.getArity() == 1) {
        return func.call(getMonitor(), new Type[] { tf.listType(tf.stringType()) },new IValue[] { parsePlainCommandLineArgs(commandline)}, null).getValue();
      }
      else if (main.hasKeywordArgs() && main.getArity() == 0) {
        Map<String, IValue> args = parseKeywordCommandLineArgs(monitor, commandline, main);
        return func.call(getMonitor(), new Type[] { },new IValue[] {}, args).getValue();
      }
      else {
        throw new CommandlineError("main function should either have one argument of type list[str], or keyword parameters", main);
      }
    }
    finally {
      setMonitor(old);
      setCurrentEnvt(oldEnv);
View Full Code Here


    Map<String, IValue> params = new HashMap<String,IValue>();
   
    for (int i = 0; i < commandline.length; i++) {
      if (commandline[i].equals("-help")) {
        throw new CommandlineError("Help", func);
      }
      else if (commandline[i].startsWith("-")) {
        String label = commandline[i].replaceFirst("^-+", "");
        Type expected = expectedTypes.get(label);
       
        if (expected == null) {
          throw new CommandlineError("unknown argument: " + label, func);
        }
       
        if (expected.isSubtypeOf(tf.boolType())) {
          if (i == commandline.length - 1 || commandline[i+1].startsWith("-")) {
            params.put(label, vf.bool(true));
          }
          else if (i < commandline.length - 1) {
            String arg = commandline[++i].trim();
            if (arg.equals("1") || arg.equals("true")) {
              params.put(label, vf.bool(true));
            }
            else {
              params.put(label, vf.bool(false));
            }
          }
         
          continue;
        }
        else if (i == commandline.length - 1 || commandline[i+1].startsWith("-")) {
          throw new CommandlineError("expected option for " + label, func);
        }
        else if (expected.isSubtypeOf(tf.listType(tf.valueType()))) {
          IListWriter writer = vf.listWriter();
         
          while (i + 1 < commandline.length && !commandline[i+1].startsWith("-")) {
View Full Code Here

    else {
      StringReader reader = new StringReader(option);
      try {
        return new StandardTextReader().read(vf, expected, reader);
      } catch (FactTypeUseException e) {
        throw new CommandlineError("expected " + expected + " but got " + option + " (" + e.getMessage() + ")", main);
      } catch (IOException e) {
        throw new CommandlineError("unxped problem while parsing commandline:" + e.getMessage(), main);
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.rascalmpl.interpreter.staticErrors.CommandlineError

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.