Пример #1
0
        public static ValueTable AddTableWithSyntax(this ValueList list)
        {
            // Create a new item and matching syntax
            var newSyntaxTable = new InlineTableSyntax()
            {
                OpenBrace  = SyntaxFactory.Token(TokenKind.OpenBrace),
                CloseBrace = SyntaxFactory.Token(TokenKind.CloseBrace),
            };
            var newTable = new ValueTable()
            {
                MirrorSyntax = newSyntaxTable,
            };

            newSyntaxTable.CloseBrace.AddLeadingWhitespace();

            // Add the model to the parent table model
            list.Add(new Value(newTable));

            newSyntaxTable.LeadingTrivia = new List <SyntaxTrivia>()
            {
                new SyntaxTrivia(TokenKind.Whitespaces, "\t"),
            };

            // Add the new syntax to the parent table syntax
            var arrayItemSyntax = new ArrayItemSyntax()
            {
                Value = newSyntaxTable,
                Comma = SyntaxFactory.Token(TokenKind.Comma),
            };

            arrayItemSyntax.Comma.TrailingTrivia = new List <SyntaxTrivia>()
            {
                SyntaxFactory.NewLineTrivia(),
            };

            switch (list.MirrorSyntax)
            {
            case ArraySyntax arraySyntax:
                arraySyntax.Items.Add(arrayItemSyntax);
                break;

            default:
                throw new InvalidOperationException("Unknown Syntax on ValueList");
            }

            return(newTable);
        }
Пример #2
0
        private DeclaredTypeAssignment?GetArrayItemType(ArrayItemSyntax syntax)
        {
            var parent = this.hierarchy.GetParent(syntax);

            switch (parent)
            {
            case ArraySyntax _:
                // array items can only have array parents
                // use the declared item type
                var parentType = GetDeclaredTypeAssignment(parent)?.Reference.Type;
                if (parentType is ArrayType arrayType)
                {
                    return(new DeclaredTypeAssignment(arrayType.Item.Type, syntax));
                }

                break;
            }

            return(null);
        }
Пример #3
0
        public static void AddItemWithSyntax(this ValueList list, string value)
        {
            // Create a new item and matching syntax
            var newSyntaxValue = new StringValueSyntax(value);
            var newValue       = new Value(value)
            {
                // TODO: MirrorSyntax = newSyntaxTable,
            };

            // Add the model to the parent table model
            list.Add(newValue);

            newSyntaxValue.LeadingTrivia = new List <SyntaxTrivia>()
            {
                new SyntaxTrivia(TokenKind.Whitespaces, "\t"),
            };

            // Add the new syntax to the parent table syntax
            var arrayItemSyntax = new ArrayItemSyntax()
            {
                Value = newSyntaxValue,
                Comma = SyntaxFactory.Token(TokenKind.Comma),
            };

            arrayItemSyntax.Comma.TrailingTrivia = new List <SyntaxTrivia>()
            {
                SyntaxFactory.NewLineTrivia(),
            };

            switch (list.MirrorSyntax)
            {
            case ArraySyntax arraySyntax:
                arraySyntax.Items.Add(arrayItemSyntax);
                break;

            default:
                throw new InvalidOperationException("Unknown Syntax on ValueList");
            }
        }
Пример #4
0
        public override void VisitArrayItemSyntax(ArrayItemSyntax syntax)
        => AssignTypeWithCaching(syntax, () => {
            Visit(syntax.Value);

            return(assignedTypes[syntax.Value]);
        });