/**
   * This code is used to activate syntax coloring for each section detected by the
   * XWikiPartitionner The partitioner is activated in createDocument in PageDocumentProvider.java
   *
   * @see PageDocumentProvider#createDocument(Object)
   */
  @Override
  public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
    PresentationReconciler reconciler = new PresentationReconciler();
    reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));

    /* Use the XWiki markup for tables and default content. */
    DefaultDamagerRepairer dr = new DefaultDamagerRepairer(new XWikiMarkupScanner());
    reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
    reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);

    reconciler.setDamager(dr, XWikiPartitionScanner.XWIKI_TABLE);
    reconciler.setRepairer(dr, XWikiPartitionScanner.XWIKI_TABLE);

    /* Use the Velocity Scanner for velocity blocks */
    dr = new DefaultDamagerRepairer(new VelocityScanner());
    reconciler.setDamager(dr, XWikiPartitionScanner.VELOCITY);
    reconciler.setRepairer(dr, XWikiPartitionScanner.VELOCITY);

    /* Use the Groovy Scanner for groovy blocks */
    dr = new DefaultDamagerRepairer(new GroovyScanner());
    reconciler.setDamager(dr, XWikiPartitionScanner.GROOVY);
    reconciler.setRepairer(dr, XWikiPartitionScanner.GROOVY);

    /* Use a uniform style for html blocks. */
    RuleBasedScanner codeScanner = new RuleBasedScanner();
    codeScanner.setDefaultReturnToken(
        new Token(Preferences.getDefault().getTextAttribute(Preferences.Style.HTML)));
    dr = new DefaultDamagerRepairer(codeScanner);
    reconciler.setDamager(dr, XWikiPartitionScanner.XWIKI_HTML);
    reconciler.setRepairer(dr, XWikiPartitionScanner.XWIKI_HTML);

    /* Use a uniform style for code blocks. */
    codeScanner = new RuleBasedScanner();
    codeScanner.setDefaultReturnToken(
        new Token(Preferences.getDefault().getTextAttribute(Preferences.Style.CODE)));
    dr = new DefaultDamagerRepairer(codeScanner);
    reconciler.setDamager(dr, XWikiPartitionScanner.XWIKI_CODE);
    reconciler.setRepairer(dr, XWikiPartitionScanner.XWIKI_CODE);

    /* Use a uniform style for pre blocks. */
    RuleBasedScanner preScanner = new RuleBasedScanner();
    preScanner.setDefaultReturnToken(
        new Token(Preferences.getDefault().getTextAttribute(Preferences.Style.CODE)));
    dr = new DefaultDamagerRepairer(preScanner);
    reconciler.setDamager(dr, XWikiPartitionScanner.XWIKI_PRE);
    reconciler.setRepairer(dr, XWikiPartitionScanner.XWIKI_PRE);

    RuleBasedScanner javadocScanner = new GroovyScanner();
    dr = new DefaultDamagerRepairer(javadocScanner);
    reconciler.setDamager(dr, GroovyPartitionScanner.GROOVY_DEFAULT);
    reconciler.setRepairer(dr, GroovyPartitionScanner.GROOVY_DEFAULT);

    return reconciler;
  }
Exemplo n.º 2
0
 ITokenScanner getCommentScanner() {
   // lazy init
   if (this.commentScanner == null) {
     final Token comment =
         new Token(new TextAttribute(JFaceResources.getColorRegistry().get(COMMENT_COLOR)));
     // no rules needed, because this will apply to comment partition only
     final RuleBasedScanner ruleBasedScanner = new RuleBasedScanner();
     // this will apply the syntax
     ruleBasedScanner.setDefaultReturnToken(comment);
     this.commentScanner = ruleBasedScanner;
   }
   return commentScanner;
 }
    @Override
    public RuleBasedScanner createItemParser() {
      List<IRule> rules = new ArrayList<IRule>();
      for (Directive directive : Directive.values()) {
        if (!directive.isEndDirective()) {
          rules.add(new DirectiveRule(directive));
        }
      }

      RuleBasedScanner result = new SyntaxModeListenerRuleBasedScanner();
      result.setRules(rules.toArray(new IRule[rules.size()]));
      return result;
    }
  public RuleBasedScanner getCodeScanner() {
    RuleBasedScanner scanner = new RuleBasedScanner();
    List rules = new ArrayList();
    Rule main = mode.getDefaultRuleSet();
    addWhitespaceRule(rules);

    IToken defaultToken = newToken(ColorsPreferencePage.NULL_COLOR);
    addTextSequenceRules(main, rules, defaultToken);

    IRule[] result = new IRule[rules.size()];
    rules.toArray(result);
    scanner.setRules(result);
    return scanner;
  }
 private void setupScannerType(PresentationReconciler reconciler, String typeName) {
   String[] contentTypes = mode.getContentTypes();
   for (int i = 0; i < contentTypes.length; i++) {
     String contentType = contentTypes[i];
     if (!contentType.startsWith(typeName)) continue;
     RuleBasedScanner scanner = new RuleBasedScanner();
     String type = contentType.substring(contentType.lastIndexOf('.') + 1);
     IToken defaultToken = newToken(colorManager.colorForType(type));
     scanner.setDefaultReturnToken(defaultToken);
     DefaultDamagerRepairer dr = new DefaultDamagerRepairer(scanner);
     reconciler.setDamager(dr, contentType);
     reconciler.setRepairer(dr, contentType);
   }
 }
