/*
 * Created on 2004-08-21
 *
 * 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
 *
 * Parsers the errors and warning of the Visual Studio nmake utility
 */
public class NMakeErrorParser implements IErrorParser {

    /**
     * 
     */
    public NMakeErrorParser() {
        super();
        fErrorMatch=Pattern.compile("^NMAKE :\\s*error\\s+(U.*)$");
        fFatalErrorMatch=Pattern.compile("^NMAKE :\\s*fatal error\\s+(U.*)$");
        fWarningMatch=Pattern.compile("^NMAKE :\\s*warning\\s+(U.*)$");
    }
    
    Pattern fErrorMatch;
    Pattern fFatalErrorMatch;
    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(1), IMarkerGenerator.SEVERITY_ERROR_BUILD, null);
			return true;
        }
        
        matcher=fFatalErrorMatch.matcher(line);
        if (matcher.matches())
        {
			eoParser.generateMarker(null, -1, matcher.group(1), IMarkerGenerator.SEVERITY_ERROR_BUILD, null);
			return true;
        }        

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

}
