package fortran.lexer;

import static fortran.lexer.LiteralType.*;

import java.util.Collections;
import java.util.EnumSet;
import java.util.Set;

/**
 * This class contains the definition of the subset of {@link LiteralType}s,
 * that directly represent a keyword of the FORTRAN language:
 * <ul>
 *  <li>Control Statements:
 *  <tt>GO, TO, ASSIGN, IF,
 *  SENSE, LIGHT, SWITCH,
 *  ACCUMULATOR, OVERFLOW, QUOTIENT, DIVIDE, CHECK,
 *  PAUSE, STOP, DO, CONTINUE</tt></li>
 *  <li>Input/Output:
 *  <tt>READ, PUNCH, PRINT, INPUT,
 *  WRITE, OUTPUT,
 *  FORMAT,
 *  TAPE, DRUM,
 *  END, FILE, REWIND, BACKSPACE</tt></li>
 *  <li>Specification Statements:
 *  <tt>DIMENSTION, EQUIVALENCE, FREQUENCY</tt></li>
 * </ul> 
 * @author oreissig
 */
public class Keyword {
	/**
	 * All {@link LiteralType}s, that directly represent a
	 * keyword of the FORTRAN language.
	 */
	public static final Set<LiteralType> set;
	
	static {
		EnumSet<LiteralType> keywords = EnumSet.of(
			    // Control Statements
			    GO, TO, ASSIGN, IF,
			    SENSE, LIGHT, SWITCH,
			    ACCUMULATOR, OVERFLOW, QUOTIENT, DIVIDE, CHECK,
			    PAUSE, STOP, DO, CONTINUE,
			    // Input/Output
			    READ, PUNCH, PRINT, INPUT,
			    WRITE, OUTPUT,
			    FORMAT,
			    TAPE, DRUM,
			    END, FILE, REWIND, BACKSPACE,
			    // Specification Statements
			    DIMENSTION, EQUIVALENCE, FREQUENCY
				);
		set = Collections.unmodifiableSet(keywords);
	}
	
	private Keyword() {
		// forbid instantiation
	}
}

@@ -61,16 +61,46 @@
 ype.*;%0A%0A
+import java.util.AbstractSet;%0A
 import j
@@ -164,19 +164,102 @@
 va.util.
-Set
+Iterator;%0Aimport java.util.Set;%0A%0Aimport com.google.common.collect.UnmodifiableIterator
 ;%0A%0A/**%0A 
@@ -1533,16 +1533,1173 @@
 );%0A%09%7D%0A%09%0A
+%09/**%0A%09 * String representations of all %7B@link LiteralType%7Ds%0A%09 * contained in %7B@link #set%7D.%0A%09 */%0A%09public static final Set%3CString%3E names = new AbstractSet%3CString%3E() %7B%0A%09%09@Override%0A%09%09public boolean contains(Object o) %7B%0A%09%09%09try %7B%0A%09%09%09%09LiteralType e = LiteralType.valueOf(o.toString().toUpperCase());%0A%09%09%09%09return set.contains(e);%0A%09%09%09%7D catch (IllegalArgumentException e) %7B%0A%09%09%09%09return false;%0A%09%09%09%7D%0A%09%09%7D%0A%09%09%0A%09%09@Override%0A%09%09public boolean remove(Object o) %7B%0A%09%09%09throw new UnsupportedOperationException();%0A%09%09%7D%0A%09%09%0A%09%09@Override%0A%09%09public Iterator%3CString%3E iterator() %7B%0A%09%09%09final Iterator%3CLiteralType%3E i = set.iterator();%0A%09%09%09return new UnmodifiableIterator%3CString%3E() %7B%0A%09%09%09%09@Override%0A%09%09%09%09public boolean hasNext() %7B%0A%09%09%09%09%09return i.hasNext();%0A%09%09%09%09%7D%0A%09%09%09%09%0A%09%09%09%09@Override%0A%09%09%09%09public String next() %7B%0A%09%09%09%09%09return i.next().name();%0A%09%09%09%09%7D%0A%09%09%09%7D;%0A%09%09%7D%0A%09%09%0A%09%09@Override%0A%09%09public int size() %7B%0A%09%09%09return set.size();%0A%09%09%7D%0A%09%7D;%0A%09%0A%09/**%0A%09 * Tells whether or not a given string represents a valid%0A%09 * keyword in the FORTRAN language.%0A%09 * %0A%09 * @param string to test%0A%09 * @return true if it is a keyword, false otherwise%0A%09 */%0A%09public static boolean isKeyword(String string) %7B%0A%09%09return names.contains(string);%0A%09%7D%0A%09%0A
 %09private

extend Keyword for lookup by name