blueloveTH 3 лет назад
Родитель
Сommit
e310239b05
4 измененных файлов с 23 добавлено и 6 удалено
  1. 4 3
      src/compiler.h
  2. 3 0
      src/parser.h
  3. 4 3
      src/pocketpy.h
  4. 12 0
      tests/6.py

+ 4 - 3
src/compiler.h

@@ -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);
     }

+ 3 - 0
src/parser.h

@@ -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()){

+ 4 - 3
src/pocketpy.h

@@ -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 - 0
tests/6.py

@@ -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.')