How to properly feed lexer from file?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Posts: 4
Joined: Fri Aug 30, 2019 8:34 am

How to properly feed lexer from file?

Post by alidayvn » Wed Oct 09, 2019 9:51 am

on my nrf52832 we have a tiny littlefs file system of 100kB size. My goal is to upload python files and execute them using

Therefore I figured out I need to implement mp_lexer_new_from_file(const char* filename) function.
But: since I have constrained RAM resources I cannot create a, lets say 8kB buffer with the content of the file in order to pass it to mp_lexer_new_from_str_len.
Then I looked into lexer.h and saw the mp_lexer_new function that receives a reader (stream source) as 2nd argument.
Now, you might guess where this topic is going to I'd like to know whether and more specifically how I can pass the file content byte by byte to feed the lexer? Are there any examples I have missed?
Thanks in advance

Posts: 362
Joined: Thu Apr 24, 2014 9:13 am

Re: How to properly feed lexer from file?

Post by stijn » Wed Oct 09, 2019 10:19 am

The mp_lexer_new_from_file() function does that exactly I think, and in pyexec.c you can see how it gets used and I assume you can just use pyexec_file()

Post Reply