@@ -7,13 +7,7 @@ use std::{
7
7
use proc_macro2:: { Delimiter , TokenStream , TokenTree } ;
8
8
use proc_macro2_diagnostics:: { Diagnostic , SpanDiagnosticExt } ;
9
9
use syn:: {
10
- braced, bracketed,
11
- ext:: IdentExt ,
12
- parenthesized,
13
- parse:: { Parse , ParseStream } ,
14
- spanned:: Spanned ,
15
- token:: { Brace , Bracket , Else , For , If , In , Paren , While } ,
16
- Ident , LitStr , Token ,
10
+ braced, bracketed, ext:: IdentExt , parenthesized, parse:: { Parse , ParseStream } , punctuated:: Punctuated , spanned:: Spanned , token:: { Brace , Bracket , Else , For , If , In , Paren , While } , Ident , LitStr , Token
17
11
} ;
18
12
use tracing:: instrument;
19
13
use tracing:: { error, level_filters:: LevelFilter } ;
@@ -197,9 +191,16 @@ pub enum HtmlInAttributeValueContext {
197
191
For ( HtmlForLoop < Vec < HtmlInAttributeValueContext > > ) ,
198
192
}
199
193
194
+
195
+ #[ derive( Debug ) ]
196
+ pub enum DashOrColon {
197
+ Dash ( Token ! [ -] ) ,
198
+ Colon ( Token ! [ : ] ) ,
199
+ }
200
+
200
201
#[ derive( Debug ) ]
201
202
pub enum HtmlInAttributeContext {
202
- Literal ( Ident , Option < ( Token ! [ =] , Vec < HtmlInAttributeValueContext > ) > ) ,
203
+ Literal ( Punctuated < Ident , DashOrColon > , Option < ( Token ! [ =] , Vec < HtmlInAttributeValueContext > ) > ) ,
203
204
Computation ( ( Brace , TokenStream ) ) ,
204
205
If ( HtmlIf < Vec < HtmlInAttributeContext > > ) ,
205
206
While ( HtmlWhile < Vec < HtmlInAttributeContext > > ) ,
@@ -422,6 +423,48 @@ impl MyParse<HtmlInAttributeValueContext> for ParseStream<'_> {
422
423
}
423
424
}
424
425
426
+ impl MyParse < DashOrColon > for ParseStream < ' _ > {
427
+ fn inner_my_parse ( self ) -> Result < ( DashOrColon , Vec < Diagnostic > ) , Vec < Diagnostic > > {
428
+ let lookahead = self . lookahead1 ( ) ;
429
+ let dash_or_colon = if lookahead. peek ( Token ! [ -] ) {
430
+ self . parse ( ) . map ( DashOrColon :: Dash ) . map_err ( |err| Vec :: from ( [ Diagnostic :: from ( err) ] ) ) ?
431
+ } else if lookahead. peek ( Token ! [ : ] ) {
432
+ self . parse ( ) . map ( DashOrColon :: Colon ) . map_err ( |err| Vec :: from ( [ Diagnostic :: from ( err) ] ) ) ?
433
+ } else {
434
+ return Err ( Vec :: from ( [ Diagnostic :: from ( lookahead. error ( ) ) ] ) )
435
+ } ;
436
+ Ok ( ( dash_or_colon, vec ! [ ] ) )
437
+ }
438
+ }
439
+
440
+ impl MyParse < Punctuated < Ident , DashOrColon > > for ParseStream < ' _ > {
441
+ fn inner_my_parse ( self ) -> Result < ( Punctuated < Ident , DashOrColon > , Vec < Diagnostic > ) , Vec < Diagnostic > > {
442
+ let mut diagnostics = Vec :: new ( ) ;
443
+ let mut ident: Punctuated < Ident , DashOrColon > = Punctuated :: new ( ) ;
444
+ ident. push_value ( {
445
+ let value: Ident ;
446
+ ( value, diagnostics) =
447
+ MyParse :: my_parse ( self , identity, identity, diagnostics) ?;
448
+ value
449
+ } ) ;
450
+ while self . peek ( Token ! [ -] ) || self . peek ( Token ! [ : ] ) {
451
+ ident. push_punct ( {
452
+ let value: DashOrColon ;
453
+ ( value, diagnostics) =
454
+ MyParse :: my_parse ( self , identity, identity, diagnostics) ?;
455
+ value
456
+ } ) ;
457
+ ident. push_value ( {
458
+ let value: Ident ;
459
+ ( value, diagnostics) =
460
+ MyParse :: my_parse ( self , identity, identity, diagnostics) ?;
461
+ value
462
+ } ) ;
463
+ }
464
+ Ok ( ( ident, diagnostics) )
465
+ }
466
+ }
467
+
425
468
impl MyParse < HtmlInAttributeContext > for ParseStream < ' _ > {
426
469
#[ instrument( err( Debug ) , ret, name = "Html<Inner>" ) ]
427
470
fn inner_my_parse ( self ) -> Result < ( HtmlInAttributeContext , Vec < Diagnostic > ) , Vec < Diagnostic > > {
@@ -452,6 +495,7 @@ impl MyParse<HtmlInAttributeContext> for ParseStream<'_> {
452
495
diagnostics,
453
496
) ?)
454
497
} else if lookahead. peek ( Ident :: peek_any) {
498
+ // here
455
499
Ok ( (
456
500
HtmlInAttributeContext :: Literal (
457
501
{
0 commit comments