예제 #1
0
  @Override
  protected IStatus run(IProgressMonitor monitor) {
    monitor.beginTask("Parsing", 105);

    try {
      handler.clearMessages();

      IGTD<IConstructor, IConstructor, ISourceLocation> gtd = new ClojureParser();
      parseTree =
          (IConstructor)
              gtd.parse(
                  START_SORT,
                  URI.create(path.toString()),
                  input.toCharArray(),
                  new DefaultNodeFlattener<IConstructor, IConstructor, ISourceLocation>(),
                  new UPTRNodeFactory());

    } catch (ParseError pe) {
      int offset = pe.getOffset();
      if (offset == input.length()) --offset;

      handler.handleSimpleMessage(
          "parse error",
          offset,
          offset + pe.getLength(),
          pe.getBeginColumn(),
          pe.getEndColumn(),
          pe.getBeginLine() + 1,
          pe.getEndLine() + 1);
    } catch (Throw e) {
      IValue exc = e.getException();

      if (exc.getType() == RuntimeExceptionFactory.Exception) {
        if (((IConstructor) exc).getConstructorType() == RuntimeExceptionFactory.ParseError) {
          ISourceLocation loc = (ISourceLocation) ((IConstructor) e.getException()).get(0);
          handler.handleSimpleMessage(
              "parse error: " + loc,
              loc.getOffset(),
              loc.getOffset() + loc.getLength(),
              loc.getBeginColumn(),
              loc.getEndColumn(),
              loc.getBeginLine(),
              loc.getEndLine());
        } else {
          Activator.getInstance().logException(e.getMessage(), e);
        }
      }
    } catch (Throwable e) {
      Activator.getInstance().logException("parsing failed: " + e.getMessage(), e);
    } finally {
      monitor.done();
    }

    return Status.OK_STATUS;
  }
예제 #2
0
  private void runTests(ModuleEnvironment env, List<AbstractFunction> tests) {
    testResultListener.start(tests.size());

    //		try {
    for (int i = tests.size() - 1; i >= 0; i--) {
      AbstractFunction test = tests.get(i);

      try {
        QuickCheck qc = QuickCheck.getInstance();
        StringWriter sw = new StringWriter();
        PrintWriter out = new PrintWriter(sw);
        int maxDepth = Cobra.readIntTag(test, Cobra.MAXDEPTH, 5);
        int tries = Cobra.readIntTag(test, Cobra.TRIES, 200);

        boolean result = qc.quickcheck(test, maxDepth, tries, false, out);
        if (!result) {
          out.flush();
          testResultListener.report(
              false, test.getName(), test.getAst().getLocation(), sw.getBuffer().toString(), null);
        } else {
          testResultListener.report(
              true, test.getName(), test.getAst().getLocation(), sw.getBuffer().toString(), null);
        }
      } catch (StaticError e) {
        testResultListener.report(
            false, test.getName(), test.getAst().getLocation(), e.getMessage(), e);
      } catch (Throw e) {
        testResultListener.report(
            false, test.getName(), test.getAst().getLocation(), e.getMessage(), e);
      } catch (Throwable e) {
        testResultListener.report(
            false, test.getName(), test.getAst().getLocation(), e.getMessage(), e);
      }
    }
    //		}
    //		finally {
    testResultListener.done();
    //		}
  }