"expected end of input at end of input" with mpc_parse_file and mpc_parse_contents
Closed this issue · 6 comments
I have the following extremely stripped down C code which fails to work when I try to parse the whole file (while it works fine line-by-line):
$ ./mpc-parser test.s
test.s:2:1: error: expected one of '0123456789', newline or end of input at end of input
$ cat test.s
0
$ hexdump test.s
0000000 30 0a
0000002
I'm not sure what's going on (but "expecting end of input at end of input" is surely suspicious), since the parser is defined with MPCA_LANG_DEFAULT
, so it should be whitespace insensitive. Also, I tried the same using mpc_parse_contents
but got the same result. Maybe I am missing something, would be grateful to know what.
Parser code:
#include <stdio.h>
#include <stdlib.h>
#include "mpc.h"
int main(int argc, char *argv[])
{
mpc_parser_t *Digit = mpc_new("digit");
mpc_parser_t *Program = mpc_new("program");
mpca_lang(MPCA_LANG_DEFAULT,
" digit : /[0-9]/ ;"
" program : /^/ <digit>+ /$/ ;"
, Digit, Program, NULL);
mpc_result_t r;
if (argc > 1) {
FILE *f = fopen(argv[1], "rb");
if (f == NULL) {
perror(argv[1]);
exit(EXIT_FAILURE);
}
if (mpc_parse_file(argv[1], f, Program, &r)) {
mpc_ast_print(r.output);
mpc_ast_delete(r.output);
} else {
mpc_err_print(r.error);
mpc_err_delete(r.error);
}
fclose(f);
}
mpc_cleanup(2, Digit, Program);
return 0;
}
Thanks I'll try to look into this this weekend looks like it is most likely a bug since I recently updated the end of input behavior.
Cool! Thank you! I can try to debug it myself, I just wasn't sure that I am setting up the parser correctly, so decided to double check that I am not doing anything silly before trying to fix it :)
Hi @sphynx , thanks for the great report. I think I should have fixed this issue in the latest commit. Will you be able to verify?
And apologies for the slow reply!
Hi @orangeduck, yes, it works well now, thanks for your work on the fix! I've tested it on that simple example and also on my original parser.
Thanks!