fix infinite loop

pull/66/head
huhu 5 years ago
parent 4f7a85a9f8
commit cbc5f013ca

@ -420,7 +420,7 @@ function tokenizer(input) {
// Next we're going to check for a closing parenthesis. We do the same exact // Next we're going to check for a closing parenthesis. We do the same exact
// thing as before: Check for a closing parenthesis, add a new token, // thing as before: Check for a closing parenthesis, add a new token,
// increment `current`, and `continue`. // increment `current`, and `continue`.
if (char === ')') { else if (char === ')') {
tokens.push({ tokens.push({
type: 'paren', type: 'paren',
value: ')', value: ')',
@ -436,8 +436,7 @@ function tokenizer(input) {
// //
// So here we're just going to test for existence and if it does exist we're // So here we're just going to test for existence and if it does exist we're
// going to just `continue` on. // going to just `continue` on.
let WHITESPACE = /\s/; else if (/\s/.test(char)) {
if (WHITESPACE.test(char)) {
current++; current++;
continue; continue;
} }
@ -451,8 +450,7 @@ function tokenizer(input) {
// Only two separate tokens // Only two separate tokens
// //
// So we start this off when we encounter the first number in a sequence. // So we start this off when we encounter the first number in a sequence.
let NUMBERS = /[0-9]/; else if (/[0-9]/.test(char)) {
if (NUMBERS.test(char)) {
// We're going to create a `value` string that we are going to push // We're going to create a `value` string that we are going to push
// characters to. // characters to.
@ -480,7 +478,7 @@ function tokenizer(input) {
// ^^^ ^^^ string tokens // ^^^ ^^^ string tokens
// //
// We'll start by checking for the opening quote: // We'll start by checking for the opening quote:
if (char === '"') { else if (char === '"') {
// Keep a `value` variable for building up our string token. // Keep a `value` variable for building up our string token.
let value = ''; let value = '';
@ -511,13 +509,12 @@ function tokenizer(input) {
// ^^^ // ^^^
// Name token // Name token
// //
let LETTERS = /[a-z]/i; else if (/[a-z]/i.test(char)) {
if (LETTERS.test(char)) {
let value = ''; let 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 (char && /[a-z]/i.test(char)) {
value += char; value += char;
char = input[++current]; char = input[++current];
} }
@ -526,17 +523,19 @@ function tokenizer(input) {
tokens.push({ type: 'name', value }); tokens.push({ type: 'name', value });
continue; continue;
} else {
current ++;
} }
// Finally if we have not matched a character by now, we're going to throw // Finally if we have not matched a character by now, we're going to throw
// an error and completely exit. // an error and completely exit.
throw new TypeError('I dont know what this character is: ' + char); // throw new TypeError('I dont know what this character is: ' + char);
} }
// Then at the end of our `tokenizer` we simply return the tokens array. // Then at the end of our `tokenizer` we simply return the tokens array.
return tokens; return tokens;
} }
/** /**
* ============================================================================ * ============================================================================
* /o ل͜ o\ * /o ل͜ o\

Loading…
Cancel
Save