This commit is contained in:
blueloveTH 2023-01-31 21:17:25 +08:00
parent 5e1226b9ac
commit c1485392cf
4 changed files with 23 additions and 37 deletions

View File

@ -3184,13 +3184,15 @@ struct Parser {
inline char peekchar() const{ return *curr_char; } inline char peekchar() const{ return *curr_char; }
std::string_view lookahead(int n) const{ bool match_n_chars(int n, char c0){
const char* c = curr_char; const char* c = curr_char;
for(int i=0; i<n; i++){ for(int i=0; i<n; i++){
if(*c == '\0') return std::string_view(curr_char, i); if(*c == '\0') return false;
if(*c != c0) return false;
c++; c++;
} }
return std::string_view(curr_char, n); for(int i=0; i<n; i++) eatchar_include_newline();
return true;
} }
int eat_spaces(){ int eat_spaces(){
@ -3233,7 +3235,7 @@ struct Parser {
return c; return c;
} }
char eatchar_include_newLine() { char eatchar_include_newline() {
char c = peekchar(); char c = peekchar();
curr_char++; curr_char++;
if (c == '\n'){ if (c == '\n'){
@ -3329,7 +3331,7 @@ struct Parser {
// true otherwise returns false. // true otherwise returns false.
bool matchchar(char c) { bool matchchar(char c) {
if (peekchar() != c) return false; if (peekchar() != c) return false;
eatchar_include_newLine(); eatchar_include_newline();
return true; return true;
} }
@ -4675,7 +4677,7 @@ public:
setattr(type, __name__, PyStr(name)); setattr(type, __name__, PyStr(name));
} }
this->__py2py_call_signal = new_object(_tp_object, (i64)7); this->__py2py_call_signal = new_object(_tp_object, DUMMY_VAL);
std::vector<_Str> publicTypes = {"type", "object", "bool", "int", "float", "str", "list", "tuple", "range"}; std::vector<_Str> publicTypes = {"type", "object", "bool", "int", "float", "str", "list", "tuple", "range"};
for (auto& name : publicTypes) { for (auto& name : publicTypes) {
@ -4968,30 +4970,16 @@ public:
} }
_Str eatStringUntil(char quote, bool raw) { _Str eatStringUntil(char quote, bool raw) {
bool quote3 = false; bool quote3 = parser->match_n_chars(2, quote);
std::string_view sv = parser->lookahead(2);
if(sv.size() == 2 && sv[0] == quote && sv[1] == quote) {
quote3 = true;
parser->eatchar();
parser->eatchar();
}
std::vector<char> buff; std::vector<char> buff;
while (true) { while (true) {
char c = parser->eatchar_include_newLine(); char c = parser->eatchar_include_newline();
if (c == quote){ if (c == quote){
if(quote3){ if(quote3 && !parser->match_n_chars(2, quote)){
sv = parser->lookahead(2);
if(sv.size() == 2 && sv[0] == quote && sv[1] == quote) {
parser->eatchar();
parser->eatchar();
break;
}
buff.push_back(c); buff.push_back(c);
continue; continue;
} else {
break;
} }
break;
} }
if (c == '\0'){ if (c == '\0'){
if(quote3 && parser->src->mode == SINGLE_MODE){ if(quote3 && parser->src->mode == SINGLE_MODE){
@ -5007,7 +4995,7 @@ public:
} }
} }
if (!raw && c == '\\') { if (!raw && c == '\\') {
switch (parser->eatchar_include_newLine()) { switch (parser->eatchar_include_newline()) {
case '"': buff.push_back('"'); break; case '"': buff.push_back('"'); break;
case '\'': buff.push_back('\''); break; case '\'': buff.push_back('\''); break;
case '\\': buff.push_back('\\'); break; case '\\': buff.push_back('\\'); break;
@ -5076,7 +5064,7 @@ public:
while (parser->peekchar() != '\0') { while (parser->peekchar() != '\0') {
parser->token_start = parser->curr_char; parser->token_start = parser->curr_char;
char c = parser->eatchar_include_newLine(); char c = parser->eatchar_include_newline();
switch (c) { switch (c) {
case '\'': case '"': eatString(c, NORMAL_STRING); return; case '\'': case '"': eatString(c, NORMAL_STRING); return;
case '#': parser->skip_line_comment(); break; case '#': parser->skip_line_comment(); break;

@ -1 +1 @@
Subproject commit 67715ff019df22dc7a99a73352515eb7106b33b9 Subproject commit e84dedd36affa57df6b9bf845b456df2de5de872

View File

@ -101,15 +101,13 @@ public:
bool quote3 = parser->match_n_chars(2, quote); bool quote3 = parser->match_n_chars(2, quote);
std::vector<char> buff; std::vector<char> buff;
while (true) { while (true) {
char c = parser->eatchar_include_newLine(); char c = parser->eatchar_include_newline();
if (c == quote){ if (c == quote){
if(!quote3) break; if(quote3 && !parser->match_n_chars(2, quote)){
if(parser->match_n_chars(2, quote)) {
break;
}else{
buff.push_back(c); buff.push_back(c);
continue; continue;
} }
break;
} }
if (c == '\0'){ if (c == '\0'){
if(quote3 && parser->src->mode == SINGLE_MODE){ if(quote3 && parser->src->mode == SINGLE_MODE){
@ -125,7 +123,7 @@ public:
} }
} }
if (!raw && c == '\\') { if (!raw && c == '\\') {
switch (parser->eatchar_include_newLine()) { switch (parser->eatchar_include_newline()) {
case '"': buff.push_back('"'); break; case '"': buff.push_back('"'); break;
case '\'': buff.push_back('\''); break; case '\'': buff.push_back('\''); break;
case '\\': buff.push_back('\\'); break; case '\\': buff.push_back('\\'); break;
@ -194,7 +192,7 @@ public:
while (parser->peekchar() != '\0') { while (parser->peekchar() != '\0') {
parser->token_start = parser->curr_char; parser->token_start = parser->curr_char;
char c = parser->eatchar_include_newLine(); char c = parser->eatchar_include_newline();
switch (c) { switch (c) {
case '\'': case '"': eatString(c, NORMAL_STRING); return; case '\'': case '"': eatString(c, NORMAL_STRING); return;
case '#': parser->skip_line_comment(); break; case '#': parser->skip_line_comment(); break;

View File

@ -124,7 +124,7 @@ struct Parser {
if(*c != c0) return false; if(*c != c0) return false;
c++; c++;
} }
for(int i=0; i<n; i++) eatchar_include_newLine(); for(int i=0; i<n; i++) eatchar_include_newline();
return true; return true;
} }
@ -168,7 +168,7 @@ struct Parser {
return c; return c;
} }
char eatchar_include_newLine() { char eatchar_include_newline() {
char c = peekchar(); char c = peekchar();
curr_char++; curr_char++;
if (c == '\n'){ if (c == '\n'){
@ -264,7 +264,7 @@ struct Parser {
// true otherwise returns false. // true otherwise returns false.
bool matchchar(char c) { bool matchchar(char c) {
if (peekchar() != c) return false; if (peekchar() != c) return false;
eatchar_include_newLine(); eatchar_include_newline();
return true; return true;
} }