Parser

Trait Parser 

Source
pub trait Parser<U: Ui>: Send + 'static {
    // Provided methods
    fn parse(
        &mut self,
        pa: &mut Pass,
        snap: FileSnapshot<'_>,
        ranges: Option<&mut Ranges>,
    ) { ... }
    fn update_range(
        &mut self,
        parts: FileParts<'_, U>,
        within: Option<Range<Point>>,
    ) { ... }
    fn parse_remote(
        &mut self,
        snap: FileSnapshot<'_>,
        ranges: Option<&mut Ranges>,
    ) { ... }
    fn make_remote(&self) -> bool { ... }
}
Expand description

A Text reader, modifying it whenever Moments happen

Provided Methods§

Source

fn parse( &mut self, pa: &mut Pass, snap: FileSnapshot<'_>, ranges: Option<&mut Ranges>, )

Parses the File after a Moment takes place

After this point, even if no other functions are called, the state of this Parser should reflect the state of the FileSnapshot that were passed.

The FileSnapshot has three item in it: The Bytes after the Moment was applied, the Moment itself, and the PrintCfg of the File at that point in time.

The ranges argument, if given, represents the Ranges in the Text that Parser::update_range should care about updating. You can add and remove Range<usize>s from it, and later, when these byte ranges are printed to the screen, Duat will request that this reader update that them via Parser::update_range, allowing for efficient updating only when it would matter. If the argument is None, you don’t need to care about that.

§Notes

This is not where Tags will be added or removed, as you can see by the lack of an appropriate argument for that (that argument would be Tags). That is instead done in Parser::update_range.

And while you could still do that because of the Pass, this is not recommended, since update_range gives you the exact span that you need to care about in order to update efficiently.

§Note

You can access the File as it is right now via the Pass argument, but there is no guarantee of synchronicity between the Bytes of the File and the Bytes in the FileSnapshot.

Source

fn update_range( &mut self, parts: FileParts<'_, U>, within: Option<Range<Point>>, )

Updates in a given Range

This function, unlike parse and parse_remote does not give you a snapshot of the File. Since it is supposed to add and remove Tags, it gives you direct access to the File’s parts, like a Pass would.

The within

§NOTES

One other thing to note is that the within range is just a suggestion. In most circumstances, it would be a little convenient to go slightly over that range. For example, a regex searcher should look only at the range provided, but if a match goes slightly beyond the range, it is fine to add Tags in there.

Finally, keep in mind that Tags are not allowed to be repeated, and you can use this to your advantage, as in, instead of checking if you need to place a Tag in a certain spot, you can just place it, and Duat will ignore that request if that Tag was already there.

Source

fn parse_remote(&mut self, snap: FileSnapshot<'_>, ranges: Option<&mut Ranges>)

Same as parse, but on another thread

The biggest difference between this function and parse is that, since this one doesn’t take place on the main thread, you lose access to Duat’s shared state afforded by the Pass, the only things you will have access to are the Bytes, PrintCfg and the latest Moment of the File that was updated, all within the FileSnapshot.

Source

fn make_remote(&self) -> bool

Wether this Parser should be sent to update its internal state in another thread

This should pretty much never be used, unless in very specific circumstances, such as with very large files, or with broken syntax trees, whose update time has become slow

Implementors§