]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/names/SCLReservedWords.java
Added a class listing the reserved words of SCL language
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / common / names / SCLReservedWords.java
1 package org.simantics.scl.compiler.common.names;
2
3 import java.io.StringReader;
4
5 import org.simantics.scl.compiler.internal.parsing.Token;
6 import org.simantics.scl.compiler.internal.parsing.parser.SCLLexer;
7 import org.simantics.scl.compiler.internal.parsing.parser.SCLTerminals;
8
9 import gnu.trove.set.hash.THashSet;
10
11 public class SCLReservedWords {
12     public static final String[] RESERVED_WORDS_ARRAY = {
13             "as",
14             "by",
15             "do",
16             "if",
17             "in",
18             "edo",
19             "let",
20             "mdo",
21             "data",
22             "else",
23             "rule",
24             "then",
25             "type",
26             "when",
27             "with",
28             "class",
29             "infix",
30             "match",
31             "where",
32             "effect",
33             "forall",
34             "hiding",
35             "import",
36             "infixl",
37             "infixr",
38             "select",
39             "enforce",
40             "include",
41             "ruleset",
42             "deriving",
43             "instance",
44             "constraint",
45             "importJava",
46             "transformation",
47     };
48
49     public static final THashSet<String> RESERVED_WORDS_SET = new THashSet<>();
50
51     static {
52         for(String word : RESERVED_WORDS_ARRAY)
53             RESERVED_WORDS_SET.add(word);
54     }
55
56     public static boolean isReserved(String str) {
57         try {
58             SCLLexer lexer = new SCLLexer(new StringReader(str));
59             Token token = lexer.nextToken();
60             return token.id != SCLTerminals.ID;
61         } catch(Exception e) {
62             return true;
63         }
64     }
65 }