Examples of IStrategoTerm


Examples of org.spoofax.interpreter.terms.IStrategoTerm

    return getApplicationSubterm(decl, "TransImportDec", 1);
  }

  @Override
  public IStrategoTerm getTransformationBody(IStrategoTerm decl) {
    IStrategoTerm body = getApplicationSubterm(decl, "TransDec", 1);
    IStrategoTerm sugarBody = getApplicationSubterm(body, "TransBody", 0);
    return sugarBody;
  }
View Full Code Here

Examples of org.spoofax.interpreter.terms.IStrategoTerm

    return sugarBody;
  }

  @Override
  public String getTransformationName(IStrategoTerm decl) throws IOException {
    IStrategoTerm head = getApplicationSubterm(decl, "TransDec", 0);
    String extName = prettyPrint(getApplicationSubterm(head, "TransDecHead", 1));
    return extName;
  }
View Full Code Here

Examples of org.spoofax.interpreter.terms.IStrategoTerm

   * Pretty prints the content of a Java AST.
   *
   * @param aterm
   */
  protected String prettyPrint(IStrategoTerm term) {
    IStrategoTerm string = pp_java_string_0_0.instance.invoke(javaFronCtx, term);
    if (string != null)
      return Term.asJavaString(string);
 
    throw new RuntimeException("pretty printing java AST failed: " + term);
  }
View Full Code Here

Examples of org.spoofax.interpreter.terms.IStrategoTerm

    throw new RuntimeException("pretty printing java AST failed: " + term);
  }

  @Override
  public String getModelName(IStrategoTerm decl) throws IOException {
    IStrategoTerm head = getApplicationSubterm(decl, "ModelDec", 0);
    String extName = prettyPrint(getApplicationSubterm(head, "ModelDecHead", 1));
    return extName;
  }
View Full Code Here

Examples of org.spoofax.interpreter.terms.IStrategoTerm

    }
  }
 
  private Result parseFailureResult(String filename) throws FileNotFoundException, IOException {
    ITermFactory f = ATermCommands.factory;
    IStrategoTerm tbl =
      f.makeAppl(f.makeConstructor("parse-table", 5),
          f.makeInt(6),
          f.makeInt(0),
          f.makeList(),
          f.makeAppl(f.makeConstructor("states", 1), f.makeList()),
          f.makeAppl(f.makeConstructor("priorities", 1),
                     f.makeList(f.makeAppl(f.makeConstructor("arg-gtr-prio", 3),
                                           f.makeInt(257), f.makeInt(1), f.makeInt(257))))); // XXX

    ParseTable pt = null;
    try {
      pt = new ParseTable(tbl, f);
    } catch (InvalidParseTableException e) {
      throw new RuntimeException(e);
    }

    Tokenizer tokenizer = new Tokenizer(" ", " ", new KeywordRecognizer(pt) {});
    Token tok = tokenizer.makeToken(0, IToken.TK_UNKNOWN, true);
    IStrategoTerm term = ATermCommands.makeList("CompilationUnit", tok);
   
    Result r = new Result() {
      public boolean isUpToDate(int h, Environment env) { return false; }
    };
    r.setSugaredSyntaxTree(term);
View Full Code Here

Examples of org.spoofax.interpreter.terms.IStrategoTerm

   
    while (true) {
      if (remainingInput == null || remainingInput.isEmpty())
        return null;

      IStrategoTerm term;
      try {
        term = (IStrategoTerm) parser.parse(remainingInput, filename, "NextToplevelDeclaration");
      } catch (SGLRException e) {
        return null;
      } catch (InterruptedException e) {
        return null;
      }
     
      if (!ATermCommands.isApplication(term, "NextToplevelDeclaration"))
        return null;
     
      IStrategoTerm nextDecl = ATermCommands.getApplicationSubterm(term, "NextToplevelDeclaration", 0);
      list.add(nextDecl);
      if (nextDecl.toString().contains(ContentProposerSemantic.COMPLETION_TOKEN)) {
        IStrategoList termList = ATermCommands.makeList("NextToplevelDeclaration", list);
       
        IStrategoList listIt = termList;
        while (!listIt.isEmpty()) {
          ParentAttachment.putParent(listIt.head(), termList, listIt);
          listIt = listIt.tail();
        }
       
        return termList;
      }
       
      IStrategoTerm remainingInputTerm = ATermCommands.getApplicationSubterm(term, "NextToplevelDeclaration", 1);
      treeBuilder.retract(remainingInputTerm);
      remainingInput = ((IStrategoString) remainingInputTerm).stringValue();
    }
  }
View Full Code Here

