X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=code%2Ftokens.js;h=b83c36d19b96f40f047d3c5202c4f47316870dfb;hp=98277a0f6144dd6a0b4c0b444233596515fe94ae;hb=516417f5f9ac78553dd1788e263878ff6016f21d;hpb=42859c95fe5548d1fc3c3f5b03980b13a35ebf35 diff --git a/code/tokens.js b/code/tokens.js index 98277a0f..b83c36d1 100644 --- a/code/tokens.js +++ b/code/tokens.js @@ -1,25 +1,26 @@ // Based on tokens.js -// 2009-05-17 -// (c) 2006 Douglas Crockford +// 2009-05-17 +// (c) 2006 Douglas Crockford -// Produce an array of simple token objects from a string. -// A simple token object contains these members: -// type: 'name', 'string', 'number', 'operator' -// value: string or number value of the token -// from: index of first character of the token -// to: index of the last character + 1 +// Produce an array of simple token objects from a string. +// A simple token object contains these members: +// type: 'name', 'string', 'number', 'operator' +// value: string or number value of the token +// from: index of first character of the token +// to: index of the last character + 1 -// Comments of the ; type are ignored. - -// Operators are by default single characters. Multicharacter -// operators can be made by supplying a string of prefix and -// suffix characters. -// characters. For example, -// '<>+-&', '=>&:' -// will match any of these: -// <= >> >>> <> >= +: -: &: &&: && +// Comments of the ; type are ignored. +// Operators are by default single characters. Multicharacter +// operators can be made by supplying a string of prefix and +// suffix characters. +// characters. For example, +// '<>+-&', '=>&:' +// will match any of these: +// <= >> >>> <> >= +: -: &: &&: && +/*jslint onevar: false + */ String.prototype.tokens = function (prefix, suffix) { var c; // The current character. @@ -53,10 +54,10 @@ String.prototype.tokens = function (prefix, suffix) { // If prefix and suffix strings are not provided, supply defaults. if (typeof prefix !== 'string') { - prefix = ''; + prefix = ''; } if (typeof suffix !== 'string') { - suffix = ''; + suffix = ''; } @@ -111,7 +112,7 @@ String.prototype.tokens = function (prefix, suffix) { // Make sure the next character is not a letter. - if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '_') { + if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c === '_') { str += c; i += 1; make('number', str).error("Bad number"); @@ -129,7 +130,7 @@ String.prototype.tokens = function (prefix, suffix) { // comment. - } else if (c === ';') { + } else if (c === ';') { for (;;) { c = this.charAt(i); if (c === '\n' || c === '\r' || c === '') {