"use babel";

export default {
    config: {
        executable: {
            type: "string",
            default: "gfortran"
        },
        gfortran_flags: {
            type: "string",
            default: "-Wall -Wextra"
        },
    },

    activate: () => {
        require("atom-package-deps").install("linter-gfortran");
    },

    provideLinter: () => {
        const helpers = require("atom-linter");
        const regex = "(?<file>.+):(?<line>\\d+):(?<col>\\d+):((.|\\n)*)(?<type>(Error|Warning|Note)):\\s*(?<message>.*)";
        const tmpdir = require('tmp').dirSync().name;
        return {
            name: "gfortran",
            grammarScopes: ["source.fortran.free"],
            scope: "file",
            lintOnFly: false,
            lint: (activeEditor) => {
                const command = atom.config.get("linter-gfortran.executable");
                const file = activeEditor.getPath();

                const args = ["-fsyntax-only", "-J", tmpdir];
                args.push(file);

                return helpers.exec(command, args, {stream: "stderr"}).then(output =>
                    helpers.parse(output, regex)
                );
            }
        };
    }
};

@@ -663,16 +663,33 @@
 copes: %5B
+%0A                
 %22source.
@@ -701,16 +701,154 @@
 an.free%22
+,%0A                %22source.fortran.fixed%22,%0A                %22source.fortran.modern%22,%0A                %22source.fortran.punchcard%22%0A            
 %5D,%0A     

Support all the fortran grammars