From 0138cbec17a19c66032879933491d3b0c890609e Mon Sep 17 00:00:00 2001 From: Rhythm Date: Thu, 7 Apr 2016 18:53:00 +0530 Subject: [PATCH 1/2] added alphanumeric and underscore support for type name --- super-tiny-compiler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/super-tiny-compiler.js b/super-tiny-compiler.js index e4e214d..ea9c051 100644 --- a/super-tiny-compiler.js +++ b/super-tiny-compiler.js @@ -446,7 +446,7 @@ function tokenizer(input) { // ^^^ // Name token // - var LETTERS = /[a-z]/i; + var LETTERS = /[a-zA-Z_0-9]/; if (LETTERS.test(char)) { var value = ''; @@ -934,4 +934,4 @@ module.exports = { transformer: transformer, codeGenerator: codeGenerator, compiler: compiler -}; +}; \ No newline at end of file From 47bd1ce4b8212c0836b79c7ba9d5a42c140029e8 Mon Sep 17 00:00:00 2001 From: Rhythm Date: Fri, 8 Apr 2016 11:26:29 +0530 Subject: [PATCH 2/2] Added support for alphanumeric and underscore for type name --- super-tiny-compiler.js | 10 ++++++---- test.js | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/super-tiny-compiler.js b/super-tiny-compiler.js index ea9c051..95482bd 100644 --- a/super-tiny-compiler.js +++ b/super-tiny-compiler.js @@ -446,13 +446,15 @@ function tokenizer(input) { // ^^^ // Name token // - var LETTERS = /[a-zA-Z_0-9]/; - if (LETTERS.test(char)) { + var validIdentifierStart = /[a-zA-Z_]/; + var validIdentifierChar = /[a-zA-Z_0-9]/; + if (validIdentifierStart.test(char)) { + var value = ''; // Again we're just going to loop through all the letters pushing them to // a value. - while (LETTERS.test(char)) { + while (validIdentifierChar.test(char)) { value += char; char = input[++current]; } @@ -465,7 +467,7 @@ function tokenizer(input) { continue; } - + // Finally if we have not matched a character by now, we're going to throw // an error and completely exit. throw new TypeError('I dont know what this character is: ' + char); diff --git a/test.js b/test.js index ef351a8..afc794d 100644 --- a/test.js +++ b/test.js @@ -81,4 +81,10 @@ assert.deepStrictEqual(transformer(ast), newAst, 'Transformer should turn `ast` assert.deepStrictEqual(codeGenerator(newAst), output, 'Code Generator should turn `newAst` into `output` string'); assert.deepStrictEqual(compiler(input), output, 'Compiler should turn `input` into `output`'); +//Identifier Test +input = '(_add 2 (subtract 4 2))'; +output = '_add(2, subtract(4, 2));'; +assert.deepStrictEqual(compiler(input), output, 'Compiler should turn `input` into `output`'); console.log('All Passed!'); + +