mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-21 20:10:17 +00:00
fix a parser bug
This commit is contained in:
parent
3219f588c2
commit
a28afb60be
@ -756,6 +756,10 @@ __EAT_DOTS_END:
|
||||
}
|
||||
|
||||
void Compiler::compile_stmt() {
|
||||
if(match(TK("class"))){
|
||||
compile_class();
|
||||
return;
|
||||
}
|
||||
advance();
|
||||
int kw_line = prev().line; // backup line number
|
||||
int curr_loop_block = ctx()->get_loop();
|
||||
@ -968,6 +972,12 @@ __EAT_DOTS_END:
|
||||
base->emit_(ctx());
|
||||
}
|
||||
ctx()->emit_(OP_BEGIN_CLASS, namei, BC_KEEPLINE);
|
||||
|
||||
for(auto& c: this->contexts.data()){
|
||||
if(c.is_compiling_class){
|
||||
SyntaxError("nested class is not allowed");
|
||||
}
|
||||
}
|
||||
ctx()->is_compiling_class = true;
|
||||
compile_block_body();
|
||||
ctx()->is_compiling_class = false;
|
||||
@ -1134,10 +1144,6 @@ __EAT_DOTS_END:
|
||||
used = true;
|
||||
|
||||
tokens = lexer->run();
|
||||
// if(lexer->src->filename == "<stdin>"){
|
||||
// for(auto& t: tokens) std::cout << t.info() << std::endl;
|
||||
// }
|
||||
|
||||
CodeObject_ code = push_global_context();
|
||||
|
||||
advance(); // skip @sof, so prev() is always valid
|
||||
@ -1161,11 +1167,7 @@ __EAT_DOTS_END:
|
||||
}
|
||||
|
||||
while (!match(TK("@eof"))) {
|
||||
if (match(TK("class"))) {
|
||||
compile_class();
|
||||
} else {
|
||||
compile_stmt();
|
||||
}
|
||||
compile_stmt();
|
||||
match_newlines();
|
||||
}
|
||||
pop_context();
|
||||
|
@ -117,3 +117,12 @@ class A(c.void_p):
|
||||
|
||||
a = A(0)
|
||||
assert repr(a).startswith('<void* at')
|
||||
|
||||
if 1:
|
||||
class TrueClass:
|
||||
pass
|
||||
else:
|
||||
class FalseClass:
|
||||
pass
|
||||
|
||||
assert TrueClass
|
||||
|
Loading…
x
Reference in New Issue
Block a user