blob: c9b4476f426de043804eefd12e6a2b9431296f38 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2008 Istvan Rath and Daniel Varro
* 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:
* Istvan Rath - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.editor.text.light.vtcl;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.text.rules.EndOfLineRule;
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.WhitespaceRule;
import org.eclipse.jface.text.rules.WordRule;
import org.eclipse.viatra2.editor.text.light.IVTEConstants;
import org.eclipse.viatra2.editor.text.light.VTEColorProvider;
import org.eclipse.viatra2.editor.text.light.VTEColorToken;
import org.eclipse.viatra2.editor.text.light.vtml.VTMLWhitespaceDetector;
import org.eclipse.viatra2.editor.text.light.vtml.VTMLWordDetector;
public class VTCLCodeScanner extends RuleBasedScanner {
public VTCLCodeScanner(VTEColorProvider provider,VTEColorToken vct) {
IToken keyword = vct.KEYWORD;
IToken string = vct.STRING;
IToken comment = vct.COMMENT;
IToken other = vct.OTHER;
String[] keywords = IVTEConstants.vtclKeywords;
List<IRule> rules= new ArrayList<IRule>();
rules.add(new MultiLineRule("/*","*/",comment));
rules.add(new EndOfLineRule("//", comment));
rules.add(new SingleLineRule("\"", "\"", string, '\\'));
rules.add(new SingleLineRule("'", "'", string, '\\'));
// we can use VTML whitespace and word detectors
rules.add(new WhitespaceRule(new VTMLWhitespaceDetector()));
WordRule wordRule= new WordRule(new VTMLWordDetector(), other);
for (int i= 0; i < keywords.length; i++)
wordRule.addWord(keywords[i], keyword);
rules.add(wordRule);
IRule[] result= new IRule[rules.size()];
rules.toArray(result);
setRules(result);
}
}