MP_PARSE_SINGLE_INPUT vs MP_PARSE_FILE_INPUT

C programming, build, interpreter/VM.
Target audience: MicroPython Developers.
Post Reply
jickster
Posts: 629
Joined: Thu Sep 07, 2017 8:57 pm

MP_PARSE_SINGLE_INPUT vs MP_PARSE_FILE_INPUT

Post by jickster » Fri Dec 15, 2017 10:13 pm

What is the exact difference between these two? The names would seem to make it obvious but I would to be sure.

Code: Select all

int main(int argc, char **argv) {
    mp_init();
    do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_SINGLE_INPUT);
    do_str("for i in range(10):\n  print(i)", MP_PARSE_FILE_INPUT);
    mp_deinit();
    return 0;
}
Does a MP_PARSE_SINGLE_INPUT only work on single-line statements?

Can I technically use MP_PARSE_FILE_INPUT even if I have a single-line statement (i.e. is it a superset)? If so, what's the point of having MP_PARSE_SINGLE_INPUT ?

Code: Select all

do_str("print('hello world!', list(x+1 for x in range(10)), end='eol\\n')", MP_PARSE_FILE_INPUT );
What happens if I pass in the wrong input_kind as below?

Code: Select all

do_str("for i in range(10):\n  print(i)", MP_PARSE_SINGLE_INPUT);
There is no documentation on this

https://docs.micropython.org/en/latest/ ... ea=default

Post Reply