Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.

Commit

Permalink
Refactored identifierToken to use keywordTokens map.
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Feldman committed Jul 26, 2013
1 parent d51d7ff commit 8d18325
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions src/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,39 @@ var INDENT = /^(?:\n[^\n\S]*)+/;
var GENERIC = /^#([a-z]+)/;
var SHEBANG = /^#!.*/;

var keywordTokens = {
'true': 'BOOLEAN',
'false': 'BOOLEAN',
'Function': 'FUNCTION',
'let': 'LET',
'if': 'IF',
'instance': 'INSTANCE',
'then': 'THEN',
'else': 'ELSE',
'data': 'DATA',
'type': 'TYPE',
'typeclass': 'TYPECLASS',
'match': 'MATCH',
'case': 'CASE',
'do': 'DO',
'return': 'RETURN',
'with': 'WITH',
'where': 'WHERE'
};

var chunk;
var indent;
var indents;
var tokens;
var lineno;

var identifierToken = function() {
var value,
name,
token = IDENTIFIER.exec(chunk);
var token = IDENTIFIER.exec(chunk);

if(token) {
value = token[0];
switch(value) {
case 'true':
case 'false':
name = 'BOOLEAN';
break;
case 'Function':
case 'let':
case 'if':
case 'instance':
case 'then':
case 'else':
case 'data':
case 'type':
case 'typeclass':
case 'match':
case 'case':
case 'do':
case 'return':
case 'with':
case 'where':
name = value.toUpperCase();
break;
default:
name = 'IDENTIFIER';
break;
}
var value = token[0],
name = keywordTokens[value] || 'IDENTIFIER';

tokens.push([name, value, lineno]);
return token[0].length;
}
Expand Down

0 comments on commit 8d18325

Please sign in to comment.