From: Hannu Niemistö Date: Thu, 20 Sep 2018 08:26:21 +0000 (+0300) Subject: Added a class listing the reserved words of SCL language X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F22%2F2722%2F1;p=simantics%2Fplatform.git Added a class listing the reserved words of SCL language Change-Id: I22f9c0edd5b23bba9ae9c9cbc346d501972c87ef --- 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 index 000000000..7f6f80b15 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/names/SCLReservedWords.java @@ -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 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; + } + } +}