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

오픈
unidan5 년 전을 오픈 · 0개의 코멘트
unidan 코멘트됨, 5 년 전

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>; } ```
로그인하여 이 대화에 참여
레이블 없음
마일스톤 없음
담당자 없음
참여자 1명
로딩중...
취소
저장
아직 콘텐츠가 없습니다.