@ -6,24 +6,51 @@ var error = require("./errors.js");
var operators = Object . keys ( rep . OPInfo ) ;
var _ = require ( "underscore" ) ;
function isDigit ( a ) {
if ( ! a )
function isDigit ( c ) {
if ( ! c )
return false ;
var code = a . charCodeAt ( ) ;
return ( 46 < code && code < 58 || code < 58 && code > 46 ) ;
var code = c . charCodeAt ( ) ;
if ( isNaN ( code ) ) {
return false ;
}
return ( 46 < code &&
code < 58 ||
code < 58 &&
code > 46 ) ;
}
function isWhitespace ( a ) {
if ( ! a )
function isWhitespace ( c ) {
if ( ! c )
return true ;
var code = a . charCodeAt ( ) ;
return ( code === 9 || code === 32 || code === 10 || code === 13 || code === 11 ) ;
var code = c . charCodeAt ( ) ;
if ( isNaN ( code ) ) {
return false ;
}
return ( code === 9 ||
code === 32 ||
code === 10 ||
code === 13 ||
code === 11 ) ;
}
function isIdentifier ( a ) {
var code = a . charCodeAt ( ) ;
return code !== 41 && code !== 40 && code && 125 && code && 123 && code !== 93 && code !== 91 && code !== 44 ;
function isIdentifier ( c ) {
var code = c . charCodeAt ( ) ;
return ( ! isNaN ( code ) &&
code !== 41 &&
code !== 40 &&
code !== 125 &&
code !== 123 &&
code !== 93 &&
code !== 91 &&
code !== 44 ) ;
}
function isUpper ( c ) {
var code = c . charCodeAt ( ) ;
return ( ! isNaN ( code ) &&
( code >= 65 ) &&
( code <= 90 ) ) ;
}
function tokenizeNum ( tokstream , charnum , linenum ) {
@ -79,7 +106,10 @@ function tokenizeNum(tokstream, charnum, linenum) {
* Everything after the operator goes back on to the token stream
* /
function tokenizeIdent ( tokstream , matchop , charnum , linenum ) {
function tokenizeIdent ( tokstream ,
matchop ,
charnum ,
linenum ) {
var identifier = [ ] ;
var n = 0 ;
while ( ( ! isWhitespace ( tokstream [ 0 ] ) ) && isIdentifier ( tokstream [ 0 ] ) && ! matchop ( tokstream ) ) {
@ -93,6 +123,18 @@ function tokenizeIdent(tokstream, matchop, charnum, linenum) {
return [ [ n , [ "identifier" , identifier , charnum , linenum ] ] ] ;
}
function tokenizeCtor ( tokstream ,
matchop ,
charnum ,
linenum ) {
var ident = tokenizeIdent ( tokstream ,
matchop ,
charnum ,
linenum ) ;
ident [ 0 ] [ 1 ] [ 0 ] = "constructor" ;
return ident ;
}
function tokenizeStr ( tokstream , charnum , linenum ) {
var stringlit = [ ] ;
var n = 1 ;
@ -212,9 +254,9 @@ function tokenize(tokstream, matchop) {
break ;
/* falls through */
case 45 : // '-'
/*case 45: / / '-'
lambda = peek ( tokstream , "arrow" , "->" ) ;
if ( lambda ) {
if ( false ) {
tokens . push ( $ . extend ( lambda , [ charnum , linenum ] ) ) ;
tokstream = tokstream . substr ( 2 ) ;
break ;
@ -325,8 +367,13 @@ function tokenize(tokstream, matchop) {
tokstream = tokstream . substr ( l ) ;
tokens . push ( [ "identifier" , op , charnum , linenum ] ) ;
}
else {
if ( isUpper ( tokstream [ 0 ] ) ) {
result = tokenizeCtor ( tokstream , matchop , charnum , linenum ) ;
}
else {
result = tokenizeIdent ( tokstream , matchop , charnum , linenum ) ;
}
for ( var index = 0 ; index < result . length ; index ++ ) {
charnum ++ ;
tokens . push ( result [ index ] [ 1 ] ) ;
@ -376,4 +423,6 @@ function tokenizeFull(input) {
return tokenizeHelp ( input , matchop , true ) ;
}
module . exports = { tokenize : tokenizeFull } ;
module . exports = { tokenize : tokenizeFull ,
isIdentifier : isIdentifier } ;