Package de.innovationgate.eclipse.editors.tml

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

/*******************************************************************************
* 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.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;

/**
* scans the content of an tml start tag
*
*
*/
public class TMLStartTagContentScanner extends RuleBasedScanner {

  public TMLStartTagContentScanner() {
    setDefaultReturnToken(new Token(TextStyles.STYLE_ATTRIBUTE));
   
    IToken tag = new Token(TextStyles.STYLE_TML_TAG);
    IToken defaultToken = new Token(TextStyles.STYLE_DEFAULT);
    IToken string = new Token(TextStyles.STRING);
    IToken tmlScriptlet = new Token(TextStyles.TML_SCRIPTLET);   
   
    List<IRule> rules = new ArrayList<IRule>();
   
    rules.add(new SingleLineRule("<", " ", tag, '\\', true));
   
    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 tmlscriptlets
    rules.add(new SingleLineRule("\"{", "}\"", tmlScriptlet, '\\'));   
   
    // 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.TMLStartTagContentScanner

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.