Page 1 of 1

MP_PARSE_SINGLE_INPUT vs MP_PARSE_FILE_INPUT

Posted: Fri Dec 15, 2017 10:13 pm
by jickster
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