@@ -37,6 +37,7 @@ use wasm_bindgen_backend::TryToTokens;
37
37
use weedle:: attribute:: ExtendedAttributeList ;
38
38
use weedle:: dictionary:: DictionaryMember ;
39
39
use weedle:: interface:: InterfaceMember ;
40
+ use weedle:: Parse ;
40
41
41
42
struct Program {
42
43
main : ast:: Program ,
@@ -74,26 +75,19 @@ impl Default for ApiStability {
74
75
}
75
76
76
77
fn parse_source ( source : & str ) -> Result < Vec < weedle:: Definition > > {
77
- weedle:: parse ( source) . map_err ( |e| {
78
- match & e {
79
- weedle:: Err :: Incomplete ( needed) => anyhow:: anyhow!( "needed {:?} more bytes" , needed) ,
80
- weedle:: Err :: Error ( cx) | weedle:: Err :: Failure ( cx) => {
81
- // Note that #[allow] here is a workaround for Geal/nom#843
82
- // because the `Context` type here comes from `nom` and if
83
- // something else in our crate graph enables the
84
- // `verbose-errors` feature then we need to still compiled
85
- // against the changed enum definition.
86
- #[ allow( unreachable_patterns) ]
87
- let remaining = match cx {
88
- weedle:: Context :: Code ( remaining, _) => remaining. len ( ) ,
89
- _ => 0 ,
90
- } ;
91
- let pos = source. len ( ) - remaining;
92
-
93
- WebIDLParseError ( pos) . into ( )
94
- }
78
+ match weedle:: Definitions :: parse ( source) {
79
+ Ok ( ( "" , parsed) ) => Ok ( parsed) ,
80
+
81
+ Ok ( ( remaining, _) )
82
+ | Err ( weedle:: Err :: Error ( ( remaining, _) ) )
83
+ | Err ( weedle:: Err :: Failure ( ( remaining, _) ) ) => {
84
+ Err ( WebIDLParseError ( source. len ( ) - remaining. len ( ) ) . into ( ) )
95
85
}
96
- } )
86
+
87
+ Err ( weedle:: Err :: Incomplete ( needed) ) => {
88
+ Err ( anyhow:: anyhow!( "needed {:?} more bytes" , needed) )
89
+ }
90
+ }
97
91
}
98
92
99
93
/// Parse a string of WebIDL source text into a wasm-bindgen AST.
0 commit comments