<commit_before>import Syft

func sequenceDiagram() -> Pipeline<String> {
    return Pipeline(defaultInput: "participant App", parser: makeSequenceDiagramParser(), transformer: makeSequenceDiagramTransformer()) { ast in
        return "\(ast)"
    }
}

func makeSequenceDiagramParser() -> ParserProtocol {
    let space = " ".match
    let spaces = space.some
    let skip = spaces.maybe
    let character = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_".match
    let token = character.some.tag("token")
    let quotableToken = (character | space).some.tag("token")
    let quote = "\"".match
    let quotedToken = quote >>> quotableToken >>> quote
    let shorthand = spaces >>> str("as") >>> spaces >>> (quotedToken | token).tag("shorthand") >>> skip
    let participantToken = (quotedToken | token).tag("participant")
    let participant = skip >>> str("participant") >>> spaces >>> participantToken >>> (shorthand | spaces).maybe
    
    let parser = participant
    return parser
}

func makeSequenceDiagramTransformer() -> Transformer<String> {
    let transformer = Transformer<String>()
    
    transformer.rule(["token": .simple("t")]) { args in
        try args.raw("t")
    }
    
    transformer.rule(["participant": .simple("p")]) { args in
        "Hello \(try args.transformed("p"))"
    }
    
    return transformer
}<commit_msg>Parse events in the sequence diagram<commit_after>import Syft

func sequenceDiagram() -> Pipeline<String> {
    return Pipeline(defaultInput: "participant App", parser: makeSequenceDiagramParser(), transformer: makeSequenceDiagramTransformer()) { ast in
        return "\(ast)"
    }
}

func makeSequenceDiagramParser() -> ParserProtocol {
    
    let space = " ".match
    let spaces = space.some
    let skip = spaces.maybe
    let character = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_".match
    let newline = str("\n")

    let token = character.some.tag("token")
    let quotableToken = (character | space).some.tag("token")
    let quote = "\"".match
    let quotedToken = quote >>> quotableToken >>> quote
    let shorthand = spaces >>> str("as") >>> spaces >>> (quotedToken | token).tag("shorthand") >>> skip
    let participantToken = (quotedToken | token).tag("participant")
    let participant = skip >>> str("participant") >>> spaces >>> participantToken >>> (shorthand | spaces).maybe
    
    let source = token.tag("source")
    let destination = token.tag("destination")
    let weakArrow = str("-->")
    let strongArrow = str("->")
    let comment = quotableToken.tag("comment")
    let colon = str(":") >>> skip
    let destinationAndComment = destination >>> colon >>> comment
    let strongEvent = (source >>> strongArrow >>> destinationAndComment).tag("strong")
    let weakEvent = (source >>> weakArrow >>> destinationAndComment).tag("weak")
    let event = strongEvent | weakEvent
    
    let lines = ((event | participant) >>> newline).some.maybe
    
    let parser = lines
    return parser
}

func makeSequenceDiagramTransformer() -> Transformer<String> {
    let transformer = Transformer<String>()
    
    transformer.rule(["token": .simple("t")]) { args in
        try args.raw("t")
    }
    
    transformer.rule(["participant": .simple("p")]) { args in
        "Hello \(try args.transformed("p"))"
    }
    
    return transformer
}
{'fraction_non_alphanumeric': 0.14345238095238094, 'fraction_numerical': 0.005952380952380952, 'mean_word_length': 3.6104252400548695, 'pattern_counts': {'":': 5, '<': 9, '<?xml version=': 0, '>': 101, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4412098', 'n_tokens_mistral': 994, 'n_tokens_neox': 957, 'n_words': 237}