Remove blueprint/parser.Ident
It wasn't adding anything useful, and it resulted in Name.Name to get to the identifier. Replace Name Ident with Name string; NamePos scanner.Position. Change-Id: Idf9b18b31dd563a18f27c602c2d14298955af371
This commit is contained in:
parent
d4f49b07d1
commit
c32c47938f
7 changed files with 100 additions and 82 deletions
|
@ -124,9 +124,9 @@ func findModules(file *parser.File) (modified bool, errs []error) {
|
||||||
for _, def := range file.Defs {
|
for _, def := range file.Defs {
|
||||||
if module, ok := def.(*parser.Module); ok {
|
if module, ok := def.(*parser.Module); ok {
|
||||||
for _, prop := range module.Properties {
|
for _, prop := range module.Properties {
|
||||||
if prop.Name.Name == "name" && prop.Value.Type() == parser.StringType {
|
if prop.Name == "name" && prop.Value.Type() == parser.StringType {
|
||||||
if targetedModule(prop.Value.Eval().(*parser.String).Value) {
|
if targetedModule(prop.Value.Eval().(*parser.String).Value) {
|
||||||
m, newErrs := processModule(module, prop.Name.Name, file)
|
m, newErrs := processModule(module, prop.Name, file)
|
||||||
errs = append(errs, newErrs...)
|
errs = append(errs, newErrs...)
|
||||||
modified = modified || m
|
modified = modified || m
|
||||||
}
|
}
|
||||||
|
@ -142,7 +142,7 @@ func processModule(module *parser.Module, moduleName string,
|
||||||
file *parser.File) (modified bool, errs []error) {
|
file *parser.File) (modified bool, errs []error) {
|
||||||
|
|
||||||
for _, prop := range module.Properties {
|
for _, prop := range module.Properties {
|
||||||
if prop.Name.Name == *parameter {
|
if prop.Name == *parameter {
|
||||||
modified, errs = processParameter(prop.Value, *parameter, moduleName, file)
|
modified, errs = processParameter(prop.Value, *parameter, moduleName, file)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
11
context.go
11
context.go
|
@ -1040,8 +1040,7 @@ func (c *Context) prettyPrintVariant(variant variationMap) string {
|
||||||
func (c *Context) processModuleDef(moduleDef *parser.Module,
|
func (c *Context) processModuleDef(moduleDef *parser.Module,
|
||||||
relBlueprintsFile string) (*moduleInfo, []error) {
|
relBlueprintsFile string) (*moduleInfo, []error) {
|
||||||
|
|
||||||
typeName := moduleDef.Type.Name
|
factory, ok := c.moduleFactories[moduleDef.Type]
|
||||||
factory, ok := c.moduleFactories[typeName]
|
|
||||||
if !ok {
|
if !ok {
|
||||||
if c.ignoreUnknownModuleTypes {
|
if c.ignoreUnknownModuleTypes {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -1049,8 +1048,8 @@ func (c *Context) processModuleDef(moduleDef *parser.Module,
|
||||||
|
|
||||||
return nil, []error{
|
return nil, []error{
|
||||||
&Error{
|
&Error{
|
||||||
Err: fmt.Errorf("unrecognized module type %q", typeName),
|
Err: fmt.Errorf("unrecognized module type %q", moduleDef.Type),
|
||||||
Pos: moduleDef.Type.Pos,
|
Pos: moduleDef.TypePos,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1059,7 +1058,7 @@ func (c *Context) processModuleDef(moduleDef *parser.Module,
|
||||||
|
|
||||||
module := &moduleInfo{
|
module := &moduleInfo{
|
||||||
logicModule: logicModule,
|
logicModule: logicModule,
|
||||||
typeName: typeName,
|
typeName: moduleDef.Type,
|
||||||
relBlueprintsFile: relBlueprintsFile,
|
relBlueprintsFile: relBlueprintsFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1074,7 +1073,7 @@ func (c *Context) processModuleDef(moduleDef *parser.Module,
|
||||||
return nil, errs
|
return nil, errs
|
||||||
}
|
}
|
||||||
|
|
||||||
module.pos = moduleDef.Type.Pos
|
module.pos = moduleDef.TypePos
|
||||||
module.propertyPos = make(map[string]scanner.Position)
|
module.propertyPos = make(map[string]scanner.Position)
|
||||||
for name, propertyDef := range propertyMap {
|
for name, propertyDef := range propertyMap {
|
||||||
module.propertyPos[name] = propertyDef.Pos
|
module.propertyPos[name] = propertyDef.Pos
|
||||||
|
|
|
@ -29,7 +29,8 @@ type Definition interface {
|
||||||
// An Assignment is a variable assignment at the top level of a Blueprints file, scoped to the
|
// An Assignment is a variable assignment at the top level of a Blueprints file, scoped to the
|
||||||
// file and and subdirs.
|
// file and and subdirs.
|
||||||
type Assignment struct {
|
type Assignment struct {
|
||||||
Name Ident
|
Name string
|
||||||
|
NamePos scanner.Position
|
||||||
Value Expression
|
Value Expression
|
||||||
OrigValue Expression
|
OrigValue Expression
|
||||||
Pos scanner.Position
|
Pos scanner.Position
|
||||||
|
@ -45,7 +46,8 @@ func (a *Assignment) definitionTag() {}
|
||||||
|
|
||||||
// A Module is a module definition at the top level of a Blueprints file
|
// A Module is a module definition at the top level of a Blueprints file
|
||||||
type Module struct {
|
type Module struct {
|
||||||
Type Ident
|
Type string
|
||||||
|
TypePos scanner.Position
|
||||||
Map
|
Map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,11 +72,15 @@ func (m *Module) String() string {
|
||||||
|
|
||||||
func (m *Module) definitionTag() {}
|
func (m *Module) definitionTag() {}
|
||||||
|
|
||||||
|
func (m *Module) Pos() scanner.Position { return m.TypePos }
|
||||||
|
func (m *Module) End() scanner.Position { return m.Map.End() }
|
||||||
|
|
||||||
// A Property is a name: value pair within a Map, which may be a top level Module.
|
// A Property is a name: value pair within a Map, which may be a top level Module.
|
||||||
type Property struct {
|
type Property struct {
|
||||||
Name Ident
|
Name string
|
||||||
Value Expression
|
NamePos scanner.Position
|
||||||
Pos scanner.Position
|
Pos scanner.Position
|
||||||
|
Value Expression
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Property) Copy() *Property {
|
func (p *Property) Copy() *Property {
|
||||||
|
@ -87,17 +93,6 @@ func (p *Property) String() string {
|
||||||
return fmt.Sprintf("%s@%s: %s", p.Name, p.Pos, p.Value)
|
return fmt.Sprintf("%s@%s: %s", p.Name, p.Pos, p.Value)
|
||||||
}
|
}
|
||||||
|
|
||||||
// An Ident is a name identifier, the Type of a Module, the Name of a Property, or the Name of a
|
|
||||||
// Variable.
|
|
||||||
type Ident struct {
|
|
||||||
Name string
|
|
||||||
Pos scanner.Position
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i Ident) String() string {
|
|
||||||
return fmt.Sprintf("%s@%s", i.Name, i.Pos)
|
|
||||||
}
|
|
||||||
|
|
||||||
// An Expression is a Value in a Property or Assignment. It can be a literal (String or Bool), a
|
// An Expression is a Value in a Property or Assignment. It can be a literal (String or Bool), a
|
||||||
// Map, a List, an Operator that combines two expressions of the same type, or a Variable that
|
// Map, a List, an Operator that combines two expressions of the same type, or a Variable that
|
||||||
// references and Assignment.
|
// references and Assignment.
|
||||||
|
|
|
@ -190,7 +190,8 @@ func (p *parser) parseAssignment(name string, namePos scanner.Position,
|
||||||
}
|
}
|
||||||
value := p.parseExpression()
|
value := p.parseExpression()
|
||||||
|
|
||||||
assignment.Name = Ident{name, namePos}
|
assignment.Name = name
|
||||||
|
assignment.NamePos = namePos
|
||||||
assignment.Value = value
|
assignment.Value = value
|
||||||
assignment.OrigValue = value
|
assignment.OrigValue = value
|
||||||
assignment.Pos = pos
|
assignment.Pos = pos
|
||||||
|
@ -198,13 +199,12 @@ func (p *parser) parseAssignment(name string, namePos scanner.Position,
|
||||||
|
|
||||||
if p.scope != nil {
|
if p.scope != nil {
|
||||||
if assigner == "+=" {
|
if assigner == "+=" {
|
||||||
if old, local := p.scope.Get(assignment.Name.Name); old == nil {
|
if old, local := p.scope.Get(assignment.Name); old == nil {
|
||||||
p.errorf("modified non-existent variable %q with +=", assignment.Name.Name)
|
p.errorf("modified non-existent variable %q with +=", assignment.Name)
|
||||||
} else if !local {
|
} else if !local {
|
||||||
p.errorf("modified non-local variable %q with +=", assignment.Name.Name)
|
p.errorf("modified non-local variable %q with +=", assignment.Name)
|
||||||
} else if old.Referenced {
|
} else if old.Referenced {
|
||||||
p.errorf("modified variable %q with += after referencing",
|
p.errorf("modified variable %q with += after referencing", assignment.Name)
|
||||||
assignment.Name.Name)
|
|
||||||
} else {
|
} else {
|
||||||
val, err := p.evaluateOperator(old.Value, assignment.Value, '+', assignment.Pos)
|
val, err := p.evaluateOperator(old.Value, assignment.Value, '+', assignment.Pos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -244,7 +244,8 @@ func (p *parser) parseModule(typ string, typPos scanner.Position) *Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Module{
|
return &Module{
|
||||||
Type: Ident{typ, typPos},
|
Type: typ,
|
||||||
|
TypePos: typPos,
|
||||||
Map: Map{
|
Map: Map{
|
||||||
Properties: properties,
|
Properties: properties,
|
||||||
LBracePos: lbracePos,
|
LBracePos: lbracePos,
|
||||||
|
@ -293,7 +294,8 @@ func (p *parser) parseProperty(isModule, compat bool) (property *Property) {
|
||||||
|
|
||||||
value := p.parseExpression()
|
value := p.parseExpression()
|
||||||
|
|
||||||
property.Name = Ident{name, namePos}
|
property.Name = name
|
||||||
|
property.NamePos = namePos
|
||||||
property.Value = value
|
property.Value = value
|
||||||
property.Pos = pos
|
property.Pos = pos
|
||||||
|
|
||||||
|
@ -362,18 +364,18 @@ func (p *parser) addMaps(map1, map2 []*Property, pos scanner.Position) ([]*Prope
|
||||||
inBoth := make(map[string]*Property)
|
inBoth := make(map[string]*Property)
|
||||||
|
|
||||||
for _, prop1 := range map1 {
|
for _, prop1 := range map1 {
|
||||||
inMap1[prop1.Name.Name] = prop1
|
inMap1[prop1.Name] = prop1
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, prop2 := range map2 {
|
for _, prop2 := range map2 {
|
||||||
inMap2[prop2.Name.Name] = prop2
|
inMap2[prop2.Name] = prop2
|
||||||
if _, ok := inMap1[prop2.Name.Name]; ok {
|
if _, ok := inMap1[prop2.Name]; ok {
|
||||||
inBoth[prop2.Name.Name] = prop2
|
inBoth[prop2.Name] = prop2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, prop1 := range map1 {
|
for _, prop1 := range map1 {
|
||||||
if prop2, ok := inBoth[prop1.Name.Name]; ok {
|
if prop2, ok := inBoth[prop1.Name]; ok {
|
||||||
var err error
|
var err error
|
||||||
newProp := *prop1
|
newProp := *prop1
|
||||||
newProp.Value, err = p.evaluateOperator(prop1.Value, prop2.Value, '+', pos)
|
newProp.Value, err = p.evaluateOperator(prop1.Value, prop2.Value, '+', pos)
|
||||||
|
@ -387,7 +389,7 @@ func (p *parser) addMaps(map1, map2 []*Property, pos scanner.Position) ([]*Prope
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, prop2 := range map2 {
|
for _, prop2 := range map2 {
|
||||||
if _, ok := inBoth[prop2.Name.Name]; !ok {
|
if _, ok := inBoth[prop2.Name]; !ok {
|
||||||
ret = append(ret, prop2)
|
ret = append(ret, prop2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -550,15 +552,15 @@ func NewScope(s *Scope) *Scope {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Scope) Add(assignment *Assignment) error {
|
func (s *Scope) Add(assignment *Assignment) error {
|
||||||
if old, ok := s.vars[assignment.Name.Name]; ok {
|
if old, ok := s.vars[assignment.Name]; ok {
|
||||||
return fmt.Errorf("variable already set, previous assignment: %s", old)
|
return fmt.Errorf("variable already set, previous assignment: %s", old)
|
||||||
}
|
}
|
||||||
|
|
||||||
if old, ok := s.inheritedVars[assignment.Name.Name]; ok {
|
if old, ok := s.inheritedVars[assignment.Name]; ok {
|
||||||
return fmt.Errorf("variable already set in inherited scope, previous assignment: %s", old)
|
return fmt.Errorf("variable already set in inherited scope, previous assignment: %s", old)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.vars[assignment.Name.Name] = assignment
|
s.vars[assignment.Name] = assignment
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,8 @@ var validParseTestCases = []struct {
|
||||||
`,
|
`,
|
||||||
[]Definition{
|
[]Definition{
|
||||||
&Module{
|
&Module{
|
||||||
Type: Ident{"foo", mkpos(3, 2, 3)},
|
Type: "foo",
|
||||||
|
TypePos: mkpos(3, 2, 3),
|
||||||
Map: Map{
|
Map: Map{
|
||||||
LBracePos: mkpos(7, 2, 7),
|
LBracePos: mkpos(7, 2, 7),
|
||||||
RBracePos: mkpos(8, 2, 8),
|
RBracePos: mkpos(8, 2, 8),
|
||||||
|
@ -56,13 +57,15 @@ var validParseTestCases = []struct {
|
||||||
`,
|
`,
|
||||||
[]Definition{
|
[]Definition{
|
||||||
&Module{
|
&Module{
|
||||||
Type: Ident{"foo", mkpos(3, 2, 3)},
|
Type: "foo",
|
||||||
|
TypePos: mkpos(3, 2, 3),
|
||||||
Map: Map{
|
Map: Map{
|
||||||
LBracePos: mkpos(7, 2, 7),
|
LBracePos: mkpos(7, 2, 7),
|
||||||
RBracePos: mkpos(27, 4, 3),
|
RBracePos: mkpos(27, 4, 3),
|
||||||
Properties: []*Property{
|
Properties: []*Property{
|
||||||
{
|
{
|
||||||
Name: Ident{"name", mkpos(12, 3, 4)},
|
Name: "name",
|
||||||
|
NamePos: mkpos(12, 3, 4),
|
||||||
Pos: mkpos(16, 3, 8),
|
Pos: mkpos(16, 3, 8),
|
||||||
Value: &String{
|
Value: &String{
|
||||||
LiteralPos: mkpos(18, 3, 10),
|
LiteralPos: mkpos(18, 3, 10),
|
||||||
|
@ -83,13 +86,15 @@ var validParseTestCases = []struct {
|
||||||
`,
|
`,
|
||||||
[]Definition{
|
[]Definition{
|
||||||
&Module{
|
&Module{
|
||||||
Type: Ident{"foo", mkpos(3, 2, 3)},
|
Type: "foo",
|
||||||
|
TypePos: mkpos(3, 2, 3),
|
||||||
Map: Map{
|
Map: Map{
|
||||||
LBracePos: mkpos(7, 2, 7),
|
LBracePos: mkpos(7, 2, 7),
|
||||||
RBracePos: mkpos(28, 4, 3),
|
RBracePos: mkpos(28, 4, 3),
|
||||||
Properties: []*Property{
|
Properties: []*Property{
|
||||||
{
|
{
|
||||||
Name: Ident{"isGood", mkpos(12, 3, 4)},
|
Name: "isGood",
|
||||||
|
NamePos: mkpos(12, 3, 4),
|
||||||
Pos: mkpos(18, 3, 10),
|
Pos: mkpos(18, 3, 10),
|
||||||
Value: &Bool{
|
Value: &Bool{
|
||||||
LiteralPos: mkpos(20, 3, 12),
|
LiteralPos: mkpos(20, 3, 12),
|
||||||
|
@ -111,13 +116,15 @@ var validParseTestCases = []struct {
|
||||||
`,
|
`,
|
||||||
[]Definition{
|
[]Definition{
|
||||||
&Module{
|
&Module{
|
||||||
Type: Ident{"foo", mkpos(3, 2, 3)},
|
Type: "foo",
|
||||||
|
TypePos: mkpos(3, 2, 3),
|
||||||
Map: Map{
|
Map: Map{
|
||||||
LBracePos: mkpos(7, 2, 7),
|
LBracePos: mkpos(7, 2, 7),
|
||||||
RBracePos: mkpos(67, 5, 3),
|
RBracePos: mkpos(67, 5, 3),
|
||||||
Properties: []*Property{
|
Properties: []*Property{
|
||||||
{
|
{
|
||||||
Name: Ident{"stuff", mkpos(12, 3, 4)},
|
Name: "stuff",
|
||||||
|
NamePos: mkpos(12, 3, 4),
|
||||||
Pos: mkpos(17, 3, 9),
|
Pos: mkpos(17, 3, 9),
|
||||||
Value: &List{
|
Value: &List{
|
||||||
LBracePos: mkpos(19, 3, 11),
|
LBracePos: mkpos(19, 3, 11),
|
||||||
|
@ -163,20 +170,23 @@ var validParseTestCases = []struct {
|
||||||
`,
|
`,
|
||||||
[]Definition{
|
[]Definition{
|
||||||
&Module{
|
&Module{
|
||||||
Type: Ident{"foo", mkpos(3, 2, 3)},
|
Type: "foo",
|
||||||
|
TypePos: mkpos(3, 2, 3),
|
||||||
Map: Map{
|
Map: Map{
|
||||||
LBracePos: mkpos(7, 2, 7),
|
LBracePos: mkpos(7, 2, 7),
|
||||||
RBracePos: mkpos(62, 7, 3),
|
RBracePos: mkpos(62, 7, 3),
|
||||||
Properties: []*Property{
|
Properties: []*Property{
|
||||||
{
|
{
|
||||||
Name: Ident{"stuff", mkpos(12, 3, 4)},
|
Name: "stuff",
|
||||||
|
NamePos: mkpos(12, 3, 4),
|
||||||
Pos: mkpos(17, 3, 9),
|
Pos: mkpos(17, 3, 9),
|
||||||
Value: &Map{
|
Value: &Map{
|
||||||
LBracePos: mkpos(19, 3, 11),
|
LBracePos: mkpos(19, 3, 11),
|
||||||
RBracePos: mkpos(58, 6, 4),
|
RBracePos: mkpos(58, 6, 4),
|
||||||
Properties: []*Property{
|
Properties: []*Property{
|
||||||
{
|
{
|
||||||
Name: Ident{"isGood", mkpos(25, 4, 5)},
|
Name: "isGood",
|
||||||
|
NamePos: mkpos(25, 4, 5),
|
||||||
Pos: mkpos(31, 4, 11),
|
Pos: mkpos(31, 4, 11),
|
||||||
Value: &Bool{
|
Value: &Bool{
|
||||||
LiteralPos: mkpos(33, 4, 13),
|
LiteralPos: mkpos(33, 4, 13),
|
||||||
|
@ -184,7 +194,8 @@ var validParseTestCases = []struct {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: Ident{"name", mkpos(43, 5, 5)},
|
Name: "name",
|
||||||
|
NamePos: mkpos(43, 5, 5),
|
||||||
Pos: mkpos(47, 5, 9),
|
Pos: mkpos(47, 5, 9),
|
||||||
Value: &String{
|
Value: &String{
|
||||||
LiteralPos: mkpos(49, 5, 11),
|
LiteralPos: mkpos(49, 5, 11),
|
||||||
|
@ -210,13 +221,15 @@ var validParseTestCases = []struct {
|
||||||
`,
|
`,
|
||||||
[]Definition{
|
[]Definition{
|
||||||
&Module{
|
&Module{
|
||||||
Type: Ident{"foo", mkpos(17, 3, 3)},
|
Type: "foo",
|
||||||
|
TypePos: mkpos(17, 3, 3),
|
||||||
Map: Map{
|
Map: Map{
|
||||||
LBracePos: mkpos(32, 3, 18),
|
LBracePos: mkpos(32, 3, 18),
|
||||||
RBracePos: mkpos(81, 6, 3),
|
RBracePos: mkpos(81, 6, 3),
|
||||||
Properties: []*Property{
|
Properties: []*Property{
|
||||||
{
|
{
|
||||||
Name: Ident{"isGood", mkpos(52, 5, 4)},
|
Name: "isGood",
|
||||||
|
NamePos: mkpos(52, 5, 4),
|
||||||
Pos: mkpos(58, 5, 10),
|
Pos: mkpos(58, 5, 10),
|
||||||
Value: &Bool{
|
Value: &Bool{
|
||||||
LiteralPos: mkpos(60, 5, 12),
|
LiteralPos: mkpos(60, 5, 12),
|
||||||
|
@ -258,13 +271,15 @@ var validParseTestCases = []struct {
|
||||||
`,
|
`,
|
||||||
[]Definition{
|
[]Definition{
|
||||||
&Module{
|
&Module{
|
||||||
Type: Ident{"foo", mkpos(3, 2, 3)},
|
Type: "foo",
|
||||||
|
TypePos: mkpos(3, 2, 3),
|
||||||
Map: Map{
|
Map: Map{
|
||||||
LBracePos: mkpos(7, 2, 7),
|
LBracePos: mkpos(7, 2, 7),
|
||||||
RBracePos: mkpos(27, 4, 3),
|
RBracePos: mkpos(27, 4, 3),
|
||||||
Properties: []*Property{
|
Properties: []*Property{
|
||||||
{
|
{
|
||||||
Name: Ident{"name", mkpos(12, 3, 4)},
|
Name: "name",
|
||||||
|
NamePos: mkpos(12, 3, 4),
|
||||||
Pos: mkpos(16, 3, 8),
|
Pos: mkpos(16, 3, 8),
|
||||||
Value: &String{
|
Value: &String{
|
||||||
LiteralPos: mkpos(18, 3, 10),
|
LiteralPos: mkpos(18, 3, 10),
|
||||||
|
@ -275,13 +290,15 @@ var validParseTestCases = []struct {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
&Module{
|
&Module{
|
||||||
Type: Ident{"bar", mkpos(32, 6, 3)},
|
Type: "bar",
|
||||||
|
TypePos: mkpos(32, 6, 3),
|
||||||
Map: Map{
|
Map: Map{
|
||||||
LBracePos: mkpos(36, 6, 7),
|
LBracePos: mkpos(36, 6, 7),
|
||||||
RBracePos: mkpos(56, 8, 3),
|
RBracePos: mkpos(56, 8, 3),
|
||||||
Properties: []*Property{
|
Properties: []*Property{
|
||||||
{
|
{
|
||||||
Name: Ident{"name", mkpos(41, 7, 4)},
|
Name: "name",
|
||||||
|
NamePos: mkpos(41, 7, 4),
|
||||||
Pos: mkpos(45, 7, 8),
|
Pos: mkpos(45, 7, 8),
|
||||||
Value: &String{
|
Value: &String{
|
||||||
LiteralPos: mkpos(47, 7, 10),
|
LiteralPos: mkpos(47, 7, 10),
|
||||||
|
@ -303,7 +320,8 @@ var validParseTestCases = []struct {
|
||||||
`,
|
`,
|
||||||
[]Definition{
|
[]Definition{
|
||||||
&Assignment{
|
&Assignment{
|
||||||
Name: Ident{"foo", mkpos(3, 2, 3)},
|
Name: "foo",
|
||||||
|
NamePos: mkpos(3, 2, 3),
|
||||||
Pos: mkpos(7, 2, 7),
|
Pos: mkpos(7, 2, 7),
|
||||||
Value: &String{
|
Value: &String{
|
||||||
LiteralPos: mkpos(9, 2, 9),
|
LiteralPos: mkpos(9, 2, 9),
|
||||||
|
@ -317,7 +335,8 @@ var validParseTestCases = []struct {
|
||||||
Referenced: true,
|
Referenced: true,
|
||||||
},
|
},
|
||||||
&Assignment{
|
&Assignment{
|
||||||
Name: Ident{"bar", mkpos(19, 3, 3)},
|
Name: "bar",
|
||||||
|
NamePos: mkpos(19, 3, 3),
|
||||||
Pos: mkpos(23, 3, 7),
|
Pos: mkpos(23, 3, 7),
|
||||||
Value: &Variable{
|
Value: &Variable{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
@ -339,7 +358,8 @@ var validParseTestCases = []struct {
|
||||||
Referenced: true,
|
Referenced: true,
|
||||||
},
|
},
|
||||||
&Assignment{
|
&Assignment{
|
||||||
Name: Ident{"baz", mkpos(31, 4, 3)},
|
Name: "baz",
|
||||||
|
NamePos: mkpos(31, 4, 3),
|
||||||
Pos: mkpos(35, 4, 7),
|
Pos: mkpos(35, 4, 7),
|
||||||
Value: &Operator{
|
Value: &Operator{
|
||||||
OperatorPos: mkpos(41, 4, 13),
|
OperatorPos: mkpos(41, 4, 13),
|
||||||
|
@ -405,7 +425,8 @@ var validParseTestCases = []struct {
|
||||||
Referenced: true,
|
Referenced: true,
|
||||||
},
|
},
|
||||||
&Assignment{
|
&Assignment{
|
||||||
Name: Ident{"boo", mkpos(49, 5, 3)},
|
Name: "boo",
|
||||||
|
NamePos: mkpos(49, 5, 3),
|
||||||
Pos: mkpos(53, 5, 7),
|
Pos: mkpos(53, 5, 7),
|
||||||
Value: &Operator{
|
Value: &Operator{
|
||||||
Args: [2]Expression{
|
Args: [2]Expression{
|
||||||
|
@ -496,7 +517,8 @@ var validParseTestCases = []struct {
|
||||||
Assigner: "=",
|
Assigner: "=",
|
||||||
},
|
},
|
||||||
&Assignment{
|
&Assignment{
|
||||||
Name: Ident{"boo", mkpos(61, 6, 3)},
|
Name: "boo",
|
||||||
|
NamePos: mkpos(61, 6, 3),
|
||||||
Pos: mkpos(66, 6, 8),
|
Pos: mkpos(66, 6, 8),
|
||||||
Value: &Variable{
|
Value: &Variable{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
|
|
@ -87,7 +87,7 @@ func (p *printer) printDef(def Definition) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *printer) printAssignment(assignment *Assignment) {
|
func (p *printer) printAssignment(assignment *Assignment) {
|
||||||
p.printToken(assignment.Name.Name, assignment.Name.Pos)
|
p.printToken(assignment.Name, assignment.NamePos)
|
||||||
p.requestSpace()
|
p.requestSpace()
|
||||||
p.printToken(assignment.Assigner, assignment.Pos)
|
p.printToken(assignment.Assigner, assignment.Pos)
|
||||||
p.requestSpace()
|
p.requestSpace()
|
||||||
|
@ -96,7 +96,7 @@ func (p *printer) printAssignment(assignment *Assignment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *printer) printModule(module *Module) {
|
func (p *printer) printModule(module *Module) {
|
||||||
p.printToken(module.Type.Name, module.Type.Pos)
|
p.printToken(module.Type, module.TypePos)
|
||||||
p.printMap(&module.Map)
|
p.printMap(&module.Map)
|
||||||
p.requestDoubleNewline()
|
p.requestDoubleNewline()
|
||||||
}
|
}
|
||||||
|
@ -175,7 +175,7 @@ func (p *printer) printOperator(operator *Operator) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *printer) printProperty(property *Property) {
|
func (p *printer) printProperty(property *Property) {
|
||||||
p.printToken(property.Name.Name, property.Name.Pos)
|
p.printToken(property.Name, property.NamePos)
|
||||||
p.printToken(":", property.Pos)
|
p.printToken(":", property.Pos)
|
||||||
p.requestSpace()
|
p.requestSpace()
|
||||||
p.printExpression(property.Value)
|
p.printExpression(property.Value)
|
||||||
|
|
|
@ -82,7 +82,7 @@ func buildPropertyMap(namePrefix string, propertyDefs []*parser.Property,
|
||||||
propertyMap map[string]*packedProperty) (errs []error) {
|
propertyMap map[string]*packedProperty) (errs []error) {
|
||||||
|
|
||||||
for _, propertyDef := range propertyDefs {
|
for _, propertyDef := range propertyDefs {
|
||||||
name := namePrefix + propertyDef.Name.Name
|
name := namePrefix + propertyDef.Name
|
||||||
if first, present := propertyMap[name]; present {
|
if first, present := propertyMap[name]; present {
|
||||||
if first.property == propertyDef {
|
if first.property == propertyDef {
|
||||||
// We've already added this property.
|
// We've already added this property.
|
||||||
|
|
Loading…
Reference in a new issue