11use std:: collections:: HashMap ;
22use std:: num:: NonZeroU16 ;
33
4- use tree_sitter:: { InputEdit , Language , Node , Parser , Point , Range , Tree , TreeCursor } ;
4+ use tree_sitter:: {
5+ InputEdit , Language , Node , ParseOptions , Parser , Point , Range , Tree , TreeCursor ,
6+ } ;
57
68use crate :: { INLINE_LANGUAGE , LANGUAGE } ;
79
@@ -244,6 +246,16 @@ impl Default for MarkdownParser {
244246}
245247
246248impl MarkdownParser {
249+ /// Parse a slice of UTF8 text.
250+ #[ deprecated( since = "0.5.0" , note = "Prefer `parse_with_options` instead" ) ]
251+ pub fn parse_with < T : AsRef < [ u8 ] > , F : FnMut ( usize , Point ) -> T > (
252+ & mut self ,
253+ callback : & mut F ,
254+ old_tree : Option < & MarkdownTree > ,
255+ ) -> Option < MarkdownTree > {
256+ self . parse_with_options ( callback, old_tree, None , None )
257+ }
258+
247259 /// Parse a slice of UTF8 text.
248260 ///
249261 /// # Arguments:
@@ -252,14 +264,18 @@ impl MarkdownParser {
252264 /// If the text of the document has changed since `old_tree` was
253265 /// created, then you must edit `old_tree` to match the new text using
254266 /// [MarkdownTree::edit].
267+ /// * `block_options` The [options][ParseOptions] for the block parsing.
268+ /// * `inline_options` The [options][ParseOptions] for the inline parsing.
255269 ///
256270 /// Returns a [MarkdownTree] if parsing succeeded, or `None` if:
257271 /// * The timeout set with [tree_sitter::Parser::set_timeout_micros] expired
258272 /// * The cancellation flag set with [tree_sitter::Parser::set_cancellation_flag] was flipped
259- pub fn parse_with < T : AsRef < [ u8 ] > , F : FnMut ( usize , Point ) -> T > (
273+ pub fn parse_with_options < T : AsRef < [ u8 ] > , F : FnMut ( usize , Point ) -> T > (
260274 & mut self ,
261275 callback : & mut F ,
262276 old_tree : Option < & MarkdownTree > ,
277+ block_options : Option < ParseOptions < ' _ > > ,
278+ inline_options : Option < ParseOptions < ' _ > > ,
263279 ) -> Option < MarkdownTree > {
264280 let MarkdownParser {
265281 parser,
@@ -272,7 +288,11 @@ impl MarkdownParser {
272288 parser
273289 . set_language ( block_language)
274290 . expect ( "Could not load block grammar" ) ;
275- let block_tree = parser. parse_with ( callback, old_tree. map ( |tree| & tree. block_tree ) ) ?;
291+ let block_tree = parser. parse_with_options (
292+ callback,
293+ old_tree. map ( |tree| & tree. block_tree ) ,
294+ block_options,
295+ ) ?;
276296 let ( mut inline_trees, mut inline_indices) = if let Some ( old_tree) = old_tree {
277297 let len = old_tree. inline_trees . len ( ) ;
278298 ( Vec :: with_capacity ( len) , HashMap :: with_capacity ( len) )
@@ -322,9 +342,10 @@ impl MarkdownParser {
322342 }
323343 ranges. push ( range) ;
324344 parser. set_included_ranges ( & ranges) . ok ( ) ?;
325- let inline_tree = parser. parse_with (
345+ let inline_tree = parser. parse_with_options (
326346 callback,
327347 old_tree. and_then ( |old_tree| old_tree. inline_trees . get ( i) ) ,
348+ inline_options,
328349 ) ?;
329350 inline_trees. push ( inline_tree) ;
330351 inline_indices. insert ( node. id ( ) , i) ;
@@ -353,7 +374,7 @@ impl MarkdownParser {
353374 /// * The timeout set with [tree_sitter::Parser::set_timeout_micros] expired
354375 /// * The cancellation flag set with [tree_sitter::Parser::set_cancellation_flag] was flipped
355376 pub fn parse ( & mut self , text : & [ u8 ] , old_tree : Option < & MarkdownTree > ) -> Option < MarkdownTree > {
356- self . parse_with ( & mut |byte, _| & text[ byte..] , old_tree)
377+ self . parse_with_options ( & mut |byte, _| & text[ byte..] , old_tree, None )
357378 }
358379}
359380
0 commit comments