mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +00:00
remove goto
This commit is contained in:
parent
343c43c63e
commit
a5f65bb73f
22
src/parser.h
22
src/parser.h
@ -185,19 +185,23 @@ struct Parser {
|
|||||||
current_char--;
|
current_char--;
|
||||||
while(true){
|
while(true){
|
||||||
uint8_t c = peekChar();
|
uint8_t c = peekChar();
|
||||||
//printf("eatName: %d = %c\n", (int)c, c);
|
|
||||||
int u8bytes = 0;
|
int u8bytes = 0;
|
||||||
if((c & 0b10000000) == 0b00000000) u8bytes = 1;
|
if((c & 0b10000000) == 0b00000000) u8bytes = 1;
|
||||||
else if((c & 0b11100000) == 0b11000000) u8bytes = 2;
|
else if((c & 0b11100000) == 0b11000000) u8bytes = 2;
|
||||||
else if((c & 0b11110000) == 0b11100000) u8bytes = 3;
|
else if((c & 0b11110000) == 0b11100000) u8bytes = 3;
|
||||||
else if((c & 0b11111000) == 0b11110000) u8bytes = 4;
|
else if((c & 0b11111000) == 0b11110000) u8bytes = 4;
|
||||||
else return 1;
|
else return 1;
|
||||||
std::string u8str(current_char, u8bytes);
|
|
||||||
//printf("%s %d %c\n", u8str.c_str(), u8bytes, c);
|
|
||||||
if(u8str.size() != u8bytes) return 2;
|
|
||||||
if(u8bytes == 1){
|
if(u8bytes == 1){
|
||||||
if(isalpha(c) || c=='_' || isdigit(c)) goto __EAT_ALL_BYTES;
|
if(isalpha(c) || c=='_' || isdigit(c)) {
|
||||||
|
current_char++;
|
||||||
|
continue;
|
||||||
}else{
|
}else{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// handle multibyte char
|
||||||
|
std::string u8str(current_char, u8bytes);
|
||||||
|
if(u8str.size() != u8bytes) return 2;
|
||||||
uint32_t value = 0;
|
uint32_t value = 0;
|
||||||
for(int k=0; k < u8bytes; k++){
|
for(int k=0; k < u8bytes; k++){
|
||||||
uint8_t b = u8str[k];
|
uint8_t b = u8str[k];
|
||||||
@ -209,12 +213,8 @@ struct Parser {
|
|||||||
value |= (b & 0b00111111) << (6*(u8bytes-k-1));
|
value |= (b & 0b00111111) << (6*(u8bytes-k-1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// printf("value: %d", value);
|
if(__isLoChar(value)) current_char += u8bytes;
|
||||||
if(__isLoChar(value)) goto __EAT_ALL_BYTES;
|
else break;
|
||||||
}
|
|
||||||
break;
|
|
||||||
__EAT_ALL_BYTES:
|
|
||||||
current_char += u8bytes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int length = (int)(current_char - token_start);
|
int length = (int)(current_char - token_start);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user