Package de.innovationgate.eclipse.editors.tmlscript

Source Code of de.innovationgate.eclipse.editors.tmlscript.TMLScriptScanner

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

import java.util.ArrayList;
import java.util.Iterator;
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.WordRule;

import de.innovationgate.eclipse.editors.helpers.JavaScriptWordDetector;
import de.innovationgate.eclipse.editors.helpers.TextStyles;

public class TMLScriptScanner extends RuleBasedScanner {
 
  private List<String> _commandList =  new ArrayList<String>();
 
 
 
  private void initCommands(){ 
    _commandList = CommandList.getCommands();
   
  }
  public TMLScriptScanner() {   
    IToken string = new Token(TextStyles.STRING);
 
    initCommands();   

    List<IRule> rules = new ArrayList<IRule>();
    rules.add(createCommandRule());   

   
    // Add a rule for single quotes - attributes
    rules.add(new SingleLineRule("'", "'", string, '\\'));

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

   
    setRules(rules.toArray(new IRule[0]));
  }
 
 
 
 
  private IRule createCommandRule() {
    IToken keyword = new Token(TextStyles.STYLE_TMLSCRIPT_KEYWORD);

    WordRule wordRule= new WordRule(new JavaScriptWordDetector(), new Token(TextStyles.STYLE_DEFAULT));

     
      Iterator<String> iter = _commandList.iterator();
     
      while (iter.hasNext()){       
        wordRule.addWord(iter.next(), keyword);
      }

      return wordRule;
   

 
}
TOP

Related Classes of de.innovationgate.eclipse.editors.tmlscript.TMLScriptScanner

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.