Package de.innovationgate.eclipse.editors.tml

Source Code of de.innovationgate.eclipse.editors.tml.TagScanner

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/
package de.innovationgate.eclipse.editors.tml;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.text.rules.IRule;
import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.MultiLineRule;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.SingleLineRule;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.rules.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;

import de.innovationgate.eclipse.editors.helpers.SingleCharacterWordDetector;
import de.innovationgate.eclipse.editors.helpers.TextStyles;
import de.innovationgate.eclipse.editors.helpers.WhitespaceDetector;

/**
* scanner for generic tags
* for e.g. html/xml
* tml scanning is done by an separate content scanner {@link TMLStartTagContentScanner}
*
*
*/
public class TagScanner extends RuleBasedScanner {

  public TagScanner() { 
    IToken defaultToken = new Token(TextStyles.STYLE_DEFAULT);
    setDefaultReturnToken(defaultToken);
   
    IToken string = new Token(TextStyles.STRING_HTML);
    IToken tag = new Token(TextStyles.STYLE_TAG);
   
    List<IRule> rules = new ArrayList<IRule>();
   
   
   
    rules.add(new HTMLXMLTagRule(tag));
    rules.add(new MultiLineRule("<", ">", tag));
   
    SingleCharacterWordDetector detector = new SingleCharacterWordDetector();
    detector.addChar('=');
    detector.addChar('>');
    detector.addChar('/');
    WordRule wordRule = new WordRule(detector, tag);
    wordRule.addWord("=", defaultToken);
    rules.add(wordRule);
   
    // Add a rule for single quotes - attributes
    rules.add(new SingleLineRule("'", "'", string, '\\'));

    // Add rule for double quotes - attributes
    rules.add(new SingleLineRule("\"", "\"", string, '\\'));
   
   
   
    // Add generic whitespace rule.
    rules.add(new WhitespaceRule(new WhitespaceDetector()));

    setRules(rules.toArray(new IRule[0]));
  }
}
TOP

Related Classes of de.innovationgate.eclipse.editors.tml.TagScanner

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.