File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
src/main/java/com/annimon/ownlang/utils Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change 1010import com .annimon .ownlang .parser .Lexer ;
1111import com .annimon .ownlang .parser .Parser ;
1212import com .annimon .ownlang .parser .Token ;
13+ import com .annimon .ownlang .parser .TokenType ;
1314import com .annimon .ownlang .parser .ast .BlockStatement ;
1415import com .annimon .ownlang .parser .ast .Statement ;
1516import com .annimon .ownlang .parser .visitors .PrintVisitor ;
@@ -35,6 +36,8 @@ public final class Repl {
3536 RESET = ":reset" ,
3637 EXIT = ":exit" ;
3738
39+ private static final Token PRINTLN_TOKEN = new Token (TokenType .PRINTLN , "" , 0 , 0 );
40+
3841 public static void main (String [] args ) {
3942 System .out .println ("Welcome to OwnLang " + Main .VERSION + " REPL" );
4043 printHelp (false );
@@ -73,7 +76,15 @@ public static void main(String[] args) {
7376 final Parser parser = new Parser (tokens );
7477 program = parser .parse ();
7578 if (parser .getParseErrors ().hasErrors ()) {
76- continue ;
79+ // Try to print value
80+ List <Token > tokens2 = new ArrayList <>();
81+ tokens2 .add (PRINTLN_TOKEN );
82+ tokens2 .addAll (tokens );
83+ Parser parser2 = new Parser (tokens2 );
84+ program = parser2 .parse ();
85+ if (parser2 .getParseErrors ().hasErrors ()) {
86+ continue ;
87+ }
7788 }
7889 program .execute ();
7990 } catch (LexerException lex ) {
You can’t perform that action at this time.
0 commit comments