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.
diff --git a/parser/printer.go b/parser/printer.go
index 46ad34f..53fbbcc 100644
--- a/parser/printer.go
+++ b/parser/printer.go
@@ -107,7 +107,7 @@
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 @@
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 @@
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 @@
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)
}
diff --git a/parser/printer_test.go b/parser/printer_test.go
index 5b752e7..9f26230 100644
--- a/parser/printer_test.go
+++ b/parser/printer_test.go
@@ -25,93 +25,93 @@
}{
{
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 @@
{
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 @@
// test
module // test
-(
+ {
srcs
- = [
+ : [
"src1.c",
"src2.c",
],
//test
-)
+}
//test2
`,
output: `
// test
-module( // test
+module { // test
- srcs = [
+ srcs: [
"src1.c",
"src2.c",
],
//test
-)
+}
//test2
`,
},