Go back to the old Blueprints file format

Switch back to:
moduleType {
    name: value,
    arch: {
        x86: {
            name: value,
        },
    },
}

This provides better consistency between properties defined at the
top level of a module and properties defined inside a map.

The parser will continue to support the other format for now, but the
printer will only produce the original format.
This commit is contained in:
Colin Cross 2015-03-02 15:32:36 -08:00
parent d9d92cb75d
commit cb7b9ad6ca
2 changed files with 64 additions and 76 deletions

View file

@ -107,7 +107,7 @@ func (p *printer) printAssignment(assignment *Assignment) {
func (p *printer) printModule(module *Module) {
p.printToken(module.Type.Name, module.Type.Pos, wsDontCare)
p.printMap(module.Properties, module.LbracePos, module.RbracePos, true)
p.printMap(module.Properties, module.LbracePos, module.RbracePos)
p.prev.ws = wsForceDoubleBreak
}
@ -131,7 +131,7 @@ func (p *printer) printValue(value Value) {
case List:
p.printList(value.ListValue, value.Pos, value.EndPos)
case Map:
p.printMap(value.MapValue, value.Pos, value.EndPos, false)
p.printMap(value.MapValue, value.Pos, value.EndPos)
default:
panic(fmt.Errorf("bad property type: %d", value.Type))
}
@ -156,26 +156,18 @@ func (p *printer) printList(list []Value, pos, endPos scanner.Position) {
p.printToken("]", endPos, wsDontCare)
}
func (p *printer) printMap(list []*Property, pos, endPos scanner.Position, isModule bool) {
if isModule {
p.printToken("(", pos, wsDontCare)
} else {
p.printToken("{", pos, wsBefore)
}
func (p *printer) printMap(list []*Property, pos, endPos scanner.Position) {
p.printToken("{", pos, wsBefore)
if len(list) > 0 || pos.Line != endPos.Line {
p.prev.ws = wsForceBreak
p.indent(p.curIndent() + 4)
for _, prop := range list {
p.printProperty(prop, isModule)
p.printProperty(prop)
p.printToken(",", noPos, wsForceBreak)
}
p.unindent()
}
if isModule {
p.printToken(")", endPos, wsForceDoubleBreak)
} else {
p.printToken("}", endPos, wsDontCare)
}
p.printToken("}", endPos, wsDontCare)
}
func (p *printer) printExpression(expression Expression) {
@ -184,13 +176,9 @@ func (p *printer) printExpression(expression Expression) {
p.printValue(expression.Args[1])
}
func (p *printer) printProperty(property *Property, isModule bool) {
func (p *printer) printProperty(property *Property) {
p.printToken(property.Name.Name, property.Name.Pos, wsDontCare)
if isModule {
p.printToken("=", property.Pos, wsBoth)
} else {
p.printToken(":", property.Pos, wsAfter)
}
p.printToken(":", property.Pos, wsAfter)
p.printValue(property.Value)
}

View file

@ -25,93 +25,93 @@ var validPrinterTestCases = []struct {
}{
{
input: `
foo ()
foo {}
`,
output: `
foo()
foo {}
`,
},
{
input: `
foo(name= "abc",)
foo{name= "abc",}
`,
output: `
foo(
name = "abc",
)
foo {
name: "abc",
}
`,
},
{
input: `
foo(
stuff = ["asdf", "jkl;", "qwert",
foo {
stuff: ["asdf", "jkl;", "qwert",
"uiop", "bnm,"]
)
}
`,
output: `
foo(
stuff = [
foo {
stuff: [
"asdf",
"bnm,",
"jkl;",
"qwert",
"uiop",
],
)
}
`,
},
{
input: `
foo(
stuff = {
foo {
stuff: {
isGood: true,
name: "bar"
}
)
}
`,
output: `
foo(
stuff = {
foo {
stuff: {
isGood: true,
name: "bar",
},
)
}
`,
},
{
input: `
// comment1
foo(
foo {
// comment2
isGood = true, // comment3
)
isGood: true, // comment3
}
`,
output: `
// comment1
foo(
foo {
// comment2
isGood = true, // comment3
)
isGood: true, // comment3
}
`,
},
{
input: `
foo(
name = "abc",
)
foo {
name: "abc",
}
bar (
name = "def",
)
bar {
name: "def",
}
`,
output: `
foo(
name = "abc",
)
foo {
name: "abc",
}
bar(
name = "def",
)
bar {
name: "def",
}
`,
},
{
@ -131,41 +131,41 @@ baz += foo
{
input: `
//test
test /* test */(
srcs = [
test /* test */ {
srcs: [
/*"blueprint/bootstrap/bootstrap.go",
"blueprint/bootstrap/cleanup.go",*/
"blueprint/bootstrap/command.go",
"blueprint/bootstrap/doc.go", //doc.go
"blueprint/bootstrap/config.go", //config.go
],
deps = ["libabc"],
incs = []
) //test
deps: ["libabc"],
incs: []
} //test
//test
test2(
)
test2 {
}
//test3
`,
output: `
//test
test /* test */ (
srcs = [
test /* test */ {
srcs: [
/*"blueprint/bootstrap/bootstrap.go",
"blueprint/bootstrap/cleanup.go",*/
"blueprint/bootstrap/command.go",
"blueprint/bootstrap/config.go", //config.go
"blueprint/bootstrap/doc.go", //doc.go
],
deps = ["libabc"],
incs = [],
) //test
deps: ["libabc"],
incs: [],
} //test
//test
test2(
)
test2 {
}
//test3
`,
@ -175,26 +175,26 @@ test2(
// test
module // test
(
{
srcs
= [
: [
"src1.c",
"src2.c",
],
//test
)
}
//test2
`,
output: `
// test
module( // test
module { // test
srcs = [
srcs: [
"src1.c",
"src2.c",
],
//test
)
}
//test2
`,
},