]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java
(refs #7386) Minor SCL tools improvements
[simantics/platform.git] / bundles / org.simantics.scl.compiler / src / org / simantics / scl / compiler / environment / Environments.java
index 4328d15e0b02535dfe695e06602702c19ea41218..2ce0ced5bd5e46438a93a54b3c7651fab130cba9 100644 (file)
@@ -7,6 +7,7 @@ import java.util.function.Consumer;
 
 import org.simantics.scl.compiler.common.names.Name;
 import org.simantics.scl.compiler.compilation.CompilationContext;
+import org.simantics.scl.compiler.elaboration.chr.CHRRuleset;
 import org.simantics.scl.compiler.elaboration.contexts.TypeTranslationContext;
 import org.simantics.scl.compiler.elaboration.modules.SCLValue;
 import org.simantics.scl.compiler.elaboration.modules.TypeClass;
@@ -107,6 +108,10 @@ public class Environments {
        return getEnvironmentEntry(environment, localName, getTypeClass);
     }
 
+    public static CHRRuleset getRuleset(Environment environment, String localName) throws AmbiguousNameException {
+        return getEnvironmentEntry(environment, localName, getRuleset);
+    }
+    
     /**
      * Get the Name object representing an SCL value defined in a given environment.
      * The name can be a local name or a fully scoped name with modules separated by periods. 
@@ -186,7 +191,7 @@ public class Environments {
             TypeAst typeAst = (TypeAst)parser.parseType();
             TypeTranslationContext context = new TypeTranslationContext(compilationContext);
             Type type = context.toType(typeAst);
-            if(compilationContext.errorLog.isEmpty())
+            if(compilationContext.errorLog.hasNoErrors())
                 return type;
         } catch(SCLSyntaxErrorException e) {
             compilationContext.errorLog.log(e.location, e.getMessage());
@@ -236,6 +241,8 @@ public class Environments {
             Namespace childNamespace = namespace.getNamespace(prefix.substring(0, p));
             if(childNamespace != null)
                 findValuesForPrefix(childNamespace, prefix.substring(p+1), proc);
+            else
+                namespace.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
         }
         else
             namespace.findValuesForPrefix(prefix, AcceptAllNamespaceFilter.INSTANCE, proc);
@@ -332,6 +339,13 @@ public class Environments {
                        return ns.getTypeClass(name);
                }               
        };
+       
+    private static final NamespaceValueAccessor<CHRRuleset> getRuleset = new NamespaceValueAccessor<CHRRuleset>() {
+        @Override
+        public CHRRuleset get(Namespace ns, String name) throws AmbiguousNameException {
+            return ns.getRuleset(name);
+        }
+    };
     
        private static <T> T getEnvironmentEntry(Environment environment, String localName, NamespaceValueAccessor<T> accessor) throws AmbiguousNameException {
         Namespace namespace = environment.getLocalNamespace();