Exemplo n.º 6
0
 protected ITokenScanner getStringScanner() {
   if (stringScanner == null) {
     stringScanner = new RuleBasedScanner();
     stringScanner.setDefaultReturnToken(getToken(ICSSConstants.CSS_STRING_SCOPE));
   }
   return stringScanner;
 }
Exemplo n.º 7
0
 protected ITokenScanner getWordScanner() {
   if (multilineCommentScanner == null) {
     multilineCommentScanner = new RuleBasedScanner();
     multilineCommentScanner.setDefaultReturnToken(
         getToken(ICSSConstants.CSS_COMMENT_BLOCK_SCOPE));
   }
   return multilineCommentScanner;
 }
 private void setupScannerTypeForMark(PresentationReconciler reconciler) {
   String[] contentTypes = mode.getContentTypes();
   for (int i = 0; i < contentTypes.length; i++) {
     String contentType = contentTypes[i];
     if (contentType.startsWith(Type.MARK_PREVIOUS)
         || contentType.startsWith(Type.MARK_FOLLOWING)) {
       RuleBasedScanner scanner = new RuleBasedScanner();
       String colorType = contentType.substring(contentType.lastIndexOf('.') + 1);
       LToken defaultToken = (LToken) newToken(colorManager.colorForType(colorType), true);
       defaultToken.setLength(getLength(contentType));
       defaultToken.isPrevious(contentType.startsWith(Type.MARK_PREVIOUS));
       scanner.setDefaultReturnToken(defaultToken);
       DefaultDamagerRepairer dr = new MarkDamagerRepairer(scanner);
       reconciler.setDamager(dr, contentType);
       reconciler.setRepairer(dr, contentType);
     }
   }
 }
  private RuleBasedScanner getDelegateScanner(Rule rule) {
    RuleBasedScanner scanner = new RuleBasedScanner();
    List rules = new ArrayList();

    String colorName = colorManager.colorForType(rule.getDefaultTokenType());
    IToken defaultToken = newToken(colorName);
    scanner.setDefaultReturnToken(defaultToken);
    ColoringEditorTools.add(
        rule,
        rules,
        new ITokenFactory() {
          public IToken makeToken(Type type) {
            String color = colorManager.colorForType(type.getColor());
            return newToken(color);
          }
        });
    addTextSequenceRules(rule, rules, defaultToken);

    scanner.setRules((IRule[]) rules.toArray(new IRule[rules.size()]));
    return scanner;
  }
  private ITokenScanner getDefaultScanner() {
    RuleBasedScanner scanner = new RuleBasedScanner();

    IRule[] rules = new IRule[14];
    rules[0] = createHeader6Rule();
    rules[1] = createHeader5Rule();
    rules[2] = createHeader4Rule();
    rules[3] = createHeader3Rule();
    rules[4] = createHeader2Rule();
    rules[5] = createHeader1Rule();
    rules[6] = createHRRule();
    rules[7] = createMacroRule();
    rules[8] = createExternalHTTPRule();
    rules[9] = createListRule();
    rules[10] = createNumberedListRule();
    rules[11] = createBoldItalicRule();
    rules[12] = createBoldRule();
    rules[13] = createItalicRule();

    scanner.setRules(rules);
    return scanner;
  }
Exemplo n.º 11
0
  public IToken evaluate(ICharacterScanner charScanner) {

    RuleBasedScanner scanner = (RuleBasedScanner) charScanner;
    StringBuffer buff = new StringBuffer();
    boolean stopReading = false;
    int reads = 0;

    /*char c = (char) ICharacterScanner.EOF;

    do {
        c = (char) scanner.read();

        System.out.print(c);
    } while (c != (char) ICharacterScanner.EOF);

    scanner.unread();*/

    if (scanner.getColumn() > 0) {
      scanner.unread();

      char c = (char) scanner.read();

      if (Character.isJavaIdentifierPart(c)) return Token.UNDEFINED;
    }

    while (!stopReading) {

      reads++;

      char c = (char) scanner.read();

      String currentWord = buff.toString();

      if (buff.length() > 0 && !Character.isJavaIdentifierPart(c)) {
        if (isKeyword(currentWord.toLowerCase()) && !keywordExists(currentWord + c)) {
          scanner.unread();
          return keywordToken;
        }
      }

      buff.append(c);

      stopReading = !keywordExists(currentWord.toLowerCase());
    }

    for (int i = 0; i < reads; i++) {
      scanner.unread();
    }

    return Token.UNDEFINED;
  }