blueloveTH il y a 3 ans
Parent
commit
e310239b05
4 fichiers modifiés avec 23 ajouts et 6 suppressions
  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();
         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);
     }
     }

+ 3 - 0
src/parser.h

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

+ 4 - 3
src/pocketpy.h

@@ -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;
-        return vm->startExec(code);
+        if(code == nullptr) return false;
+        vm->startExec(code);
+        return true;
     }
     }
 
 
     __EXPORT
     __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.')