mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
add inline block
This commit is contained in:
parent
051560279d
commit
63a00d0faf
@ -690,6 +690,10 @@ __LISTCOMP:
|
|||||||
void compile_block_body(CompilerAction action=nullptr) {
|
void compile_block_body(CompilerAction action=nullptr) {
|
||||||
if(action == nullptr) action = &Compiler::compile_stmt;
|
if(action == nullptr) action = &Compiler::compile_stmt;
|
||||||
consume(TK(":"));
|
consume(TK(":"));
|
||||||
|
if(peek()!=TK("@eol") && peek()!=TK("@eof")){
|
||||||
|
(this->*action)(); // inline block
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!match_newlines(mode()==REPL_MODE)){
|
if(!match_newlines(mode()==REPL_MODE)){
|
||||||
SyntaxError("expected a new line after ':'");
|
SyntaxError("expected a new line after ':'");
|
||||||
}
|
}
|
||||||
@ -1009,7 +1013,8 @@ __LISTCOMP:
|
|||||||
consume(TK("@id"));
|
consume(TK("@id"));
|
||||||
func->name = parser->prev.str();
|
func->name = parser->prev.str();
|
||||||
|
|
||||||
if (match(TK("(")) && !match(TK(")"))) {
|
consume(TK("("));
|
||||||
|
if (!match(TK(")"))) {
|
||||||
_compile_f_args(func, true);
|
_compile_f_args(func, true);
|
||||||
consume(TK(")"));
|
consume(TK(")"));
|
||||||
}
|
}
|
||||||
|
20
tests/_inline_blocks.py
Normal file
20
tests/_inline_blocks.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
class A: pass
|
||||||
|
class B: pass
|
||||||
|
a = A()
|
||||||
|
assert type(a) is A
|
||||||
|
|
||||||
|
x = 0
|
||||||
|
if x==0: x=1
|
||||||
|
assert x==1
|
||||||
|
|
||||||
|
def f(x, y): return x+y
|
||||||
|
assert f(1,2)==3
|
||||||
|
|
||||||
|
c = 1
|
||||||
|
if c==0: x=1
|
||||||
|
elif c==1: x=2
|
||||||
|
else: x=3
|
||||||
|
assert x==2
|
||||||
|
|
||||||
|
def f1(x): return x+1
|
||||||
|
assert f1(1)==2
|
Loading…
x
Reference in New Issue
Block a user