Skip to content

Instantly share code, notes, and snippets.

@agrafix
Created September 28, 2014 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agrafix/ab66da8c8329d00caf25 to your computer and use it in GitHub Desktop.
Save agrafix/ab66da8c8329d00caf25 to your computer and use it in GitHub Desktop.
var samples =
[ ' do var <- readTVar'
, 'do foo'
, 'main = do let x = do { foo }'
, 'main = do let x = do foo'
, 'main = foo $ do '
];
for (var i in samples) {
var line = samples[i];
if (line.search(/(\s*do\s+)/) !== -1) {
var lastDo = line.lastIndexOf("do");
var rest = line.substring(lastDo+2);
if (rest.trim() === "") {
console.log("No match: " + line);
continue;
}
if (rest.indexOf("{") !== -1) {
lastDo = line.substring(0, lastDo).lastIndexOf("do");
}
var ident = Array(lastDo+1+3).join(" ");
console.log(line);
console.log(ident + "^");
console.log("--------------------------");
} else {
console.log("No match: " + line);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment