コード例 #1
0
 public static KeyValueSyntax AddTrailingComment(this KeyValueSyntax keyValue, string comment)
 {
     if (keyValue == null)
     {
         throw new ArgumentNullException(nameof(keyValue));
     }
     if (keyValue.Value == null)
     {
         throw new InvalidOperationException("The Value must not be null on the KeyValueSyntax");
     }
     keyValue.Value.AddTrailingWhitespace().AddTrailingComment(comment);
     return(keyValue);
 }
 /// <summary>
 /// Creates an instance of <see cref="InlineTableItemSyntax"/>
 /// </summary>
 /// <param name="keyValue">The key=value</param>
 public InlineTableItemSyntax(KeyValueSyntax keyValue) : this()
 {
     KeyValue = keyValue ?? throw new ArgumentNullException(nameof(keyValue));
 }
コード例 #3
0
 public virtual void Visit(KeyValueSyntax keyValue)
 {
     DefaultVisit(keyValue);
 }
        public override void Visit(KeyValueSyntax keyValue)
        {
            var savedPath = _currentPath.Clone();

            if (keyValue.Key == null)
            {
                _diagnostics.Error(keyValue.Span, "A KeyValueSyntax must have a non null Key");
                // returns immediately
                return;
            }

            if (!KeyNameToObjectPath(keyValue.Key, ObjectKind.Table))
            {
                return;
            }

            ObjectKind kind;

            switch (keyValue.Value)
            {
            case ArraySyntax _:
                kind = ObjectKind.Array;
                break;

            case BooleanValueSyntax _:
                kind = ObjectKind.Boolean;
                break;

            case DateTimeValueSyntax time:
                switch (time.Kind)
                {
                case SyntaxKind.OffsetDateTime:
                    kind = ObjectKind.OffsetDateTime;
                    break;

                case SyntaxKind.LocalDateTime:
                    kind = ObjectKind.LocalDateTime;
                    break;

                case SyntaxKind.LocalDate:
                    kind = ObjectKind.LocalDate;
                    break;

                case SyntaxKind.LocalTime:
                    kind = ObjectKind.LocalTime;
                    break;

                default:
                    throw new NotSupportedException($"Unsupported datetime kind `{time.Kind}` for the key-value `{keyValue}`");
                }
                break;

            case FloatValueSyntax _:
                kind = ObjectKind.Float;
                break;

            case InlineTableSyntax _:
                kind = ObjectKind.Table;
                break;

            case IntegerValueSyntax _:
                kind = ObjectKind.Integer;
                break;

            case StringValueSyntax _:
                kind = ObjectKind.String;
                break;

            default:
                _diagnostics.Error(keyValue.Span, keyValue.Value == null ? $"A KeyValueSyntax must have a non null Value" : $"Not supported type `{keyValue.Value.Kind}` for the value of a KeyValueSyntax");
                return;
            }
            AddObjectPath(keyValue, kind, false);

            base.Visit(keyValue);
            _currentPath = savedPath;
        }