/*
 * Created on 2004-10-07
 *
 * 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;
import org.eclipse.core.resources.IFile;

/**
 * Parese the strings after the MMPFILE output of ABLD
 * 
 * @author mikolaj
 */
public class MMPFileErrorParser implements IErrorParser {

    public MMPFileErrorParser()
    {
        super();
        fErrorMatch=Pattern.compile("^\\s*([^\\*\\?\\(\\)]+)\\(([0-9]+)\\) : (.*)$");        
    }

    /* (non-Javadoc)
     * @see org.eclipse.cdt.core.IErrorParser#processLine(java.lang.String, org.eclipse.cdt.core.ErrorParserManager)
     */
    public boolean processLine(String line, ErrorParserManager eoParser) {
        if (line.equals("FATAL ERROR(S)"))
        {
            fSeverity=IMarkerGenerator.SEVERITY_ERROR_BUILD;
            return true;
        }
        
        if (line.equals("WARNING(S)"))
        {
            fSeverity=IMarkerGenerator.SEVERITY_WARNING;
            return true;
        }
        
        Matcher matcher=fErrorMatch.matcher(line);
        if (matcher.matches())
        {
    		IFile file = eoParser.findFilePath(matcher.group(1));
			eoParser.generateMarker(file, Integer.parseInt(matcher.group(2)),
			        matcher.group(3), fSeverity, null);
			return true;
        }        
        
        return false;
    }

    String fFileName;
    Pattern fErrorMatch;
    int fSeverity=IMarkerGenerator.SEVERITY_INFO;
}
