@@ -98,22 +98,17 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
9898 return failed ( & crate_name) ;
9999 }
100100 } ;
101- let mut bad = false ;
102101 for esc in [ "\\ n" , "\\ \" " , "\\ '" ] {
103102 for _ in resource_contents. matches ( esc) {
104- bad = true ;
105103 Diagnostic :: spanned ( resource_span, Level :: Error , format ! ( "invalid escape `{esc}` in Fluent resource" ) )
106104 . note ( "Fluent does not interpret these escape sequences (<https://projectfluent.org/fluent/guide/special.html>)" )
107105 . emit ( ) ;
108106 }
109107 }
110- if bad {
111- return failed ( & crate_name) ;
112- }
113108
114109 let resource = match FluentResource :: try_new ( resource_contents) {
115110 Ok ( resource) => resource,
116- Err ( ( this , errs) ) => {
111+ Err ( ( resource , errs) ) => {
117112 Diagnostic :: spanned ( resource_span, Level :: Error , "could not parse Fluent resource" )
118113 . help ( "see additional errors emitted" )
119114 . emit ( ) ;
@@ -124,7 +119,7 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
124119 err. replace_range ( 0 ..1 , & err. chars ( ) . next ( ) . unwrap ( ) . to_lowercase ( ) . to_string ( ) ) ;
125120
126121 let message = annotate_snippets:: Level :: Error . title ( & err) . snippet (
127- Snippet :: source ( this . source ( ) )
122+ Snippet :: source ( resource . source ( ) )
128123 // Using an absolute path is fine here as compilation will not continue.
129124 . origin ( absolute_ftl_path. to_str ( ) . unwrap ( ) )
130125 . fold ( true )
@@ -134,7 +129,8 @@ pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::Tok
134129 eprintln ! ( "{}\n " , renderer. render( message) ) ;
135130 }
136131
137- return failed ( & crate_name) ;
132+ // Try to recover from the parse error to avoid cascading errors.
133+ resource
138134 }
139135 } ;
140136
0 commit comments