Last active
December 24, 2015 10:12
-
-
Save yihuang/0af450e858daf2d99138 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ echo 'sdf>sdf>' | ./a.out | |
text|regex:1:1 'sdf>sdf> | |
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "mpc.h" | |
mpc_parser_t* gen_parser() { | |
mpc_parser_t* Entity = mpc_new("entity"); | |
mpc_parser_t* Text = mpc_new("text"); | |
mpc_parser_t* All = mpc_new("all"); | |
mpc_err_t* err = mpca_lang(MPCA_LANG_WHITESPACE_SENSITIVE, | |
"entity : /&[a-zA-Z0-9_#]+;/ ;\n" | |
"text : /.+/ ;\n" | |
"all : (<entity> | <text>)* ;\n" | |
, Entity, Text, All, NULL); | |
if (err != NULL) { | |
mpc_err_print(err); | |
mpc_err_delete(err); | |
return NULL; | |
} | |
return All; | |
} | |
int main() { | |
mpc_result_t r; | |
if (mpc_parse_pipe("stdin", stdin, gen_parser(), &r)) { | |
mpc_ast_print((mpc_ast_t*)r.output); | |
mpc_ast_delete((mpc_ast_t*)r.output); | |
} else { | |
mpc_err_print(r.error); | |
mpc_err_delete(r.error); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment