public BoundStringLiteralExpression(StringLiteralExpressionSyntax syntax, bool hasValue, bool hasErrors, string value)
            : base(hasValue, hasErrors)
        {
            Debug.Assert(!syntax.IsDefault(), "'syntax' must not be null.");
            Debug.Assert(!value.IsDefault(), "'value' must not be null.");

            this.Syntax = syntax;
            this.Value  = value;
        }
        public static void SetAnnotations(List <VariableDeclarationStatementSyntax> annotations)
        {
            if (annotations == null || !_varValid)
            {
                return;
            }
            _activeVar.Annotations = new Dictionary <string, string>();
            foreach (VariableDeclarationStatementSyntax vdsSyntax in annotations)
            {
                SeparatedSyntaxList <VariableDeclaratorSyntax> sSyntaxList = vdsSyntax.Declaration.Variables;
                if (sSyntaxList.Count != 1)
                {
                    _varValid = false;
                    return;
                }
                VariableDeclaratorSyntax vdSyntax = sSyntaxList[0];
                string key = vdSyntax.Identifier.ValueText;
                EqualsValueClauseSyntax evcSyntax = (EqualsValueClauseSyntax)vdSyntax.Initializer;

                string value = "";
                if (evcSyntax.Value is StringLiteralExpressionSyntax)
                {
                    StringLiteralExpressionSyntax sleSyntax = (StringLiteralExpressionSyntax)evcSyntax.Value;
                    List <SyntaxToken>            tokens    = sleSyntax.Tokens;
                    if (tokens.Count > 0)
                    {
                        value = tokens[0].ValueText;
                    }
                }
                else if (evcSyntax.Value is PrefixUnaryExpressionSyntax)
                {
                    PrefixUnaryExpressionSyntax ueSyntax = (PrefixUnaryExpressionSyntax)evcSyntax.Value;
                    value = ueSyntax.ToString();
                }
                else if (evcSyntax.Value is LiteralExpressionSyntax)
                {
                    LiteralExpressionSyntax ueSyntax = (LiteralExpressionSyntax)evcSyntax.Value;
                    value = ueSyntax.ToString();
                }
                else
                {
                    throw new Exception("Unsupported annontation");
                }

                _activeVar.Annotations.Add(key, value);
            }
        }
Example #3
0
        private static BoundStringLiteralExpression BindStringLiteralExpression(StringLiteralExpressionSyntax syntax)
        {
            string value = syntax.StringToken.Text;

            if (value.Length < 1 || value[0] != '"')
            {
                throw new InvalidOperationException($"String literal '{value}' should have never been parsed without a starting double quotes.");
            }

            value = value.Substring(1);
            if (value.Length > 0 && value[value.Length - 1] == '"')
            {
                value = value.Substring(0, value.Length - 1);
            }

            return(new BoundStringLiteralExpression(syntax, hasValue: true, hasErrors: false, value));
        }
        private ExpressionSyntax ParseTerm()
        {
            ExpressionSyntax expr;

            var tk = Current.Kind;
            switch (tk)
            {
                case SyntaxKind.IdentifierToken:
                    expr = ParseIdentifier();
                    break;
                case SyntaxKind.FalseKeyword:
                case SyntaxKind.TrueKeyword:
                case SyntaxKind.IntegerLiteralToken:
                case SyntaxKind.FloatLiteralToken:
                    expr = new LiteralExpressionSyntax(SyntaxFacts.GetLiteralExpression(Current.Kind), NextToken());
                    break;
                case SyntaxKind.StringLiteralToken:
                {
                    var stringTokens = new List<SyntaxToken> { NextToken() };
                    while (Current.Kind == SyntaxKind.StringLiteralToken)
                        stringTokens.Add(NextToken());
                    expr = new StringLiteralExpressionSyntax(stringTokens);
                    break;
                }
                case SyntaxKind.OpenParenToken:
                    expr = ParseCastOrParenthesizedExpression();
                    break;
                default:
                    if ((SyntaxFacts.IsPredefinedScalarType(tk) && tk != SyntaxKind.UnsignedKeyword && tk != SyntaxKind.VoidKeyword)
                        || SyntaxFacts.IsPredefinedVectorType(tk)
                        || SyntaxFacts.IsPredefinedMatrixType(tk))
                    {
                        if (Lookahead.Kind == SyntaxKind.OpenParenToken)
                        {
                            expr = ParseNumericConstructorInvocationExpression();
                            break;
                        }
                    }

                    expr = CreateMissingIdentifierName();

                    if (tk == SyntaxKind.EndOfFileToken)
                        expr = WithDiagnostic(expr, DiagnosticId.ExpressionExpected);
                    else
                        expr = WithDiagnostic(expr, DiagnosticId.InvalidExprTerm, tk.GetText());

                    break;
            }

            return ParsePostFixExpression(expr);
        }
Example #5
0
 private static BoundExpression BindStringLiteralExpression(StringLiteralExpressionSyntax syntax)
 {
     return(new BoundStringLiteralExpression(syntax.Tokens.Select(x => x.Text).ToImmutableArray()));
 }
        private ExpressionSyntax ParseTerm()
        {
            ExpressionSyntax expr;

            var tk = Current.Kind;

            switch (tk)
            {
            case SyntaxKind.IdentifierToken:
                expr = ParseIdentifierOrFunctionInvocationExpression();
                break;

            case SyntaxKind.FalseKeyword:
            case SyntaxKind.TrueKeyword:
            case SyntaxKind.IntegerLiteralToken:
            case SyntaxKind.FloatLiteralToken:
                expr = new LiteralExpressionSyntax(SyntaxFacts.GetLiteralExpression(Current.Kind), NextToken());
                break;

            case SyntaxKind.StringLiteralToken:
            {
                var stringTokens = new List <SyntaxToken> {
                    NextToken()
                };
                while (Current.Kind == SyntaxKind.StringLiteralToken)
                {
                    stringTokens.Add(NextToken());
                }
                expr = new StringLiteralExpressionSyntax(stringTokens);
                break;
            }

            case SyntaxKind.OpenParenToken:
                expr = ParseCastOrParenthesizedExpression();
                break;

            default:
                if (_allowLinearAndPointAsIdentifiers && (tk == SyntaxKind.LinearKeyword || tk == SyntaxKind.PointKeyword))
                {
                    goto case SyntaxKind.IdentifierToken;
                }

                if ((SyntaxFacts.IsPredefinedScalarType(tk) && tk != SyntaxKind.UnsignedKeyword && tk != SyntaxKind.VoidKeyword) || SyntaxFacts.IsPredefinedVectorType(tk) || SyntaxFacts.IsPredefinedMatrixType(tk))
                {
                    if (Lookahead.Kind == SyntaxKind.OpenParenToken)
                    {
                        expr = ParseNumericConstructorInvocationExpression();
                        break;
                    }
                }

                expr = CreateMissingIdentifierName();

                if (tk == SyntaxKind.EndOfFileToken)
                {
                    expr = WithDiagnostic(expr, DiagnosticId.ExpressionExpected);
                }
                else
                {
                    expr = WithDiagnostic(expr, DiagnosticId.InvalidExprTerm, tk.GetText());
                }

                break;
            }

            return(ParsePostFixExpression(expr));
        }
Example #7
0
 public virtual void VisitStringLiteralExpression(StringLiteralExpressionSyntax node)
 {
     DefaultVisit(node);
 }
 public virtual void VisitStringLiteralExpression(StringLiteralExpressionSyntax node)
 {
     DefaultVisit(node);
 }