parent
							
								
									10d33452e2
								
							
						
					
					
						commit
						00584bb091
					
				
					 5 changed files with 28 additions and 8 deletions
				
			
		|  | @ -83,6 +83,8 @@ static void addAttr(ExprAttrs * attrs, AttrPath & attrPath, | ||||||
|     AttrPath::iterator i; |     AttrPath::iterator i; | ||||||
|     // All attrpaths have at least one attr |     // All attrpaths have at least one attr | ||||||
|     assert(!attrPath.empty()); |     assert(!attrPath.empty()); | ||||||
|  |     // Checking attrPath validity. | ||||||
|  |     // =========================== | ||||||
|     for (i = attrPath.begin(); i + 1 < attrPath.end(); i++) {  |     for (i = attrPath.begin(); i + 1 < attrPath.end(); i++) {  | ||||||
|         if (i->symbol.set()) { |         if (i->symbol.set()) { | ||||||
|             ExprAttrs::AttrDefs::iterator j = attrs->attrs.find(i->symbol); |             ExprAttrs::AttrDefs::iterator j = attrs->attrs.find(i->symbol); | ||||||
|  | @ -104,11 +106,29 @@ static void addAttr(ExprAttrs * attrs, AttrPath & attrPath, | ||||||
|             attrs = nested; |             attrs = nested; | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |     // Expr insertion. | ||||||
|  |     // ========================== | ||||||
|     if (i->symbol.set()) {  |     if (i->symbol.set()) {  | ||||||
|         ExprAttrs::AttrDefs::iterator j = attrs->attrs.find(i->symbol); |         ExprAttrs::AttrDefs::iterator j = attrs->attrs.find(i->symbol); | ||||||
|         if (j != attrs->attrs.end()) { |         if (j != attrs->attrs.end()) { | ||||||
|             dupAttr(attrPath, pos, j->second.pos); |             // This attr path is already defined. However, if both | ||||||
|  |             // e and the expr pointed by the attr path are two attribute sets, | ||||||
|  |             // we want to merge them. | ||||||
|  |             // Otherwise, throw an error. | ||||||
|  |             ExprAttrs* ae = dynamic_cast<ExprAttrs *>(e); | ||||||
|  |             ExprAttrs* jAttrs = dynamic_cast<ExprAttrs *>(j->second.e); | ||||||
|  |             if (jAttrs && ae) { | ||||||
|  |                 for (auto ad: ae->attrs) { | ||||||
|  |                     ExprAttrs::AttrDefs::iterator j2 = jAttrs->attrs.find(ad.first); | ||||||
|  |                     if (j2 != jAttrs->attrs.end()) // Attr already defined in iAttrs, error. | ||||||
|  |                         dupAttr(ad.first, j2->second.pos, ad.second.pos); | ||||||
|  |                     jAttrs->attrs[ad.first] = ad.second; | ||||||
|  |                 } | ||||||
|             } else { |             } else { | ||||||
|  |                 dupAttr(attrPath, pos, j->second.pos); | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             // This attr path is not defined. Let's create it. | ||||||
|             attrs->attrs[i->symbol] = ExprAttrs::AttrDef(e, pos); |             attrs->attrs[i->symbol] = ExprAttrs::AttrDef(e, pos); | ||||||
|             e->setName(i->symbol); |             e->setName(i->symbol); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|  | @ -1,4 +1,4 @@ | ||||||
| {  | {  | ||||||
|   x = { y = 3; z = 3; };  |  | ||||||
|   x.z = 3;  |   x.z = 3;  | ||||||
|  |   x = { y = 3; z = 3; };  | ||||||
| } | } | ||||||
							
								
								
									
										4
									
								
								tests/lang/parse-fail-mixed-nested-attrs2.nix
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								tests/lang/parse-fail-mixed-nested-attrs2.nix
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,4 @@ | ||||||
|  | {  | ||||||
|  |   x.y.y = 3;  | ||||||
|  |   x = { y.y= 3; z = 3; };  | ||||||
|  | } | ||||||
|  | @ -1,4 +0,0 @@ | ||||||
| {  |  | ||||||
|   x = { y = 3; z = 3; };  |  | ||||||
|   x.q = 3;  |  | ||||||
| } |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue