How to indent if..then..else..end in simple mode

I’m trying to add my own mode, for ruby like language usig simple mode.
I want to indent something like this:

if name == "dir" then
    echo "<DIR>"
else if name == "echo" then
    echo args.join(" ")
else
    echo "Invalid Command"
    end

The problem is that end is not properly indented.

I use this code:

     CodeMirror.defineSimpleMode("gaiman", {
         // The start state contains the rules that are initially used
         start: [
             // The regex matches the token, the token property contains the type
             { regex: /"(?:[^\\]|\\.)*?(?:"|$)/, token: "string" },
             // You can match multiple tokens at once. Note that the captured
             // groups must span the whole string in this case
             { regex: /(?:do|then|def|lambda|else(?!\s+if))\b/, token: "keyword", indent: true },
             { regex: /(?:end|else)\b/, token: "keyword", dedent: true },
             { regex: new RegExp('(?:' + keywordList.join('|') + ')\\b'), token: "keyword" },
             { regex: /(def)(\s+)([a-z$][\w$]*)/,
              token: ["keyword", null, "variable-2"] },
             { regex: /true|false|null|undefined/, token: "atom" },
             { regex: /0x[a-f\d]+|[-+]?(?:\.\d+|\d+\.?\d*)(?:e[-+]?\d+)?/i,
               token: "number" },
             { regex: /#.*/, token: "comment" },
             { regex: /\/(?:[^\\]|\\.)*?\//, token: "variable-3" },
             { regex: /[-+\/*=<>!]+/, token: "operator" },
             // indent and dedent properties guide autoindentation
             { regex: /[\{\[\(]/, indent: true },
             { regex: /[\}\]\)]/, dedent: true },
             { regex: /[a-z$][\w$]*/, token: "variable" },
             { regex: /<</, token: "meta", mode: {spec: "xml", end: />>/} }
         ],
         meta: {
             dontIndentStates: ["comment"],
             lineComment: "#"
         }
     });

If I remove |else(?!\s+if) from first indent regex, it don’t indent the else clause

if name == "dir" then
    echo "<DIR>"
else if name == "echo" then
    echo args.join(" ")
else
echo "Invalid Command"
end

I’ve figure that out, I needed else without if to be both ident and dedent

{ regex: /(?:do|then|def|lambda)\b/, token: "keyword", indent: true },
{ regex: /(?:else(?!\b\s+if))\b/, token: "keyword", indent: true, dedent: true },
{ regex: /(?:end|else)\b/, token: "keyword", dedent: true },