Package org.fife.ui.rsyntaxtextarea

Examples of org.fife.ui.rsyntaxtextarea.Token


  @Test
  public void testUnderstanding() {
   
    String code = "f = function(x) {\n return(1+x);\n}";
    JavaScriptTokenMaker tokenMaker = new JavaScriptTokenMaker();
    Token tokenList = tokenMaker.getTokenList(new Segment(code.toCharArray(), 0, code.length()), 0, 0);
   
    tokenList = dumpTokenList(tokenList);
  }
View Full Code Here


  @Test
  public void testRenjin() {
   
    String code = "f <- function(x) {\n return(1+x);\n}";
    RenjinTokenMaker tokenMaker = new RenjinTokenMaker();
    Token tokenList = tokenMaker.getTokenList(new Segment(code.toCharArray(), 0, code.length()), 0, 0);
   
    tokenList = dumpTokenList(tokenList);
  }
View Full Code Here

  private CompletionProvider getProviderFor(JTextComponent comp) {

    RSyntaxTextArea rsta = (RSyntaxTextArea)comp;
    RSyntaxDocument doc = (RSyntaxDocument)rsta.getDocument();
    int line = rsta.getCaretLineNumber();
    Token t = doc.getTokenListForLine(line);
    if (t==null) {
      return getDefaultCompletionProvider();
    }

    int dot = rsta.getCaretPosition();
    Token curToken = RSyntaxUtilities.getTokenAtOffset(t, dot);

    if (curToken==null) { // At end of the line

      int type = doc.getLastTokenTypeOnLine(line);
      if (type==Token.NULL) {
        Token temp = t.getLastPaintableToken();
        if (temp==null) {
          return getDefaultCompletionProvider();
        }
        type = temp.type;
      }
View Full Code Here

  private CompletionProvider getProviderFor(JTextComponent comp) {

    RSyntaxTextArea rsta = (RSyntaxTextArea)comp;
    RSyntaxDocument doc = (RSyntaxDocument)rsta.getDocument();
    int line = rsta.getCaretLineNumber();
    Token t = doc.getTokenListForLine(line);
    if (t==null) {
      return getDefaultCompletionProvider();
    }

    int dot = rsta.getCaretPosition();
    Token curToken = RSyntaxUtilities.getTokenAtOffset(t, dot);

    if (curToken==null) { // At end of the line

      int type = doc.getLastTokenTypeOnLine(line);
      if (type==Token.NULL) {
        Token temp = t.getLastPaintableToken();
        if (temp==null) {
          return getDefaultCompletionProvider();
        }
        type = temp.type;
      }
View Full Code Here

    result.clearNotices();
    result.setParsedLines(0, lineCount-1);

    for (int line=0; line<lineCount; line++) {

      Token t = doc.getTokenListForLine(line);
      int offs = -1;
      int start = -1;
      String text = null;

      while (t!=null && t.isPaintable()) {
        if (t.type==Token.COMMENT_EOL ||
            t.type==Token.COMMENT_MULTILINE ||
            t.type==Token.COMMENT_DOCUMENTATION) {

          offs = t.offset;
          text = t.getLexeme();

          Matcher m = taskPattern.matcher(text);
          if (m.find()) {
            start = m.start();
            offs += start;
            break;
          }

        }
        t = t.getNextToken();
      }

      if (start>-1) {
        text = text.substring(start);
        // TODO: Strip off end of MLC's if they're there.
View Full Code Here

  private CompletionProvider getProviderFor(JTextComponent comp) {

    RSyntaxTextArea rsta = (RSyntaxTextArea)comp;
    RSyntaxDocument doc = (RSyntaxDocument)rsta.getDocument();
    int line = rsta.getCaretLineNumber();
    Token t = doc.getTokenListForLine(line);
    if (t==null) {
      return this.defaultProvider;
    }


    int dot = rsta.getCaretPosition();

    //Token curToken = RSyntaxUtilities.getTokenAtOffset(t, dot);
    Token curToken = RSyntaxUtilities.getTokenAtOffset(t, dot);

    if (curToken==null) { // At end of the line

      int type = doc.getLastTokenTypeOnLine(line);
      if (type==Token.NULL) {
        Token temp = t.getLastPaintableToken();
        if (temp==null) {
          return this.defaultProvider;
        }
        type = temp.type;
      }
View Full Code Here

    try {

      for (int line=0; line<lineCount; line++) {

        Token t = textArea.getTokenListForLine(line);
        while (t!=null && t.isPaintable()) {

          // If we're folding PHP.  Note that PHP folding can only be
          // "one level deep," so our logic here is simple.
          if (language>=0 && t.type==Token.SEPARATOR) {

            // <?, <?php, <%, <%!, ...
            if (t.startsWith(LANG_START[language])) {
              if (currentFold==null) {
                currentFold = new Fold(FoldType.CODE, textArea, t.offset);
                folds.add(currentFold);
              }
              else {
                currentFold = currentFold.createChild(FoldType.CODE, t.offset);
              }
              inSublanguage = true;
            }

            // ?> or %>
            else if (t.startsWith(LANG_END[language])) {
              int phpEnd = t.offset + t.textCount - 1;
              currentFold.setEndOffset(phpEnd);
              Fold parentFold = currentFold.getParent();
              // Don't add fold markers for single-line blocks
              if (currentFold.isOnSingleLine()) {
                removeFold(currentFold, folds);
              }
              currentFold = parentFold;
              inSublanguage = false;
              t = t.getNextToken();
              continue;
            }

          }

          if (!inSublanguage) {

            if (t.type==Token.COMMENT_MULTILINE) {

              // Continuing an MLC from a previous line
              if (inMLC) {
                // Found the end of the MLC starting on a previous line...
                if (t.endsWith(MLC_END)) {
                  int mlcEnd = t.offset + t.textCount - 1;
                  currentFold.setEndOffset(mlcEnd);
                  Fold parentFold = currentFold.getParent();
                  // Don't add fold markers for single-line blocks
                  if (currentFold.isOnSingleLine()) {
                    removeFold(currentFold, folds);
                  }
                  currentFold = parentFold;
                  inMLC = false;
                }
                // Otherwise, this MLC is continuing on to yet
                // another line.
              }
 
              // Continuing a JS MLC from a previous line
              else if (inJSMLC) {
                // Found the end of the MLC starting on a previous line...
                if (t.endsWith(JSP_COMMENT_END)) {
                  int mlcEnd = t.offset + t.textCount - 1;
                  currentFold.setEndOffset(mlcEnd);
                  Fold parentFold = currentFold.getParent();
                  // Don't add fold markers for single-line blocks
                  if (currentFold.isOnSingleLine()) {
                    removeFold(currentFold, folds);
                  }
                  currentFold = parentFold;
                  inJSMLC = false;
                }
                // Otherwise, this MLC is continuing on to yet
                // another line.
              }

              // Starting a MLC that ends on a later line...
              else if (t.startsWith(MLC_START) && !t.endsWith(MLC_END)) {
                if (currentFold==null) {
                  currentFold = new Fold(FoldType.COMMENT, textArea, t.offset);
                  folds.add(currentFold);
                }
                else {
                  currentFold = currentFold.createChild(FoldType.COMMENT, t.offset);
                }
                inMLC = true;
              }

              // Starting a JSP comment that ends on a later line...
              else if (language==LANGUAGE_JSP &&
                  t.startsWith(JSP_COMMENT_START) &&
                  !t.endsWith(JSP_COMMENT_END)) {
                if (currentFold==null) {
                  currentFold = new Fold(FoldType.COMMENT, textArea, t.offset);
                  folds.add(currentFold);
                }
                else {
                  currentFold = currentFold.createChild(FoldType.COMMENT, t.offset);
                }
                inJSMLC = true;
              }

            }

            // If we're starting a new tag...
            else if (t.isSingleChar(Token.MARKUP_TAG_DELIMITER, '<')) {
              Token tagStartToken = t;
              Token tagNameToken = t.getNextToken();
              if (isFoldableTag(tagNameToken)) {
                getTagCloseInfo(tagNameToken, textArea, line, tci);
                if (tci.line==-1) { // EOF reached before end of tag
                  return folds;
                }
                // We have found either ">" or "/>" with tci.
                Token tagCloseToken = tci.closeToken;
                if (tagCloseToken.isSingleChar(Token.MARKUP_TAG_DELIMITER, '>')) {
                  if (currentFold==null) {
                    currentFold = new Fold(FoldType.CODE, textArea, tagStartToken.offset);
                    folds.add(currentFold);
                  }
                  else {
                    currentFold = currentFold.createChild(FoldType.CODE, tagStartToken.offset);
                  }
                  tagNameStack.push(tagNameToken.getLexeme());
                }
                t = tagCloseToken; // Continue parsing after tag
              }
            }

            // If we've found a closing tag (e.g. "</div>").
            else if (t.is(Token.MARKUP_TAG_DELIMITER, MARKUP_CLOSING_TAG_START)) {
              if (currentFold!=null) {
                Token tagNameToken = t.getNextToken();
                if (isFoldableTag(tagNameToken) &&
                    isEndOfLastFold(tagNameStack, tagNameToken)) {
                  tagNameStack.pop();
                  currentFold.setEndOffset(t.offset);
                  Fold parentFold = currentFold.getParent();
View Full Code Here

   */
  private void getTagCloseInfo(Token tagNameToken, RSyntaxTextArea textArea,
      int line, TagCloseInfo info) {

    info.reset();
    Token t = tagNameToken.getNextToken();

    do {

      while (t!=null && t.type!=Token.MARKUP_TAG_DELIMITER) {
        t = t.getNextToken();
      }

      if (t!=null) {
        info.closeToken = t;
        info.line = line;
View Full Code Here

    try {

      for (int line=0; line<lineCount; line++) {

        Token t = textArea.getTokenListForLine(line);
        while (t!=null && t.isPaintable()) {

          if (getFoldableMultiLineComments() && t.isComment()) {

            // Java-specific stuff
            if (java) {

              if (importStartLine>-1) {
                if (lastSeenImportLine>importStartLine) {
                  Fold fold = null;
                  // Any imports found *should* be a top-level fold,
                  // but we're extra lenient here and allow groups
                  // of them anywhere to keep our parser better-behaved
                  // if they have random "imports" throughout code.
                  if (currentFold==null) {
                    fold = new Fold(FoldType.IMPORTS,
                        textArea, importGroupStartOffs);
                    folds.add(fold);
                  }
                  else {
                    fold = currentFold.createChild(FoldType.IMPORTS,
                        importGroupStartOffs);
                  }
                  fold.setEndOffset(importGroupEndOffs);
                }
                importStartLine = lastSeenImportLine =
                importGroupStartOffs = importGroupEndOffs = -1;
              }

            }

            if (inMLC) {
              // If we found the end of an MLC that started
              // on a previous line...
              if (t.endsWith(C_MLC_END)) {
                int mlcEnd = t.offset + t.textCount - 1;
                if (currentFold==null) {
                  currentFold = new Fold(FoldType.COMMENT, textArea, mlcStart);
                  currentFold.setEndOffset(mlcEnd);
                  folds.add(currentFold);
                  currentFold = null;
                }
                else {
                  currentFold = currentFold.createChild(FoldType.COMMENT, mlcStart);
                  currentFold.setEndOffset(mlcEnd);
                  currentFold = currentFold.getParent();
                }
                //System.out.println("Ending MLC at: " + mlcEnd + ", parent==" + currentFold);
                inMLC = false;
                mlcStart = 0;
              }
              // Otherwise, this MLC is continuing on to yet
              // another line.
            }
            else {
              // If we're an MLC that ends on a later line...
              if (t.type!=Token.COMMENT_EOL && !t.endsWith(C_MLC_END)) {
                //System.out.println("Starting MLC at: " + t.offset);
                inMLC = true;
                mlcStart = t.offset;
              }
            }

          }

          else if (isLeftCurly(t)) {

            // Java-specific stuff
            if (java) {

              if (importStartLine>-1) {
                if (lastSeenImportLine>importStartLine) {
                  Fold fold = null;
                  // Any imports found *should* be a top-level fold,
                  // but we're extra lenient here and allow groups
                  // of them anywhere to keep our parser better-behaved
                  // if they have random "imports" throughout code.
                  if (currentFold==null) {
                    fold = new Fold(FoldType.IMPORTS,
                        textArea, importGroupStartOffs);
                    folds.add(fold);
                  }
                  else {
                    fold = currentFold.createChild(FoldType.IMPORTS,
                        importGroupStartOffs);
                  }
                  fold.setEndOffset(importGroupEndOffs);
                }
                importStartLine = lastSeenImportLine =
                importGroupStartOffs = importGroupEndOffs = -1;
              }

            }

            if (currentFold==null) {
              currentFold = new Fold(FoldType.CODE, textArea, t.offset);
              folds.add(currentFold);
            }
            else {
              currentFold = currentFold.createChild(FoldType.CODE, t.offset);
            }

          }

          else if (isRightCurly(t)) {

            if (currentFold!=null) {
              currentFold.setEndOffset(t.offset);
              Fold parentFold = currentFold.getParent();
              //System.out.println("... Adding regular fold at " + t.offset + ", parent==" + parentFold);
              // Don't add fold markers for single-line blocks
              if (currentFold.isOnSingleLine()) {
                if (!currentFold.removeFromParent()) {
                  folds.remove(folds.size()-1);
                }
              }
              currentFold = parentFold;
            }

          }

          // Java-specific folding rules
          else if (java) {

            if (t.is(Token.RESERVED_WORD, KEYWORD_IMPORT)) {
              if (importStartLine==-1) {
                importStartLine = line;
                importGroupStartOffs = t.offset;
                importGroupEndOffs = t.offset;
              }
              lastSeenImportLine = line;
            }

            else if (importStartLine>-1 &&
                t.isIdentifier() &&//SEPARATOR &&
                t.isSingleChar(';')) {
              importGroupEndOffs = t.offset;
            }

          }

          t = t.getNextToken();

        }

      }

View Full Code Here

    try {

      for (int line=0; line<lineCount; line++) {

        Token t = textArea.getTokenListForLine(line);
        while (t!=null && t.isPaintable()) {

          if (t.is(Token.RESERVED_WORD, BEGIN)) {
            Token temp = t.getNextToken();
            if (temp!=null && temp.isLeftCurly()) {
              temp = temp.getNextToken();
              if (temp!=null && temp.type==Token.RESERVED_WORD) {
                if (currentFold==null) {
                  currentFold = new Fold(FoldType.CODE, textArea, t.offset);
                  folds.add(currentFold);
                }
                else {
                  currentFold = currentFold.createChild(FoldType.CODE, t.offset);
                }
                expectedStack.push(temp.getLexeme());
                t = temp;
              }
            }
          }

          else if (t.is(Token.RESERVED_WORD, END) &&
              currentFold!=null && !expectedStack.isEmpty()) {
            Token temp = t.getNextToken();
            if (temp!=null && temp.isLeftCurly()) {
              temp = temp.getNextToken();
              if (temp!=null && temp.type==Token.RESERVED_WORD) {
                String value = temp.getLexeme();
                if (expectedStack.peek().equals(value)) {
                  expectedStack.pop();
                  currentFold.setEndOffset(t.offset);
                  Fold parentFold = currentFold.getParent();
                  // Don't add fold markers for single-line blocks
View Full Code Here

TOP

Related Classes of org.fife.ui.rsyntaxtextarea.Token

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.