0
0

🧑‍💻 don't modify this.start on negative numbers for clean lexeme

This commit is contained in:
DrMaxNix 2022-09-07 16:58:30 +02:00
parent a14cdafcee
commit 8981e225e4

View File

@ -160,12 +160,11 @@ class Juicescript_lexer {
case "-": case "-":
// only if there's a valid digit after it // only if there's a valid digit after it
if(this.is_digit(this.peek())){ if(this.is_digit(this.peek())){
// ignore minus sign // consume minus sign
this.start += 1;
this.next(); this.next();
// scan like a normal number // scan like a normal number
this.scan_number(true); this.scan_number();
break; break;
} }
@ -353,8 +352,9 @@ class Juicescript_lexer {
/* /*
SCANNER: Handle number SCANNER: Handle number
*/ */
scan_number(negative = false){ scan_number(){
// DEFAULT VALUES FOR BASE 10 // // DEFAULT VALUES FOR POSITIVE BASE 10 NUMBER //
let negative = false;
let base = null; let base = null;
let is_valid_char = this.is_digit; let is_valid_char = this.is_digit;
let number_string_offset = 0; let number_string_offset = 0;
@ -410,10 +410,23 @@ class Juicescript_lexer {
} }
// get consumed string // get consumed string
let number_string = this.source.substring(this.start + number_string_offset, this.end); let number_string_full = this.source.substring(this.start, this.end);
// HANDLE NEGATIVE NUMBERS //
if(number_string_full.substring(0, 1) === "-"){
// remember to negate later
negative = true;
// ignore minus sign
number_string_offset++;
}
// STORE NUMBER IN TOKEN // // STORE NUMBER IN TOKEN //
// get number string
let number_string = number_string_full.substring(number_string_offset);
// parse number // parse number
let number; let number;
if(base !== null){ if(base !== null){