#1 Compile class inheriting from `Rule` into a `Rule` trait implementation

Öppen
öppnade 5 år sedan av unidan · 0 kommentarer
unidan kommenterad 5 år sedan

Example:

class EpisodeSingleDigitValidator(Rule):
    """
    Remove single digit episode when inside a group that doesn't own title.
    """
    dependency = [TitleFromPosition]

    consequence = RemoveMatch

    def when(self, matches, context):
        ret = []
        for episode in matches.named('episode', lambda match: len(match.initiator) == 1):
            group = matches.markers.at_match(episode, lambda marker: marker.name == 'group', index=0)
            if group:
                if not matches.range(*group.span, predicate=lambda match: match.name == 'title'):
                    ret.append(episode)
        return ret

Should implement something like

trait Rule {
    fn dependencies(&self) -> Vec<Dependency>;
    fn consequence(&self) -> Consequence;
    fn when(&self, matches: Matches, context: Context) -> Vec<Marker>;
}
Example: ``` class EpisodeSingleDigitValidator(Rule): """ Remove single digit episode when inside a group that doesn't own title. """ dependency = [TitleFromPosition] consequence = RemoveMatch def when(self, matches, context): ret = [] for episode in matches.named('episode', lambda match: len(match.initiator) == 1): group = matches.markers.at_match(episode, lambda marker: marker.name == 'group', index=0) if group: if not matches.range(*group.span, predicate=lambda match: match.name == 'title'): ret.append(episode) return ret ``` Should implement something like ``` trait Rule { fn dependencies(&self) -> Vec<Dependency>; fn consequence(&self) -> Consequence; fn when(&self, matches: Matches, context: Context) -> Vec<Marker>; } ```
Logga in för att delta i denna konversation.
Ingen Etikett
Ingen Milsten
Ingen förvärvare
1 Deltagare
Laddar...
Avbryt
Spara
Det finns inget innehåll än.