@@ -0,0 +1,2170 @@
+package seedu.address.logic.parser;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * A parser that tries to parse the input string with multiple parsers, and returns the first successful%0A * result.%0A */%0Apublic class OverloadParser%3CT%3E implements Parser%3CT%3E %7B%0A%0A    private final List%3CCandidate%3CT%3E%3E candidates = new ArrayList%3C%3E();%0A%0A    public OverloadParser%3CT%3E addParser(String name, Parser%3C? extends T%3E parser) %7B%0A        candidates.add(new Candidate%3CT%3E(name, parser));%0A        return this;%0A    %7D%0A%0A    @Override%0A    public T parse(String str) throws ParseException %7B%0A        List%3CCandidateException%3E candidateExceptions = new ArrayList%3C%3E();%0A%0A        // Try all parsers, while collecting their exceptions%0A        for (Candidate%3CT%3E candidate : candidates) %7B%0A            try %7B%0A                return candidate.parser.parse(str);%0A            %7D catch (ParseException e) %7B%0A                candidateExceptions.add(new CandidateException(candidate.name, e));%0A            %7D%0A        %7D%0A%0A        throw makeParseException(candidateExceptions);%0A    %7D%0A%0A    private ParseException makeParseException(List%3CCandidateException%3E candidateExceptions) %7B%0A        final ParseExceptionBuilder builder = new ParseExceptionBuilder(%22Tried to parse the input as the following but failed:%22);%0A        for (CandidateException candidateException : candidateExceptions) %7B%0A            builder.appendMessage(%22%5Cn%5Cn%22).appendMessage(candidateException.name).appendMessage(%22:%5Cn    %22)%0A                .appendMessage(candidateException.exception.getMessage());%0A            builder.addRanges(candidateException.exception.getRanges());%0A        %7D%0A        return builder.build();%0A    %7D%0A%0A    private static class Candidate%3CT%3E %7B%0A        final String name;%0A        final Parser%3C? extends T%3E parser;%0A%0A        Candidate(String name, Parser%3C? extends T%3E parser) %7B%0A            this.name = name;%0A            this.parser = parser;%0A        %7D%0A    %7D%0A%0A    private static class CandidateException %7B%0A        final String name;%0A        final ParseException exception;%0A%0A        CandidateException(String name, ParseException exception) %7B%0A            this.name = name;%0A            this.exception = exception;%0A        %7D%0A    %7D%0A%0A%7D%0A

implement OverloadParser