Package org.openntf.formula

Examples of org.openntf.formula.ASTNode


    //    doc.put("mime1", map);

  }

  private ASTNode parse(final String line) throws FormulaParseException {
    ASTNode ast = null;
    if (cacheAST)
      ast = astCache.get(line);

    FormulaParser parser = Formulas.getParser();
    if (ast == null) {
View Full Code Here


        System.out.println(LOTUS("Lotus failed: ") + ERROR(e));
        i = count;
      }

      // benchmark the AtFormulaParser
      ASTNode ast = null;
      try {
        time = System.nanoTime();
        ast = parse(line);
        parseTime += System.nanoTime() - time;
      } catch (FormulaParseException e) {
        System.out.println(NTF("Parser failed: ") + ERROR(e));
        e.printStackTrace();
        break;
      }
      // benchmark the evaluate with a document as context

      try {
        time = System.nanoTime();
        FormulaContext ctx1 = Formulas.createContext(ntfDoc, Formulas.getParser());
        ntfDocResult = ast.solve(ctx1);
        docEvaluateTime += System.nanoTime() - time;
      } catch (Exception e) {
        System.out.println(NTF("Doc-Evaluate failed: ") + ERROR(e));
        e.printStackTrace();
        i = count;
      }
      try {
        // benchmark the evaluate with a map as context
        time = System.nanoTime();
        FormulaContext ctx2 = Formulas.createContext(ntfMap, Formulas.getParser());
        ntfMapResult = ast.solve(ctx2);
        mapEvaluateTime += System.nanoTime() - time;
      } catch (Exception e) {
        System.out.println(NTF("Map-Evaluate failed: ") + ERROR(e));
        e.printStackTrace();
        i = count;
View Full Code Here

    //    doc.put("mime1", map);

  }

  private ASTNode parse(final String line) throws FormulaParseException {
    ASTNode ast = null;
    if (cacheAST)
      ast = astCache.get(line);

    FormulaParser parser = Formulas.getParser();
    if (ast == null) {
View Full Code Here

        System.out.println(LOTUS("Lotus failed: ") + ERROR(e));
        i = count;
      }

      // benchmark the AtFormulaParser
      ASTNode ast = null;
      try {
        time = System.nanoTime();
        ast = parse(line);
        parseTime += System.nanoTime() - time;
      } catch (FormulaParseException e) {
        System.out.println(NTF("Parser failed: ") + ERROR(e));
        e.printStackTrace();
        break;
      }
      // benchmark the evaluate with a document as context

      try {
        time = System.nanoTime();
        FormulaContext ctx1 = Formulas.createContext(ntfDoc, Formulas.getParser());
        ntfDocResult = ast.solve(ctx1);
        docEvaluateTime += System.nanoTime() - time;
      } catch (Exception e) {
        System.out.println(NTF("Doc-Evaluate failed: ") + ERROR(e));
        e.printStackTrace();
        i = count;
      }
      try {
        // benchmark the evaluate with a map as context
        time = System.nanoTime();
        FormulaContext ctx2 = Formulas.createContext(ntfMap, Formulas.getParser());
        ntfMapResult = ast.solve(ctx2);
        mapEvaluateTime += System.nanoTime() - time;
      } catch (Exception e) {
        System.out.println(NTF("Map-Evaluate failed: ") + ERROR(e));
        e.printStackTrace();
        i = count;
View Full Code Here

        System.err.println(ERROR("FATAL") + LOTUS("\tLotus failed: ") + ERROR(t));
      }
    }

    // benchmark the AtFormulaParser
    ASTNode ast = null;
    FormulaParser parser = Formulas.getParser();
    try {
      ast = parser.parse(line);
    } catch (FormulaParseException e) {
      errors.append(NTF("\tParser failed: ") + ERROR(e) + "\n");
      e.printStackTrace();
      parserFailed = true;
    } catch (Throwable t) {
      System.err.println(ERROR("FATAL") + NTF("\tParser failed: ") + ERROR(t));
      t.printStackTrace();
    }

    if (!parserFailed) {
      if (testDoc) {
        try {
          FormulaContext ctx1 = Formulas.createContext(ntfDoc, parser);
          ntfDocResult = ast.solve(ctx1);
        } catch (EvaluateException e) {
          errors.append(NTF("\tDoc-Evaluate failed: ") + ERROR(e) + "\n");
          ntfError = e;
          parserFailed = true;
        } catch (Throwable t) {
          System.err.println(ERROR("FATAL") + NTF("\tDoc-Evaluate failed: ") + ERROR(t));
          t.printStackTrace();
        }
      }
      if (testMap) {
        try {
          // benchmark the evaluate with a map as context
          FormulaContext ctx2 = Formulas.createContext(ntfMap, parser);
          ntfMapResult = ast.solve(ctx2);
        } catch (EvaluateException e) {
          errors.append(NTF("\tMap-Evaluate failed: ") + ERROR(e) + "\n");
          ntfError = e;
          parserFailed = true;
        } catch (Throwable t) {
          System.err.println(ERROR("FATAL") + NTF("\tMap-Evaluate failed: ") + ERROR(t));
          t.printStackTrace();
        }
      }
    }

    if (lotusFailed && parserFailed) {
      System.out.println(SUCCESS() + dump(line + " = UNDEFINED"));

      return;
    }

    if (testLotus && testDoc) {
      if (compareList(ntfDocResult, lotusResult)) {
        System.out.println(SUCCESS() + line + " = " + dump(ntfDocResult));
      } else {
        System.err.println(FAIL() + NTF("DOC:") + line);
        System.err.println("\tResult:   " + dump(ntfDocResult) + " Size: " + ((ntfDocResult == null) ? 0 : ntfDocResult.size()));
        System.err.println("\tExpected: " + dump(lotusResult) + " Size: " + ((lotusResult == null) ? 0 : lotusResult.size()));
        if (parserFailed || lotusFailed) {
          System.err.println(errors.toString());
          if (ntfError != null) {
            ntfError.printStackTrace(System.err);
          }
        }
        BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
        try {
          console.readLine();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }

      }
    } else {
      if (parserFailed) {
        ntfError.printStackTrace();
      }
      System.err.println("\tDocResult:   " + dump(ntfDocResult) + " Size: " + ((ntfDocResult == null) ? 0 : ntfDocResult.size()));
      System.err.println("\tMapResult:   " + dump(ntfMapResult) + " Size: " + ((ntfMapResult == null) ? 0 : ntfMapResult.size()));
    }
    System.out.println(NTF("Read fields\t") + ast.getReadFields());
    System.out.println(NTF("Modified fields\t") + ast.getModifiedFields());
    System.out.println(NTF("Variables\t") + ast.getVariables());
    System.out.println(NTF("Functions\t") + ast.getFunctions());

  }
