#simplify

-- simplify.input --
import "time"

"foo": "bar": "str"

a: "B": 42

"a.b": "foo-": "cc_dd": x

@attr(3)

a:
    b:
        c: 3

// references to bar are all shadowed and this can be safely turned into
// an identifier.
"bar": "str"

// These references would be directly referred to if turned into an identifier.
// The quotes should therefore not be removed.
"baz1": 3
"baz2": 3
"baz3": 3 // TODO: could be simplified.

// These string labels may be turned into an identifier.
"qux": 4
"quux": 5

// TODO(legacy): Don't simplify "hidden" fields for now.
"_foo": 3

// Issue #294
"\("x")": "x"

(x): "foo"
(x)?: "foo"
(x)!: "foo"

a: {
    [string]: _
    foo: 2
}

"#A": dontSimplify

x: {
@tag0(foo)
    r1: baz1
    bar: r2: bar
    r3: bar
    E=quux: 3

        @tag1(bar)
    r4: quux
    [baz2="str"]: 4
    r5: baz2
    [baz3="bar"]: name: baz3
    "Time": time.Time
}

y: {
    "a": {
        "bar": "a-value"
        [!="bar"]: {}
    }

    "b": {
        "x": {
            "bar": "bar"
            "baz": "baz"
            [!={
                "a": "baz"
            }.a & !="bar"]: {}
        }

        "y": {
            "bar": "a-value"
            ({
                "a": "bar"
            }.a): {}
        }
    }
}

{
    foo: {}
    bar: "foo": foo // removing the quotes would cause a cyclic reference
}
-- out/format/simplify.golden --
import "time"

foo: bar: "str"

a: B: 42

"a.b": "foo-": cc_dd: x

@attr(3)

a: b: c: 3

// references to bar are all shadowed and this can be safely turned into
// an identifier.
bar: "str"

// These references would be directly referred to if turned into an identifier.
// The quotes should therefore not be removed.
"baz1": 3
"baz2": 3
"baz3": 3 // TODO: could be simplified.

// These string labels may be turned into an identifier.
qux:  4
quux: 5

// TODO(legacy): Don't simplify "hidden" fields for now.
"_foo": 3

// Issue #294
"\("x")": "x"

(x):  "foo"
(x)?: "foo"
(x)!: "foo"

a: {
	foo: 2
	...
}

"#A": dontSimplify

x: {
	@tag0(foo)
	r1: baz1
	bar: r2: bar
	r3:     bar
	E=quux: 3

	@tag1(bar)
	r4:           quux
	[baz2="str"]: 4
	r5:           baz2
	[baz3="bar"]: name: baz3
	Time: time.Time
}

y: {
	a: {
		bar: "a-value"
		[!="bar"]: {}
	}
	b: {
		x: {
			bar: "bar"
			baz: "baz"
			[!={
				"a": "baz"
			}.a & !="bar"]: {}
		}
		y: {
			bar: "a-value"
			({
				"a": "bar"
			}.a): {}
		}
	}
}

{
	foo: {}
	bar: "foo": foo // removing the quotes would cause a cyclic reference
}
