Added a class listing the reserved words of SCL language 09/2209/2
authorHannu Niemistö <hannu.niemisto@semantum.fi>
Thu, 20 Sep 2018 08:26:21 +0000 (11:26 +0300)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 20 Sep 2018 12:03:06 +0000 (12:03 +0000)
Change-Id: I22f9c0edd5b23bba9ae9c9cbc346d501972c87ef

bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/names/SCLReservedWords.java [new file with mode: 0644]

diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/names/SCLReservedWords.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/names/SCLReservedWords.java
new file mode 100644 (file)
index 0000000..7f6f80b
--- /dev/null
@@ -0,0 +1,65 @@
+package org.simantics.scl.compiler.common.names;
+
+import java.io.StringReader;
+
+import org.simantics.scl.compiler.internal.parsing.Token;
+import org.simantics.scl.compiler.internal.parsing.parser.SCLLexer;
+import org.simantics.scl.compiler.internal.parsing.parser.SCLTerminals;
+
+import gnu.trove.set.hash.THashSet;
+
+public class SCLReservedWords {
+    public static final String[] RESERVED_WORDS_ARRAY = {
+            "as",
+            "by",
+            "do",
+            "if",
+            "in",
+            "edo",
+            "let",
+            "mdo",
+            "data",
+            "else",
+            "rule",
+            "then",
+            "type",
+            "when",
+            "with",
+            "class",
+            "infix",
+            "match",
+            "where",
+            "effect",
+            "forall",
+            "hiding",
+            "import",
+            "infixl",
+            "infixr",
+            "select",
+            "enforce",
+            "include",
+            "ruleset",
+            "deriving",
+            "instance",
+            "constraint",
+            "importJava",
+            "transformation",
+    };
+
+    public static final THashSet<String> RESERVED_WORDS_SET = new THashSet<>();
+
+    static {
+        for(String word : RESERVED_WORDS_ARRAY)
+            RESERVED_WORDS_SET.add(word);
+    }
+
+    public static boolean isReserved(String str) {
+        try {
+            SCLLexer lexer = new SCLLexer(new StringReader(str));
+            Token token = lexer.nextToken();
+            return token.id != SCLTerminals.ID;
+        } catch(Exception e) {
+            return true;
+        }
+    }
+}