mirror of
https://github.com/jamiebuilds/the-super-tiny-compiler.git
synced 2024-10-27 20:34:08 +00:00
Added support for alphanumeric and underscore for type name
This commit is contained in:
parent
47d0f2bd59
commit
47bd1ce4b8
@ -446,13 +446,15 @@ function tokenizer(input) {
|
|||||||
// ^^^
|
// ^^^
|
||||||
// Name token
|
// Name token
|
||||||
//
|
//
|
||||||
var LETTERS = /[a-zA-Z_0-9]/;
|
var validIdentifierStart = /[a-zA-Z_]/;
|
||||||
if (LETTERS.test(char)) {
|
var validIdentifierChar = /[a-zA-Z_0-9]/;
|
||||||
|
if (validIdentifierStart.test(char)) {
|
||||||
|
|
||||||
var value = '';
|
var value = '';
|
||||||
|
|
||||||
// Again we're just going to loop through all the letters pushing them to
|
// Again we're just going to loop through all the letters pushing them to
|
||||||
// a value.
|
// a value.
|
||||||
while (LETTERS.test(char)) {
|
while (validIdentifierChar.test(char)) {
|
||||||
value += char;
|
value += char;
|
||||||
char = input[++current];
|
char = input[++current];
|
||||||
}
|
}
|
||||||
|
6
test.js
6
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(codeGenerator(newAst), output, 'Code Generator should turn `newAst` into `output` string');
|
||||||
assert.deepStrictEqual(compiler(input), output, 'Compiler should turn `input` into `output`');
|
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!');
|
console.log('All Passed!');
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user