Examples of org.spoofax.interpreter.terms.IStrategoTerm

    if (res.getSugaredSyntaxTree() == null)
      return success;
   
    IToken tok = ImploderAttachment.getRightToken(res.getSugaredSyntaxTree());
   
    IStrategoTerm tuple = ATermCommands.makeTuple(
        tok,
        res.getSugaredSyntaxTree(),
        ATermCommands.makeString(file.getAbsolutePath(), tok),
        ATermCommands.makeString(project, tok));
   
    List<Error> errors = gatherNonFatalErrors(res.getSugaredSyntaxTree());
    success &= errors.isEmpty();
   
    for (Error error : errors)
      log.log("error: line " + error.lineStart + " column " + error.columnStart + " to line " + error.lineEnd + " column " + error.columEnd + ":\n  " + error.msg, Log.ALWAYS);

   
    IStrategoTerm errorTree = STRCommands.assimilate("sugarj-analyze", res.getDesugaringsFile(), tuple, new HybridInterpreter());
   
    assert errorTree.getTermType() == IStrategoTerm.TUPLE && errorTree.getSubtermCount() == 4 :
      "error in sugarj-analyze, did not return tuple with 4 elements";
   
    IStrategoList semErrors = Tools.termAt(errorTree, 1);
    IStrategoList warnings = Tools.termAt(errorTree, 2);
    IStrategoList notes = Tools.termAt(errorTree, 3);
View Full Code Here

Examples of org.spoofax.interpreter.terms.IStrategoTerm

  }
 
  private static void reportCLI(IStrategoTerm pairOrList, String kind) throws IOException {
    assert pairOrList.getTermType() == IStrategoTerm.TUPLE && pairOrList.getSubtermCount() == 2;
   
    IStrategoTerm term = Tools.termAt(pairOrList, 0);
    IStrategoString msg = Tools.termAt(pairOrList, 1);
   
    IToken left = ImploderAttachment.getLeftToken(term);
    IToken right = ImploderAttachment.getRightToken(term);
   
View Full Code Here

Examples of org.spoofax.interpreter.terms.IStrategoTerm

    String name = driver.getModuleName();
   
    if (name == null)
      return false;

    IStrategoTerm nameTerm = ATermCommands.makeString(name);
    context.setCurrent(nameTerm);
    return true;
  }
View Full Code Here

Examples of org.spoofax.interpreter.terms.IStrategoTerm

      }

      if (parseResult == null || parseResult.a == null)
        throw new ParseException("could not parse toplevel declaration in:\n" + input, -1);

      IStrategoTerm toplevelDecl = parseResult.a;
      String rest = input.substring(Math.min(parseResult.b, input.length()));

      if (input.equals(rest))
        if (driver.getParser().getCollectedErrors().isEmpty())
          throw new SGLRException(driver.getParser(), "empty toplevel declaration parse rule");
        else
          throw driver.getParser().getCollectedErrors().iterator().next();
     
//      try {
//        if (!rest.isEmpty())
//          inputTreeBuilder.retract(restTerm);
//      } catch (Throwable t) {
//        t.printStackTrace();
//      }
     
      Path tmpFile = FileCommands.newTempFile("aterm");
      FileCommands.writeToFile(tmpFile, toplevelDecl.toString());
      log.log("next toplevel declaration parsed: " + tmpFile, Log.PARSE);

      return new IncrementalParseResult(toplevelDecl, rest);
    } catch (Exception e) {
//      if (!recovery)
//        throw new SGLRException(driver.getParser(), "parsing failed", e);
     
      String msg = e.getClass().getName() + " " + e.getLocalizedMessage() != null ? e.getLocalizedMessage() : e.toString();
     
      if (!(e instanceof StrategoException) && !(e instanceof ParseException) && (!(e instanceof SGLRException) || (e instanceof FilterException)))
        e.printStackTrace();
      else
        log.logErr(msg, Log.DETAIL);
     
      if (!treeBuilder.isInitialized()) {
        SGLR parser = driver.getParser();
        if (parser == null && (e instanceof SGLRException))
          parser = ((SGLRException) e).getParser();
        if (parser == null)
          return new IncrementalParseResult(ATermCommands.factory.makeString(input), "");
        treeBuilder.initializeTable(parser.getParseTable(), 0, 0, 0);
        treeBuilder.initializeInput(input, null);
      }
      else if (treeBuilder.getTokenizer().getStartOffset() > start) {
        IToken token = treeBuilder.getTokenizer().getTokenAtOffset(start);
        ((RetractableTokenizer) treeBuilder.getTokenizer()).retractTo(token.getIndex());
        treeBuilder.setOffset(start);
      }
     
      IToken right = treeBuilder.getTokenizer().makeToken(start + input.length() - 1, IToken.TK_STRING, true);
      IToken left = treeBuilder.getTokenizer().getTokenAtOffset(start);
      treeBuilder.getTokenizer().makeToken(treeBuilder.getTokenizer().getStartOffset() - 1, IToken.TK_EOF, true);
      IStrategoTerm term = ATermCommands.factory.makeString(input);
      ImploderAttachment.putImploderAttachment(term, false, "String", left, right);
      if (!lookahead)
        driver.setErrorMessage(term, msg);
      return new IncrementalParseResult(term, "");
    } finally {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.