コード例 #1
0
        /// <summary>
        /// Method that converts tagged ast node into <see cref="Expression"/>.
        /// </summary>
        public Expression ConvertInterpolation(ITaggedTemplateExpression source, FunctionScope escapes, QualifierSpaceId currentQualifierSpaceId)
        {
            (var interpolationKind, ILiteralExpression literal, ITemplateLiteralFragment head, INodeArray <ITemplateSpan> templateSpans) = source;
            var tagTemplate = new ProcessedTagTemplateExpression(source, interpolationKind, literal, head, templateSpans);

            switch (interpolationKind)
            {
            case InterpolationKind.PathInterpolation:
                return(ConvertPathInterpolation(ref tagTemplate, escapes, currentQualifierSpaceId));

            case InterpolationKind.FileInterpolation:
                return(ConvertFileInterpolation(ref tagTemplate, escapes, currentQualifierSpaceId));

            case InterpolationKind.DirectoryInterpolation:
                return(ConvertDirectoryInterpolation(ref tagTemplate, escapes, currentQualifierSpaceId));

            case InterpolationKind.PathAtomInterpolation:
                return(ConvertPathAtomInterpolation(ref tagTemplate, escapes, currentQualifierSpaceId));

            case InterpolationKind.RelativePathInterpolation:
                return(ConvertRelativePathInterpolation(ref tagTemplate, escapes, currentQualifierSpaceId));

            default:
                throw Contract.AssertFailure(I($"Unknown interpolation kind '{interpolationKind}'."));
            }
        }
コード例 #2
0
        private Expression ConvertPathAtomInterpolation(ref ProcessedTagTemplateExpression source, FunctionScope escapes, QualifierSpaceId currentQualifierSpaceId)
        {
            if (source.Literal != null)
            {
                return(m_literalConverter.ConvertPathAtomLiteral(source.Literal, Location(source.TaggedTemplate)));
            }

            return(CurrentPathAtomInterpolationExpression(ref source, escapes, currentQualifierSpaceId));
        }
コード例 #3
0
        private Expression ConvertDirectoryInterpolation(ref ProcessedTagTemplateExpression source, FunctionScope escapes, QualifierSpaceId currentQualifierSpaceId)
        {
            var pathExpression = ConvertPathInterpolation(ref source, escapes, currentQualifierSpaceId);

            if (pathExpression == null)
            {
                // Error occurred. Error was already logged
                return(null);
            }

            return(new DirectoryLiteralExpression(pathExpression, pathExpression.Location));
        }
コード例 #4
0
        private Expression CurrentPathAtomInterpolationExpression(ref ProcessedTagTemplateExpression source, FunctionScope escapes, QualifierSpaceId currentQualifierSpaceId)
        {
            var expressions = EnumerateTaggedExpressionsForPathAtomInterpolation(source.Head, source.TemplateSpans, escapes, currentQualifierSpaceId);

            // Expressions could be empty only for the case like a``;
            if (expressions == null || expressions.Count == 0)
            {
                return(null);
            }

            return(ApplyExpression.Create(m_pathAtomInterpolateSelectorExpression, expressions.ToArray(), expressions[0].Location));
        }
コード例 #5
0
        private Expression ConvertPathInterpolationExpression(ref ProcessedTagTemplateExpression source, FunctionScope escapes, QualifierSpaceId currentQualifierSpaceId, bool isRelativePath)
        {
            var expressions = EnumerateTemplateSpans(source.Head, source.TemplateSpans, escapes, currentQualifierSpaceId, isRelativePath: isRelativePath);

            // Expressions could be empty only for the case like p``;
            if (expressions == null || expressions.Count == 0)
            {
                return(null);
            }

            return(new InterpolatedPaths(expressions, isRelativePath, expressions[0].Location));
        }