From: Tuukka Lehtonen Date: Thu, 20 Sep 2018 12:46:12 +0000 (+0000) Subject: Merge "Added a class listing the reserved words of SCL language" X-Git-Tag: v1.43.0~136^2~367 X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=commitdiff_plain;h=96a52e35c714a09715e1ac17c53910cd31ced9c7;hp=006602e856bbc3e222789cfe00a923b863e3e91b Merge "Added a class listing the reserved words of SCL language" --- 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; + } + } +}