1010#include "parse.h"
1111#include "compile.h"
1212#include "runtime.h"
13+ #include "repl.h"
1314
1415#include <readline/readline.h>
1516
16- bool str_startswith_word (const char * str , const char * head ) {
17- int i ;
18- for (i = 0 ; str [i ] && head [i ]; i ++ ) {
19- if (str [i ] != head [i ]) {
20- return false;
21- }
22- }
23- return head [i ] == '\0' && (str [i ] == '\0' || !g_unichar_isalpha (str [i ]));
24- }
25-
26- bool is_compound_stmt (const char * line ) {
27- // TODO also "compound" if unmatched open bracket
28- return
29- str_startswith_word (line , "if" )
30- || str_startswith_word (line , "while" )
31- || str_startswith_word (line , "for" )
32- || str_startswith_word (line , "true" )
33- || str_startswith_word (line , "with" )
34- || str_startswith_word (line , "def" )
35- || str_startswith_word (line , "class" )
36- || str_startswith_word (line , "@" );
37- }
38-
3917char * str_join (const char * s1 , int sep_char , const char * s2 ) {
4018 int l1 = strlen (s1 );
4119 int l2 = strlen (s2 );
@@ -46,6 +24,7 @@ char *str_join(const char *s1, int sep_char, const char *s2) {
4624 l1 += 1 ;
4725 }
4826 memcpy (s + l1 , s2 , l2 );
27+ s [l1 + l2 ] = 0 ;
4928 return s ;
5029}
5130
@@ -56,7 +35,7 @@ void do_repl() {
5635 // EOF
5736 return ;
5837 }
59- if (is_compound_stmt (line )) {
38+ if (py_repl_is_compound_stmt (line )) {
6039 for (;;) {
6140 char * line2 = readline ("... " );
6241 if (line2 == NULL || strlen (line2 ) == 0 ) {
0 commit comments