fix a bug

This commit is contained in:
blueloveTH 2022-11-16 01:12:50 +08:00
parent 542ffccd23
commit e310239b05
4 changed files with 23 additions and 6 deletions

View File

@ -176,6 +176,8 @@ public:
parser->current = parser->nextToken();
//_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') {
parser->token_start = parser->current_char;
@ -520,13 +522,12 @@ __LISTCOMP:
void exprCall() {
int ARGC = 0;
do {
matchNewLines();
matchNewLines(mode()==SINGLE_MODE);
if (peek() == TK(")")) break;
EXPR();
ARGC++;
matchNewLines();
matchNewLines(mode()==SINGLE_MODE);
} while (match(TK(",")));
matchNewLines();
consume(TK(")"));
emitCode(OP_CALL, ARGC);
}

View File

@ -103,6 +103,8 @@ struct Parser {
std::queue<Token> nexts;
std::stack<int> indents;
int ignoreIndent = 0;
Token nextToken(){
if(nexts.empty()) return makeErrToken();
Token t = nexts.front();
@ -137,6 +139,7 @@ struct Parser {
}
bool eatIndentation(){
if(ignoreIndent > 0) return true;
int spaces = eatSpaces();
// https://docs.python.org/3/reference/lexical_analysis.html#indentation
if(spaces > indents.top()){

View File

@ -723,10 +723,11 @@ extern "C" {
}
__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");
if(code == nullptr) return;
return vm->startExec(code);
if(code == nullptr) return false;
vm->startExec(code);
return true;
}
__EXPORT

12
tests/6.py Normal file
View 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.')