Skip to content

Commit

Permalink
[oz mode] clean up electric indentation test
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonygego authored and marijnh committed Sep 17, 2015
1 parent 72ca9ff commit 0c9a2ff
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions mode/oz/oz.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@ CodeMirror.defineMode("oz", function (conf) {
var doubleOperators = /(<-)|(:=)|(=<)|(>=)|(<=)|(<:)|(>:)|(=:)|(\\=)|(\\=:)|(!!)|(==)|(::)/;
var tripleOperators = /(:::)|(\.\.\.)|(=<:)|(>=:)/;

var middle = ["in", "then", "else", "of", "elseof", "elsecase", "elseif", "catch",
"finally", "with", "require", "prepare", "import", "export", "define", "do"];
var end = ["end"];

var atoms = wordRegexp(["true", "false", "nil", "unit"]);
var openingKeywords = wordRegexp(["local", "proc", "fun", "case", "class", "if", "cond", "or", "dis",
"choice", "not", "thread", "try", "raise", "lock", "for", "suchthat", "meth", "functor"]);
var middleKeywords = wordRegexp(["in", "then", "else", "of", "elseof", "elsecase", "elseif", "catch",
"finally", "with", "require", "prepare", "import", "export", "define", "do"]);
var commonKeywords = wordRegexp(["andthen", "at", "attr", "declare", "feat", "from", "lex",
"mod", "mode", "orelse", "parser", "prod", "prop", "scanner", "self", "syn", "token"]);
var endKeywords = wordRegexp(["end"]);
var openingKeywords = wordRegexp(["local", "proc", "fun", "case", "class", "if", "cond", "or", "dis",
"choice", "not", "thread", "try", "raise", "lock", "for", "suchthat", "meth", "functor"]);
var middleKeywords = wordRegexp(middle);
var endKeywords = wordRegexp(end);

// Tokenizers
function tokenBase(stream, state) {
Expand Down Expand Up @@ -200,6 +203,13 @@ CodeMirror.defineMode("oz", function (conf) {
};
}

function buildElectricInputRegEx() {
// Reindentation should occur on [] or on a match of any of
// the block closing keywords, at the end of a line.
var allClosings = middle.concat(end);
return new RegExp("[\\[\\]]|(" + allClosings.join("|") + ")$");
}

return {

startState: function () {
Expand Down Expand Up @@ -230,7 +240,7 @@ CodeMirror.defineMode("oz", function (conf) {
return state.currentIndent * conf.indentUnit;
},
fold: "indent",
electricChars: "eEdDtTnNiIoOfFhHyY[]",
electricInput: buildElectricInputRegEx(),
lineComment: "%",
blockCommentStart: "/*",
blockCommentEnd: "*/"
Expand Down

0 comments on commit 0c9a2ff

Please sign in to comment.