package edu.hm.hafner.analysis.parser;

import java.util.Optional;
import java.util.regex.Matcher;

import org.apache.commons.lang3.StringUtils;

import edu.hm.hafner.analysis.Issue;
import edu.hm.hafner.analysis.IssueBuilder;
import edu.hm.hafner.analysis.Severity;
import edu.hm.hafner.analysis.RegexpDocumentParser;

/**
 * A parser for messages from the NAG Fortran Compiler.
 *
 * @author Mat Cross.
 */
public class NagFortranParser extends RegexpDocumentParser {
    private static final long serialVersionUID = 2072414911276743946L;

    private static final String NAGFOR_MSG_PATTERN = "^(Info|Warning|Questionable|Extension|Obsolescent|Deleted "
            + "feature used|Error|Runtime Error|Fatal Error|Panic): (.+\\.[^,:\\n]+)(, line (\\d+))?: (.+($\\s+detected"
            + " at .+)?)";

    /**
     * Creates a new instance of {@link NagFortranParser}.
     */
    public NagFortranParser() {
        super(NAGFOR_MSG_PATTERN, true);
    }

    @Override
    protected Optional<Issue> createIssue(final Matcher matcher, final IssueBuilder builder) {
        String category = matcher.group(1);

        return builder.setFileName(matcher.group(2))
                .setLineStart(getLineNumber(matcher))
                .setCategory(category)
                .setMessage(matcher.group(5))
                .setSeverity(mapPriority(category))
                .buildOptional();
    }

    private Severity mapPriority(final String category) {
        switch (category) {
            case "Error":
            case "Runtime Error":
            case "Fatal Error":
            case "Panic":
                return Severity.WARNING_HIGH;
            case "Info":
                return Severity.WARNING_LOW;
            default:
                return Severity.WARNING_NORMAL;
        }
    }

    private int getLineNumber(final Matcher matcher) {
        int lineNumber;
        if (StringUtils.isEmpty(matcher.group(4))) {
            lineNumber = 0;
        }
        else {
            lineNumber = Integer.parseInt(matcher.group(4));
        }
        return lineNumber;
    }
}

@@ -220,16 +220,111 @@
 uilder;%0A
+import edu.hm.hafner.analysis.LookaheadParser;%0Aimport edu.hm.hafner.analysis.ParsingException;%0A
 import e
@@ -406,16 +406,59 @@
 tParser;
+%0Aimport edu.hm.hafner.util.LookaheadStream;
 %0A%0A/**%0A *
@@ -578,30 +578,25 @@
 extends 
-RegexpDocument
+Lookahead
 Parser %7B
@@ -1074,14 +1074,8 @@
 TERN
-, true
 );%0A 
@@ -1089,16 +1089,18 @@
    @
-Override
+Deprecated
 %0A   
@@ -1513,32 +1513,702 @@
 ional();%0A    %7D%0A%0A
+    @Override%0A    protected Optional%3CIssue%3E createIssue(final Matcher matcher, final LookaheadStream lookahead,%0A            final IssueBuilder builder)%0A            throws ParsingException %7B%0A%0A        if (lookahead.hasNext()) %7B%0A            String category = matcher.group(1);%0A%0A            return builder.setFileName(matcher.group(2))%0A                    .setLineStart(getLineNumber(matcher))%0A                    .setCategory(category)%0A                    .setMessage(matcher.group(5))%0A                    .setSeverity(mapPriority(category))%0A                    .buildOptional();%0A        %7D%0A        else %7B%0A            throw new ParsingException(%22Bla bla%22);%0A        %7D%0A    %7D%0A%0A
     private Seve

Replace RegexpDocumentParser with LookaheadParser at NagFortranParser