View Full Code Here

    Map<String, Object> ntfMap = new HashMap<String, Object>();

    fillDemoDoc(ntfMap, rnd);

    // benchmark the AtFormulaParser
    ASTNode ast = null;
    FormulaParser parser = Formulas.getParser();
    try {
      ast = parser.parse(line);
    } catch (FormulaParseException e) {
      errors.append(NTF("\tParser failed: ") + ERROR(e) + "\n");
      e.printStackTrace();
      parserFailed = true;
    } catch (Throwable t) {
      System.err.println(ERROR("FATAL") + NTF("\tParser failed: ") + ERROR(t));
      t.printStackTrace();
    }

    if (!parserFailed) {
      try {
        // benchmark the evaluate with a map as context
        FormulaContext ctx2 = Formulas.createContext(ntfMap, parser);
        ntfMapResult = ast.solve(ctx2);
      } catch (EvaluateException e) {
        errors.append(NTF("\tMap-Evaluate failed: ") + ERROR(e) + "\n");
        ntfError = e;
        parserFailed = true;
      } catch (Throwable t) {
        System.err.println(ERROR("FATAL") + NTF("\tMap-Evaluate failed: ") + ERROR(t));
        t.printStackTrace();
      }
    }

    if (parserFailed) {
      ntfError.printStackTrace();
    }
    System.err.println("\tMapResult:   " + dump(ntfMapResult) + " Size: " + ((ntfMapResult == null) ? 0 : ntfMapResult.size()));
    System.out.println(NTF("Read fields\t") + ast.getReadFields());
    System.out.println(NTF("Modified fields\t") + ast.getModifiedFields());
    System.out.println(NTF("Variables\t") + ast.getVariables());
    System.out.println(NTF("Functions\t") + ast.getFunctions());

  }
