diff options
Diffstat (limited to 'py/lexerfile.c')
-rw-r--r-- | py/lexerfile.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/py/lexerfile.c b/py/lexerfile.c new file mode 100644 index 0000000000..74bb5a061a --- /dev/null +++ b/py/lexerfile.c @@ -0,0 +1,23 @@ +#include <stdint.h> +#include <stdio.h> +#include <unistd.h> +#include <fcntl.h> + +#include "misc.h" +#include "lexer.h" + +py_lexer_t *py_lexer_from_file(const char *filename) { + // TODO abstract away file functionality + int fd = open(filename, O_RDONLY); + if (fd < 0) { + printf("cannot open file %s\n", filename); + return NULL; + } + uint size = lseek(fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); + char *data = m_new(char, size); + read(fd, data, size); + close(fd); + + return py_lexer_from_str_len(filename, data, size, true); +} |