diff options
Diffstat (limited to 'configgen/src/main/java/com/yahoo/config/codegen/ReservedWords.java')
-rw-r--r-- | configgen/src/main/java/com/yahoo/config/codegen/ReservedWords.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/configgen/src/main/java/com/yahoo/config/codegen/ReservedWords.java b/configgen/src/main/java/com/yahoo/config/codegen/ReservedWords.java new file mode 100644 index 00000000000..145f2da3245 --- /dev/null +++ b/configgen/src/main/java/com/yahoo/config/codegen/ReservedWords.java @@ -0,0 +1,72 @@ +// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.config.codegen; + +import java.util.HashMap; +import java.util.regex.Pattern; + +/** + * Reserved words that cannot be used as variable names in a config definition file. + * + * @author <a href="mailto:musum@yahoo-inc.com">Harald Musum</a> + * @since 2009-06-24 + */ + +public class ReservedWords { + + public static final String INTERNAL_PREFIX = "__"; + final static Pattern internalPrefixPattern = Pattern.compile("^" + INTERNAL_PREFIX + ".*"); + final static Pattern capitalizedPattern = Pattern.compile("^[A-Z].*"); + + private static final String[] cKeywords = + {"asm", "auto", "bool", "break", "case", "catch", + "char", "class", "const", "const_cast", "continue", "default", + "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit", + "export", "extern", "false", "float", "for", "friend", "goto", "if", + "inline", "int", "item", "long", "mutable", "namespace", "new", "operator", + "private", "protected", "public", "register", "reinterpret_cast", + "return", "short", "signed", "sizeof", "static", "static_cast", + "struct", "switch", "template", "this", "throw", "true", "try", + "typedef", "typeid", "typename", "union", "unsigned", + "using", "virtual", "void", "volatile", "wchar_t", "while", "and", "bitor", + "not", "or", "xor", "and_eq", "compl", "not_eq", "or_eq", "xor_eq", + "bitand"}; + + private static final String[] javaKeywords = + {"abstract", "boolean", "break", "byte", "case", + "catch", "char", "class","continue", "default", "do", "double", + "else", "extends","false", "final", "finally", "float", "for", + "if","implements", "import", "instanceof", "int", "interface", + "item", "long","native", "new", "null", "package", "private", + "protected","public", "return", "short", "static", + "strictfp","super","switch", "synchronized", "this", + "throw","throws","transient", "true", "try", "void", + "volatile","while", "byvalue", "cast", "const", "future", + "generic","goto", "inner", "operator", "outer", "rest", "var"}; + + private static final HashMap<String, String> allKeyWords; + + static { + allKeyWords = new HashMap<String, String>(); + for (String s : cKeywords) { + allKeyWords.put(s, "C"); + } + for (String s : javaKeywords) { + if (allKeyWords.containsKey(s)) { + allKeyWords.put(s, "C and Java"); + } else { + allKeyWords.put(s, "Java"); + } + } + } + + + public static boolean isReservedWord(String word) { + return allKeyWords.containsKey(word); + } + + public static String getLanguageForReservedWord(String word) { + return allKeyWords.get(word); + } + + +} |