/*******************************************************************************
 * Copyright (c) 2015 Bruno Medeiros and other Contributors.
 * 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:
 *     Bruno Medeiros - initial API and implementation
 *******************************************************************************/
package melnorme.lang.tooling.parser.lexer;

import melnorme.lang.utils.parse.ICharacterReader;
import melnorme.lang.utils.parse.LexingUtils;
import melnorme.utilbox.collections.HashMap2;

public class WordLexerRule<TOKEN> implements ILexingRule2<TOKEN> {
	
	protected final TOKEN whitespaceToken;
	protected final TOKEN defaultWordToken;
	protected final HashMap2<String, TOKEN> tokenMap = new HashMap2<>();
	
	public WordLexerRule(TOKEN whitespaceToken, TOKEN defaultWordToken) {
		this.whitespaceToken = whitespaceToken;
		this.defaultWordToken = defaultWordToken;
	}
	
	public void addKeywords(TOKEN token, String[] keywords) {
		for(String keyword : keywords) {
			addWord(keyword, token);
		}
	}
	
	public void addWord(String keyword, TOKEN token) {
		tokenMap.put(keyword, token);
	}
	
	@Override
	public TOKEN doEvaluateToken(ICharacterReader reader) {
		if(LexingUtils.skipWhitespace(reader) > 0) {
			return whitespaceToken;
		}
		
		String word = LexingUtils.readJavaIdentifier(reader);
		if(word.isEmpty()) {
			return null;
		}
		
		TOKEN keywordToken = tokenMap.get(word);
		return (keywordToken == null) ? defaultWordToken : keywordToken;
	}
	
}
@@ -967,24 +967,65 @@
 p2%3C%3E();%0D%0A%09%0D%0A
+%09protected String lastEvaluatedWord;%0D%0A%09%0D%0A
 %09public Word
@@ -1570,16 +1570,22 @@
 %0D%0A%09%09
-String w
+lastEvaluatedW
 ord 
@@ -1632,17 +1632,30 @@
 ;%0D%0A%09%09if(
-w
+lastEvaluatedW
 ord.isEm
@@ -1726,17 +1726,30 @@
 Map.get(
-w
+lastEvaluatedW
 ord);%0D%0A%09

Add lastEvaluatedWord