diff options
author | Tavian Barnes <tavianator@gmail.com> | 2010-02-09 21:03:10 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2010-02-09 21:03:10 -0500 |
commit | 7d3a45468b07356d6ca2863b59163b165a83a0f0 (patch) | |
tree | 45e75628a775c41384f138b4b43d833db587afc9 /dimension/grammar.epilogue | |
parent | 06b653e922cd36006f0c86b7e015109e5c0b8923 (diff) | |
download | dimension-7d3a45468b07356d6ca2863b59163b165a83a0f0.tar.xz |
Get rid of fmemopen() hack.
Diffstat (limited to 'dimension/grammar.epilogue')
-rw-r--r-- | dimension/grammar.epilogue | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/dimension/grammar.epilogue b/dimension/grammar.epilogue index e8760c7..ecb910a 100644 --- a/dimension/grammar.epilogue +++ b/dimension/grammar.epilogue @@ -47,6 +47,36 @@ dmnsn_parse(FILE *file, dmnsn_symbol_table *symtable) return astree; } +dmnsn_astree * +dmnsn_parse_string(const char *str, dmnsn_symbol_table *symtable) +{ + const char *filename; + dmnsn_astnode *fnode = dmnsn_find_symbol(symtable, "__file__"); + if (fnode && fnode->type == DMNSN_AST_STRING) { + filename = fnode->ptr; + } else { + filename = "<string>"; + dmnsn_declare_symbol(symtable, "__file__", dmnsn_new_ast_string(filename)); + } + + void *scanner; + dmnsn_astree *astree = dmnsn_new_array(sizeof(dmnsn_astnode)); + + dmnsn_yylex_init(&scanner); + dmnsn_yyset_extra(NULL, scanner); + + void *buffer = dmnsn_yy_make_string_buffer(str, scanner); + dmnsn_yy_push_buffer(buffer, scanner); + + if (yyparse(filename, scanner, astree, symtable) != 0) { + dmnsn_delete_astree(astree); + astree = NULL; + } + + dmnsn_yylex_destroy(scanner); + return astree; +} + const char * dmnsn_token_string(dmnsn_token_type token_type) { |