View Full Code Here

        // TODO Auto-generated method stub
        return null;
      }

    });
    ASTNode x = p.parse(System.in, true);
    FormulaContext ctx = Formulas.createContext(null, p);

    ctx.setParameterProvider(new FormulaProvider<String>() {

      public String get(final String key) {
        return args[Integer.valueOf(key)];
      }
    });

    List<Object> ret = x.solve(ctx);
    System.out.println(ret);
  }
View Full Code Here

  }

  public void processFormula() {
    try {
      String passedFormula = (String) ExtLibUtil.getViewScope().get("javaFormula");
      ASTNode ast = null;

      ast = Formulas.getParser().parse(passedFormula);
      FormulaContext ctx1 = Formulas.createContext(null, Formulas.getParser());
      List<Object> result = ast.solve(ctx1);
      ExtLibUtil.getViewScope().put("javaTest", result);
    } catch (Throwable t) {
      XspOpenLogUtil.logError(t);
    }
  }
View Full Code Here

  @SuppressWarnings({ "null", "unchecked" })
  @Override
  public void run() {
    try {
      System.out.println("Please type a Lotus domino @formula. Quit with CTRL+Z:");
      ASTNode n = null;
      List<Object> v = null;
      //String str = "t:={start}; @for(i:=1;i != 10; i:= i + 1; t:=t:@if(i = 1; {one} ; i <= 3; {two or three}; {four or more})); t";
      //String str = "x:=1:2*+32:64:1;x**x**x**x";
      String str = "@time(1800;2;3;4;15;18)";
      //String str = "@Transform((1:2:3)*+(0:3:6:9);{x};x*x)";
      System.out.println("Formula to test: " + str);

      long time = System.currentTimeMillis();

      //String str = "\"ab\\n\\x\\\"xyzz\"";
      //String str = "t:={start}; @for(i:=1;i != 10; i:= i + 1; t:=t:@Text(i)); @Transform(t;{x};x+{ test }+t)";
      //System.out.println(str);
      List<Function> funcs = new ArrayList<Function>();
      funcs.addAll(Formulas.getFunctionFactory().getFunctions().values());

      Collections.sort(funcs, new Comparator<Function>() {
        @Override
        public int compare(final Function o1, final Function o2) {
          return o1.toString().compareTo(o2.toString());
        }
      });
      for (Function func : funcs) {
        System.out.println(func);
      }

      FormulaParser parser = Formulas.getParser();

      for (int i = 1; i < 10000; i++) {
        java.io.StringReader sr = new java.io.StringReader(str);
        //java.io.Reader r = new java.io.BufferedReader(sr);
        n = parser.parse(sr, false);
      }
      time = System.currentTimeMillis() - time;
      System.err.println("[FormulaEngine] 10000x building AST tree\ttook " + time + "ms.");
      //n.dump("");

      time = System.currentTimeMillis();
      for (int i = 1; i < 10000; i++) {
        FormulaContext ctx = Formulas.createContext(null, parser);
        v = n.solve(ctx);
      }
      time = System.currentTimeMillis() - time;
      System.err.println("[FormulaEngine] 10000x evaluating AST tree\ttook " + time + "ms.");

      System.out.println("Result:\t" + v);
View Full Code Here

  @Override
  public void run() {
    try {

      System.out.println("Please type a Lotus domino @formula. Quit with CTRL+Z:");
      ASTNode n = null;
      List<Object> v = null;

      FormulaParser parser = Formulas.getParser();
      n = parser.parse(System.in, false);
      n.dump("");
      FormulaContext ctx = Formulas.createContext(null, parser);
      v = n.solve(ctx);

      System.out.println("NTF:\t" + v);

      //StringBuilder sb = new StringBuilder();
      //n.toFormula(sb);
View Full Code Here

TOP

Related Classes of org.openntf.formula.ASTNode

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.