Package org.spoofax.jsglr.client.imploder

Examples of org.spoofax.jsglr.client.imploder.IToken


      log.log("syntax error: line " + e.getLineNumber() + " column " + e.getColumnNumber() + ": " + e.getMessage(), Log.ALWAYS);
   
    if (res.getSugaredSyntaxTree() == null)
      return success;
   
    IToken tok = ImploderAttachment.getRightToken(res.getSugaredSyntaxTree());
   
    IStrategoTerm tuple = ATermCommands.makeTuple(
        tok,
        res.getSugaredSyntaxTree(),
        ATermCommands.makeString(file.getAbsolutePath(), tok),
View Full Code Here


    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);
   
    if (left == null && right != null)
      left = right;
    else if (left != null && right == null)
      right = left;
   
    if (left == null || right == null)
      log.log("error: " + msg + "\n  in tree " + ATermCommands.atermToFile(term), Log.ALWAYS);
    else
      log.log("error: line " + left.getLine() + " column " + left.getColumn() + " to line " + right.getLine() + " column " + right.getColumn() + ":\n  " + msg, Log.ALWAYS);
  }
View Full Code Here

    List<Error> errors = new ArrayList<Error>();
    ITokenizer tokenizer = getTokenizer(top);
    if (tokenizer == null)
      return errors;
    for (int i = 0, max = tokenizer.getTokenCount(); i < max; i++) {
      IToken token = tokenizer.getTokenAt(i);
      String error = token.getError();
      if (error != null) {
        if (error == ITokenizer.ERROR_SKIPPED_REGION) {
          i = findRightMostWithSameError(token, null);
          reportSkippedRegion(token, tokenizer.getTokenAt(i), errors);
        } else if (error.startsWith(ITokenizer.ERROR_WARNING_PREFIX)) {
View Full Code Here

  private static void reportBadToken(ITokenizer tokenizer, BadTokenException exception, List<Error> errors) {
    String message;
    if (exception.isEOFToken() || tokenizer.getTokenCount() <= 1) {
      message = exception.getShortMessage();
    } else {
      IToken token = tokenizer.getTokenAtOffset(exception.getOffset());
      token = findNextNonEmptyToken(token);
      message = ITokenizer.ERROR_WATER_PREFIX + ": " + token.toString().trim();
    }
    reportErrorNearOffset(tokenizer, exception.getOffset(), message, errors);
  }
View Full Code Here

      reportErrorAtFirstLine(message, errors);
    }
  }

  private static void reportErrorNearOffset(ITokenizer tokenizer, int offset, String message, List<Error> errors) {
    IToken errorToken = tokenizer.getErrorTokenOrAdjunct(offset);
    reportErrorAtTokens(errorToken, errorToken, message, errors);
  }
View Full Code Here

    reportErrorAtTokens(errorToken, errorToken, message, errors);
  }
  
  private static IToken findNextNonEmptyToken(IToken token) {
    ITokenizer tokenizer = token.getTokenizer();
    IToken result = null;
    for (int i = token.getIndex(), max = tokenizer.getTokenCount(); i < max; i++) {
      result = tokenizer.getTokenAt(i);
      if (result.getLength() != 0 && !Token.isWhiteSpace(result)) break;
    }
    return result;
  }
View Full Code Here

          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);
View Full Code Here

   
    return appl;
  }
 
  private static void setAttachment(IStrategoTerm term, String sort, IToken emptyToken, IStrategoTerm... children) {
    IToken left;
    IToken right;
   
    if (children.length == 0) {
      if (emptyToken == null)
        return;
     
View Full Code Here

    return newServices;
  }

  public static void setErrorMessage(IStrategoTerm toplevelDecl, String msg) {
    IToken left = ImploderAttachment.getLeftToken(toplevelDecl);
    IToken right = ImploderAttachment.getRightToken(toplevelDecl);
   
//    Path file = null;
//    try {
//      file = atermToFile(toplevelDecl);
//    } catch (IOException e) {
//      e.printStackTrace();
//    }
   
    if (left == null || right == null) {
      new IllegalStateException(msg).printStackTrace();
      return;
    }
   
    HashMap<String, String> cache = new HashMap<String, String>();
   
    for (int i = left.getIndex(), max = right.getIndex(); i <= max; i++) {
      Token tok = ((Token) left.getTokenizer().getTokenAt(i));
      if (tok.getError() == null || tok.getError().isEmpty())
        tok.setError(msg);
      else {
        StringBuilder b = new StringBuilder();
View Full Code Here

    assert getTokenizer(node) == this;
    retractTo(ImploderAttachment.getLeftToken(node).getIndex());
  }
 
  public void retractTo(int index) {
    IToken tok = getTokenAt(index);
   
    int start = tok.getIndex();
   
    for (int i = getTokenCount() - 1; i >= start; i--)
      removeTokenAt(i);
   
    assert getTokenCount() == start;
   
    setPositions(tok.getLine(), tok.getStartOffset(), tok.getStartOffset() - tok.getColumn());
  }
View Full Code Here

TOP

Related Classes of org.spoofax.jsglr.client.imploder.IToken

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.