@@ -234,15 +234,19 @@ pub const Error = struct {
234234 tag : union (enum ) {
235235 token : Tokenizer.TokenError ,
236236 invalid_attr ,
237- invalid_attr_nesting : Kind ,
237+ invalid_attr_nesting : struct {
238+ kind : Kind ,
239+ reason : []const u8 = "" ,
240+ },
238241 invalid_attr_value : struct {
239242 reason : []const u8 = "" ,
240243 },
241244 invalid_attr_combination : []const u8 , // reason
242245 missing_required_attr : []const u8 ,
243246 missing_attr_value ,
244247 boolean_attr ,
245- wrong_position : enum { first , second },
248+ wrong_position : enum { first , second , first_or_last },
249+ missing_ancestor : Kind ,
246250 missing_child : Kind ,
247251 duplicate_child : struct {
248252 span : Span , // original child
@@ -278,9 +282,9 @@ pub const Error = struct {
278282 "invalid attribute for this element" ,
279283 .{},
280284 ),
281- .invalid_attr_nesting = > | kind | w .print (
282- "invalid attribute for this element when nested under '{t}'" ,
283- .{kind },
285+ .invalid_attr_nesting = > | nest | w .print (
286+ "invalid attribute for this element when nested under '{t}' {s} " ,
287+ .{ nest . kind , nest . reason },
284288 ),
285289 .invalid_attr_value = > | iav | {
286290 try w .print ("invalid value for this attribute" , .{});
@@ -293,7 +297,7 @@ pub const Error = struct {
293297 .{iac },
294298 ),
295299 .missing_required_attr = > | attr | w .print (
296- "missing required attribute: {s}" ,
300+ "missing required attribute(s) : {s}" ,
297301 .{attr },
298302 ),
299303 .missing_attr_value = > w .print (
@@ -305,9 +309,13 @@ pub const Error = struct {
305309 .{},
306310 ),
307311 .wrong_position = > | p | w .print (
308- "element in wrong position, should be {t}" ,
309- .{p },
312+ "element in wrong position, should be {s}" ,
313+ .{switch (p ) {
314+ .first , .second = > @tagName (p ),
315+ .first_or_last = > "first or last" ,
316+ }},
310317 ),
318+ .missing_ancestor = > | e | w .print ("missing ancestor: {t}" , .{e }),
311319 .missing_child = > | e | w .print ("missing child: {t}" , .{e }),
312320 .duplicate_child = > | dc | {
313321 try w .print ("duplicate child" , .{});
@@ -316,7 +324,7 @@ pub const Error = struct {
316324 }
317325 },
318326 .invalid_nesting = > | in | {
319- try w .print ("invalid nesting under {s}" , .{
327+ try w .print ("invalid nesting under < {s}> " , .{
320328 in .span .slice (tf .src ),
321329 });
322330 if (in .reason .len > 0 ) {
@@ -490,21 +498,22 @@ pub fn init(
490498 },
491499 .html = > {
492500 if (kinds .get (name )) | kind | {
493- const parent_node = switch (current .direction ()) {
494- .in = > nodes . items [ current_idx ] ,
495- .after = > nodes .items [nodes . items [ current_idx ].parent_idx ] ,
501+ const parent_idx = switch (current .direction ()) {
502+ .in = > current_idx ,
503+ .after = > nodes .items [current_idx ].parent_idx ,
496504 };
505+
497506 const e = elements .get (kind );
498507 const model = try e .validateAttrs (
499508 gpa ,
500509 language ,
501510 & errors ,
502511 & seen_attrs ,
512+ nodes .items ,
513+ parent_idx ,
503514 src ,
504- parent_node .kind ,
505- parent_node .model .content ,
506515 tag .span ,
507- current_idx ,
516+ @intCast ( nodes . items . len ) ,
508517 );
509518
510519 break :node .{
@@ -516,7 +525,7 @@ pub fn init(
516525 try errors .append (gpa , .{
517526 .tag = .invalid_html_tag_name ,
518527 .main_location = tag .name ,
519- .node_idx = current_idx + 1 ,
528+ .node_idx = @intCast ( nodes . items . len ) ,
520529 });
521530 }
522531
@@ -1203,7 +1212,7 @@ pub fn validateNesting(
12031212 if (nodes .len < 2 or language == .xml ) return ;
12041213
12051214 var node_idx : u32 = 1 ;
1206- while (node_idx != 0 and node_idx < nodes .len - 1 ) {
1215+ while (node_idx != 0 and node_idx < nodes .len ) {
12071216 const n = nodes [node_idx ];
12081217 if (n .kind == .svg or n .kind == .math or n .kind == .___ ) {
12091218 node_idx = n .next_idx ;
@@ -1212,8 +1221,8 @@ pub fn validateNesting(
12121221 defer node_idx += 1 ;
12131222
12141223 if (! n .kind .isElement () or n .kind .isVoid ()) continue ;
1215-
12161224 const element : Element = elements .get (n .kind );
1225+
12171226 try element .validateContent (
12181227 gpa ,
12191228 nodes ,
0 commit comments