summaryrefslogtreecommitdiffstats
path: root/dimension/grammar.epilogue
diff options
context:
space:
mode:
Diffstat (limited to 'dimension/grammar.epilogue')
-rw-r--r--dimension/grammar.epilogue30
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)
{