예제 #1
0
        private StyleConstant ResolveReference(StyleCompileContext context, ConstReferenceNode constReference)
        {
            if (currentlyResolvingConstants.Contains(constReference.identifier))
            {
                throw new CompileException(constReference, "Circular dependency detected!");
            }

            for (int i = 0; i < context.constants.Count; i++)
            {
                StyleConstant constant = context.constants[i];
                if (constant.name == constReference.identifier)
                {
                    // reference resolved
                    return(constant);
                }
            }

            // now we have to recursively resolve the reference of the reference:
            // const x: string = @y; // we're here...
            // const y: string = @z: // ....referencing this
            // const z: string = "whatup"; // ...which will resolve to this.
            if (context.constantsWithReferences.ContainsKey(constReference.identifier))
            {
                currentlyResolvingConstants.Add(constReference.identifier);
                StyleConstant resolvedConstant = Resolve(context, context.constantsWithReferences[constReference.identifier]);
                currentlyResolvingConstants.Remove(constReference.identifier);
                return(resolvedConstant);
            }

            throw new CompileException(constReference, $"Could not resolve reference {constReference}. Known references are: " + context.PrintConstants());
        }
예제 #2
0
        private StyleASTNode ParseConstReference()
        {
            AdvanceIfTokenType(StyleTokenType.At);
            ConstReferenceNode constReferenceNode = StyleASTNodeFactory.ConstReferenceNode(AssertTokenTypeAndAdvance(StyleTokenType.Identifier));

            while (tokenStream.HasMoreTokens && AdvanceIfTokenType(StyleTokenType.Dot))
            {
                constReferenceNode.AddChildNode(StyleASTNodeFactory.DotAccessNode(AssertTokenTypeAndAdvance(StyleTokenType.Identifier)).WithLocation(tokenStream.Previous));
            }

            return(constReferenceNode);
        }