mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 19:40:18 +00:00
fix a bug
This commit is contained in:
parent
542ffccd23
commit
e310239b05
@ -176,6 +176,8 @@ public:
|
|||||||
parser->current = parser->nextToken();
|
parser->current = parser->nextToken();
|
||||||
|
|
||||||
//_Str _info = parser->current.info(); printf("%s\n", (const char*)_info);
|
//_Str _info = parser->current.info(); printf("%s\n", (const char*)_info);
|
||||||
|
if(parser->current.type == TK("(")) parser->ignoreIndent += 1;
|
||||||
|
if(parser->current.type == TK(")")) parser->ignoreIndent -= 1;
|
||||||
|
|
||||||
while (parser->peekChar() != '\0') {
|
while (parser->peekChar() != '\0') {
|
||||||
parser->token_start = parser->current_char;
|
parser->token_start = parser->current_char;
|
||||||
@ -520,13 +522,12 @@ __LISTCOMP:
|
|||||||
void exprCall() {
|
void exprCall() {
|
||||||
int ARGC = 0;
|
int ARGC = 0;
|
||||||
do {
|
do {
|
||||||
matchNewLines();
|
matchNewLines(mode()==SINGLE_MODE);
|
||||||
if (peek() == TK(")")) break;
|
if (peek() == TK(")")) break;
|
||||||
EXPR();
|
EXPR();
|
||||||
ARGC++;
|
ARGC++;
|
||||||
matchNewLines();
|
matchNewLines(mode()==SINGLE_MODE);
|
||||||
} while (match(TK(",")));
|
} while (match(TK(",")));
|
||||||
matchNewLines();
|
|
||||||
consume(TK(")"));
|
consume(TK(")"));
|
||||||
emitCode(OP_CALL, ARGC);
|
emitCode(OP_CALL, ARGC);
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,8 @@ struct Parser {
|
|||||||
std::queue<Token> nexts;
|
std::queue<Token> nexts;
|
||||||
std::stack<int> indents;
|
std::stack<int> indents;
|
||||||
|
|
||||||
|
int ignoreIndent = 0;
|
||||||
|
|
||||||
Token nextToken(){
|
Token nextToken(){
|
||||||
if(nexts.empty()) return makeErrToken();
|
if(nexts.empty()) return makeErrToken();
|
||||||
Token t = nexts.front();
|
Token t = nexts.front();
|
||||||
@ -137,6 +139,7 @@ struct Parser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool eatIndentation(){
|
bool eatIndentation(){
|
||||||
|
if(ignoreIndent > 0) return true;
|
||||||
int spaces = eatSpaces();
|
int spaces = eatSpaces();
|
||||||
// https://docs.python.org/3/reference/lexical_analysis.html#indentation
|
// https://docs.python.org/3/reference/lexical_analysis.html#indentation
|
||||||
if(spaces > indents.top()){
|
if(spaces > indents.top()){
|
||||||
|
@ -723,10 +723,11 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__EXPORT
|
__EXPORT
|
||||||
void pkpy_tvm_start_exec(ThreadedVM* vm, const char* source){
|
bool pkpy_tvm_start_exec(ThreadedVM* vm, const char* source){
|
||||||
_Code code = compile(vm, source, "main.py");
|
_Code code = compile(vm, source, "main.py");
|
||||||
if(code == nullptr) return;
|
if(code == nullptr) return false;
|
||||||
return vm->startExec(code);
|
vm->startExec(code);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
__EXPORT
|
__EXPORT
|
||||||
|
12
tests/6.py
Normal file
12
tests/6.py
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import ink
|
||||||
|
|
||||||
|
print('Once upon a time...')
|
||||||
|
|
||||||
|
index, val = ink.choice(
|
||||||
|
'There were two choices.',
|
||||||
|
'There were four lines of content.'
|
||||||
|
)
|
||||||
|
|
||||||
|
print(f'You selected {index}')
|
||||||
|
|
||||||
|
print('They lived happily ever after.')
|
Loading…
x
Reference in New Issue
Block a user