X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Fenvironment%2FEnvironments.java;h=2ce0ced5bd5e46438a93a54b3c7651fab130cba9;hp=4328d15e0b02535dfe695e06602702c19ea41218;hb=84b211a0aa05c956d33e038a1106bb0464ce373a;hpb=cb5fc8d606d8b322563e9345c441eecfa7f01753 diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java index 4328d15e0..2ce0ced5b 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/environment/Environments.java @@ -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 getRuleset = new NamespaceValueAccessor() { + @Override + public CHRRuleset get(Namespace ns, String name) throws AmbiguousNameException { + return ns.getRuleset(name); + } + }; private static T getEnvironmentEntry(Environment environment, String localName, NamespaceValueAccessor accessor) throws AmbiguousNameException { Namespace namespace = environment.getLocalNamespace();