Skip to content

Commit

Permalink
[scheme mode] Fix parsing of numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Jun 1, 2012
1 parent b06d307 commit 1ee8888
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions mode/scheme/scheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,6 @@ CodeMirror.defineMode("scheme", function (config, mode) {
state.indentStack = state.indentStack.prev;
}

/**
* Scheme numbers are complicated unfortunately.
* Checks if we're looking at a number, which might be possibly a fraction.
* Also checks that it is not part of a longer identifier. Returns true/false accordingly.
*/
function isNumber(ch, stream){
if (!stream.eatWhile(/[0-9]/)) {
if (stream.eat(/\//)) stream.eatWhile(/[0-9]/);
if (stream.eol() || !(/[a-zA-Z\-\_\/]/.test(stream.peek()))) return true;
stream.backUp(stream.current().length - 1); // undo all the eating
}
return false;
}

return {
startState: function () {
return {
Expand Down Expand Up @@ -124,15 +110,8 @@ CodeMirror.defineMode("scheme", function (config, mode) {
} else if (ch == ";") { // comment
stream.skipToEnd(); // rest of the line is a comment
returnType = COMMENT;
} else if (ch == "-"){

if(!isNaN(parseInt(stream.peek()))){
stream.eatWhile(/[\/0-9]/);
returnType = NUMBER;
}else{
returnType = null;
}
} else if (isNumber(ch,stream)){
} else if (/\d/.test(ch) && stream.match(/$|\d+(?:\/\d+|(?:\.\d+)?(?:[eE][+\-]?\d+)?)\b/) ||
ch == "-" && stream.match(/\d+(?:\/\d+|(?:\.\d+)?(?:[eE][+\-]?\d+)?)\b/)) {
returnType = NUMBER;
} else if (ch == "(" || ch == "[") {
var keyWord = ''; var indentTemp = stream.column();
Expand Down

0 comments on commit 1ee8888

Please sign in to comment.