Beispiel #1
0
        private List <Expression> EnumerateTaggedExpressionsForStringInterpolation(ITemplateExpression template, FunctionScope escapes, QualifierSpaceId currentQualifierSpaceId)
        {
            // Creating a list that will hold all potential expressions
            List <Expression> result = new List <Expression>((template.TemplateSpans.Length * 2) + 1);

            var head = template.Head.Text;

            if (!string.IsNullOrEmpty(head))
            {
                result.Add(LiteralConverter.ConvertStringLiteral(head, Location(template.Head)));
            }

            for (int i = 0; i < template.TemplateSpans.Length; i++)
            {
                var span = template.TemplateSpans[i];
                if (span.Expression != null)
                {
                    var convertedExpression = m_converter.ConvertExpression(span.Expression, escapes, currentQualifierSpaceId);
                    if (convertedExpression != null)
                    {
                        result.Add(convertedExpression);
                    }
                }

                var fragment = span.Literal.Text;

                if (!string.IsNullOrEmpty(fragment))
                {
                    result.Add(LiteralConverter.ConvertStringLiteral(fragment, Location(template.Head)));
                }
            }

            return(result);
        }
        /// <summary>
        /// Converts provided literal from string representation to 32-bit integer.
        /// </summary>
        public static Number TryConvertToNumber(this TypeScript.Net.Types.ILiteralExpression literal)
        {
            Contract.Requires(literal != null);
            Contract.Requires(literal.Kind == TypeScript.Net.Types.SyntaxKind.NumericLiteral);

            return(LiteralConverter.TryConvertNumber(literal.Text));
        }
Beispiel #3
0
        public InterpolationConverter(AstConverter astConverter, AstConversionContext conversionContext)
        {
            Contract.Requires(astConverter != null);
            Contract.Requires(conversionContext != null);

            m_converter = astConverter;
            m_context   = conversionContext;

            m_literalConverter = new LiteralConverter(conversionContext);
            m_pathAtomInterpolateSelectorExpression = CreatePathAtomInterpolateSelectorExpression();
            m_stringInterpolationSelectorExpression = CreateStringInterpolateSelectorExpression();
        }
Beispiel #4
0
        internal static int AsNumber(this ILiteralExpression literalExpression, bool isNegative)
        {
            Contract.Requires(literalExpression != null);

            string text = isNegative ? I($"-{literalExpression.Text}") : literalExpression.Text;

            var result = LiteralConverter.TryConvertNumber(text);

            if (!result.IsValid)
            {
                Contract.Assert(false, I($"Conversion from literal expression to number should be successful. Text: {literalExpression.Text}"));
            }

            return(result.Value);
        }