From d966badf6bc675a4dbe31b07d1bc30b2a93725b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Hannu=20Niemist=C3=B6?= Date: Thu, 20 Sep 2018 11:26:21 +0300 Subject: [PATCH] Added a class listing the reserved words of SCL language Change-Id: I22f9c0edd5b23bba9ae9c9cbc346d501972c87ef --- .../common/names/SCLReservedWords.java | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/common/names/SCLReservedWords.java 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; + } + } +} -- 2.47.1