@@ -26,6 +26,7 @@ type parser struct {
2626////////////////////////////////////////////////////////////////////////////////
2727// LIFECYCLE
2828
29+ // Create a new parser with the given plugins
2930func New (plugins ... server.Plugin ) (* parser , error ) {
3031 p := new (parser )
3132 p .meta = make (map [string ]* meta.Meta , len (plugins ))
@@ -51,7 +52,7 @@ func New(plugins ...server.Plugin) (*parser, error) {
5152////////////////////////////////////////////////////////////////////////////////
5253// PUBLIC METHODS
5354
54- // Read a file and parse it
55+ // Read a configuration file and parse it, creating variables and resources
5556func (p * parser ) Parse (path string ) error {
5657 ext := strings .ToLower (filepath .Ext (path ))
5758 switch ext {
@@ -170,16 +171,16 @@ func (p *parser) jsonPluginsParse(meta *meta.Meta, root ast.Node) error {
170171 if ! ok || label == "" {
171172 return httpresponse .ErrBadRequest .Withf ("expected label, got %q" , ident .Value ())
172173 } else {
173- meta = meta .WithLabel (label )
174+ label = meta .Label (label )
174175 }
175176
176- if _ , exists := p .resources [meta . Label () ]; exists {
177- return httpresponse .ErrBadRequest .Withf ("duplicate resource: %q" , meta . Label () )
177+ if _ , exists := p .resources [label ]; exists {
178+ return httpresponse .ErrBadRequest .Withf ("duplicate resource: %q" , label )
178179 } else if len (ident .Children ()) > 0 {
179- if resource , err := jsonResourceParse (meta , ident .Children ()[0 ]); err != nil {
180- return httpresponse .ErrBadRequest .Withf ("failed to parse %q: %s" , meta . Label () , err )
180+ if resource , err := jsonResourceParse (meta , label , ident .Children ()[0 ]); err != nil {
181+ return httpresponse .ErrBadRequest .Withf ("failed to parse %q: %s" , label , err )
181182 } else {
182- p .resources [meta . Label () ] = resource
183+ p .resources [label ] = resource
183184 }
184185 }
185186 }
@@ -223,14 +224,15 @@ func jsonVariableParse(name string, root ast.Node) (*Variable, error) {
223224 return v , nil
224225}
225226
226- func jsonResourceParse (meta * meta.Meta , root ast.Node ) (* Resource , error ) {
227+ func jsonResourceParse (meta * meta.Meta , label string , root ast.Node ) (* Resource , error ) {
227228 if root .Type () != ast .Dict {
228229 return nil , httpresponse .ErrBadRequest .Withf ("expected object, got %s" , root .Type ())
229230 }
230231
231232 // tree should contain key/value pairs and objects which may be nested
232233 r := new (Resource )
233234 r .Meta = meta
235+ r .Label = label
234236
235237 for _ , ident := range root .Children () {
236238 if ident .Type () != ast .Ident {
0 commit comments