0
0

🧑‍💻 make char an attribute

This commit is contained in:
DrMaxNix 2022-09-08 17:36:05 +02:00
parent 8c224b6666
commit 376016c8a6

View File

@ -35,6 +35,9 @@ class Juicescript_lexer {
// start where last scan ended // start where last scan ended
this.start = this.end; this.start = this.end;
// consume next character
this.char = this.next();
// scan next token // scan next token
this.scan_one(); this.scan_one();
} }
@ -55,11 +58,7 @@ class Juicescript_lexer {
HELPER: Scan one token at current position HELPER: Scan one token at current position
*/ */
scan_one(){ scan_one(){
// consume next character switch(this.char){
let char = this.next();
// scan character
switch(char){
// WHITESPACE // // WHITESPACE //
case " ": case " ":
case "\r": case "\r":
@ -88,7 +87,7 @@ class Juicescript_lexer {
case "=": case "=":
if (this.match("=")) this.token_add({type: Juicescript.token_type.EQUAL}); if (this.match("=")) this.token_add({type: Juicescript.token_type.EQUAL});
else this.error("unexpected character '" + char + "'"); else this.error("unexpected character '" + this.char + "'");
break; break;
case "<": case "<":
@ -124,14 +123,14 @@ class Juicescript_lexer {
case "#": case "#":
case "/": case "/":
// block comment // block comment
if(char === "/" && this.match("*")){ if(this.char === "/" && this.match("*")){
this.scan_block_comment(); this.scan_block_comment();
break; break;
} }
// single slash // single slash
if(char === "/" && !this.match("/")){ if(this.char === "/" && !this.match("/")){
this.error("unexpected character '" + char + "'"); this.error("unexpected character '" + this.char + "'");
break; break;
} }
@ -143,12 +142,12 @@ class Juicescript_lexer {
// STRINGS // // STRINGS //
// handle escape sequences // handle escape sequences
case "\"": case "\"":
this.scan_string(char, true); this.scan_string(this.char, true);
break; break;
// ignore escape sequences // ignore escape sequences
case "'": case "'":
this.scan_string(char, false); this.scan_string(this.char, false);
break; break;
@ -177,7 +176,7 @@ class Juicescript_lexer {
} }
// ignore with error // ignore with error
this.error("unexpected character '" + char + "'"); this.error("unexpected character '" + this.char + "'");
break; break;
@ -191,26 +190,26 @@ class Juicescript_lexer {
} }
// ignore with error // ignore with error
this.error("unexpected character '" + char + "'"); this.error("unexpected character '" + this.char + "'");
break; break;
// EVERYTHING ELSE // // EVERYTHING ELSE //
default: default:
// numbers // numbers
if(this.is_digit(char)){ if(this.is_digit(this.char)){
this.scan_number(); this.scan_number();
break; break;
} }
// identifiers // identifiers
if(this.is_alpha(char)){ if(this.is_alpha(this.char)){
this.scan_identifier(); this.scan_identifier();
break; break;
} }
// unexpected (ignore with error) // unexpected (ignore with error)
this.error("unexpected character '" + char + "'"); this.error("unexpected character '" + this.char + "'");
break; break;
} }
} }
@ -323,7 +322,7 @@ class Juicescript_lexer {
// TRY TO CONSUME UNTIL END OF SOURCE // // TRY TO CONSUME UNTIL END OF SOURCE //
while(!this.is_at_end()){ while(!this.is_at_end()){
// do we have a `*/`? // do we have a `*/`?
if(this.peek(-1) === "*" && this.peek() === "/"){ if(this.char === "*" && this.peek() === "/"){
// block comment ends here // block comment ends here
break; break;
} }
@ -391,7 +390,7 @@ class Juicescript_lexer {
// HANDLE OTHER BASES // // HANDLE OTHER BASES //
// check for '0' prefix // check for '0' prefix
if(this.peek(-1) === "0"){ if(this.char === "0"){
// assume we have to cut off a prefix of length 2 // assume we have to cut off a prefix of length 2
number_string_offset = 2; number_string_offset = 2;
@ -664,7 +663,7 @@ class Juicescript_lexer {
} }
/* /*
HELPER: Automagically add additional info to stderr HELPER: Automagically keep track of problems and add additional info to stderr
*/ */
debug(text, additional){ debug(text, additional){
// add defaults // add defaults