/*
 * Created on 2004-08-20
 *
 * Part of the Symbian development plug-in for Eclipse
 * Copyright (C) Mikołaj Zalewski, 2004
 */
package pl.zalewski.mikolaj.symbdev.errorparsers;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.eclipse.cdt.core.ErrorParserManager;
import org.eclipse.cdt.core.IErrorParser;
import org.eclipse.cdt.core.IMarkerGenerator;

/**
 * @author mikolaj
 *
 * This class parses the output of the ilink (Visual Studio linker)
 * to find error messages
 */
public class MsLinkErrorParser implements IErrorParser {

    public MsLinkErrorParser() {
        super();
        fErrorMatch=Pattern.compile("^[\\w\\.\\-_\\\\:/]+(\\([\\w\\.\\-_\\\\:/]+\\))?\\s*:\\s*(fatal\\s*)?error\\s+(LNK.*)$");
        fWarningMatch=Pattern.compile("^[\\w\\.\\-_\\\\:/]+(\\([\\w\\.\\-_\\\\:/]+\\))?\\s*:\\s*warning\\s+(LNK.*)$");
    }
    
    Pattern fErrorMatch;
    Pattern fWarningMatch;

    /* (non-Javadoc)
     * @see org.eclipse.cdt.core.IErrorParser#processLine(java.lang.String, org.eclipse.cdt.core.ErrorParserManager)
     */
    public boolean processLine(String line, ErrorParserManager eoParser) {
        Matcher matcher=fErrorMatch.matcher(line);
        if (matcher.matches())
        {
			eoParser.generateMarker(null, -1, matcher.group(3), IMarkerGenerator.SEVERITY_ERROR_BUILD, null);
			return true;
        }

        matcher=fWarningMatch.matcher(line);
        if (matcher.matches())
        {
			eoParser.generateMarker(null, -1, matcher.group(2), IMarkerGenerator.SEVERITY_WARNING, null);
			return true;
        }
        return false;
    }

}
