Instead of passing a flag through the parser and tokenizer for telling the input source if we need further input or not, we steal a trick from Lua: In the REPL, we just continue to read lines and append them to the input, until the input was loaded with no "unexpected EOF" error. After all, when we didn't expect an EOF is exactly the scenario, when we need more input. Doing things this way simplifies a bunch of places and lets us remove the ugly source_reader and iterative_runner concepts. To allow the REPL to see the error that happened during loading required some smaller refactorings, but those were honestly for the better anyway. I also decided to get rid of the token_source concept, the parser now gets the tokenizer directly. This also made things a bit simpler, also I want to soon-ish implement string interpolation, and for that the parser needs to do more with the tokenizer than just reading the next token. One last thing: This also cleans up the web playground and makes the playground and REPL share a bunch of code. Nice!
21 lines
408 B
C
21 lines
408 B
C
#ifndef APFL_REPL_H
|
|
#define APFL_REPL_H
|
|
|
|
#include "apfl.h"
|
|
|
|
enum repl_result {
|
|
REPL_OK = 0,
|
|
REPL_MORE_INPUT = 1,
|
|
REPL_ERR = 2,
|
|
REPL_FATAL = 3,
|
|
};
|
|
|
|
typedef struct repl_data *repl;
|
|
|
|
repl repl_new(struct apfl_allocator);
|
|
void repl_set_w_out(repl, struct apfl_io_writer);
|
|
void repl_set_w_err(repl, struct apfl_io_writer);
|
|
enum repl_result repl_run(repl, char *);
|
|
void repl_destroy(repl);
|
|
|
|
#endif
|