1 /* 2 Copyright 2002-2004 John Plevyak, All Rights Reserved 3 */ 4 #ifndef _dparse_H_ 5 #define _dparse_H_ 6 7 #include <stdlib.h> 8 #if defined(__cplusplus) 9 extern "C" { 10 #endif 11 #include "dparse_tables.h" 12 #include "dsymtab.h" 13 14 struct D_Parser; 15 struct D_ParserTables; 16 struct D_Scope; 17 struct D_ParseNode; 18 19 typedef void *d_voidp; 20 #ifndef D_ParseNode_User 21 #define D_ParseNode_User d_voidp 22 #endif 23 #ifndef D_ParseNode_Globals 24 #define D_ParseNode_Globals void 25 #endif 26 27 typedef void (*D_SyntaxErrorFn)(struct D_Parser *); 28 typedef struct D_ParseNode *(*D_AmbiguityFn)(struct D_Parser *, int n, struct D_ParseNode **v); 29 typedef void (*D_FreeNodeFn)(struct D_ParseNode *d); 30 31 typedef struct D_Parser { 32 D_ParseNode_Globals *initial_globals; /* global values */ 33 D_WhiteSpaceFn initial_white_space_fn; 34 struct D_Scope *initial_scope; 35 D_SyntaxErrorFn syntax_error_fn; 36 D_AmbiguityFn ambiguity_fn; 37 D_FreeNodeFn free_node_fn; 38 d_loc_t loc; /* initial location, set on error */ 39 int start_state; /* do not move or change without fixing copy_user_configurables() */ 40 /* user configurables */ 41 int sizeof_user_parse_node; 42 int save_parse_tree; 43 int dont_compare_stacks; 44 int dont_fixup_internal_productions; 45 int fixup_EBNF_productions; 46 int dont_merge_epsilon_trees; 47 int dont_use_height_for_disambiguation; 48 int dont_use_greediness_for_disambiguation; 49 int commit_actions_interval; /* 0 is immediate */ 50 int error_recovery; 51 int partial_parses; 52 /* parse results */ 53 int syntax_errors; /* do not move or change without fixing copy_user_configurables() */ 54 } D_Parser; 55 56 typedef struct D_ParseNode { 57 int symbol; 58 d_loc_t start_loc; 59 char *end; 60 char *end_skip; 61 struct D_Scope *scope; 62 D_WhiteSpaceFn white_space; 63 D_ParseNode_Globals *globals; 64 D_ParseNode_User user; 65 } D_ParseNode; 66 67 D_Parser *new_D_Parser(struct D_ParserTables *t, int sizeof_ParseNode_User); 68 void free_D_Parser(D_Parser *p); 69 D_ParseNode *dparse(D_Parser *p, char *buf, int buf_len); 70 void free_D_ParseNode(D_Parser *p, D_ParseNode *pn); 71 void free_D_ParseTreeBelow(D_Parser *p, D_ParseNode *pn); 72 73 int d_get_number_of_children(D_ParseNode *pn); 74 D_ParseNode *d_get_child(D_ParseNode *pn, int child); 75 D_ParseNode *d_find_in_tree(D_ParseNode *pn, int symbol); 76 char *d_ws_before(D_Parser *p, D_ParseNode *pn); /* points BEFORE leading ws */ 77 char *d_ws_after(D_Parser *p, D_ParseNode *pn); /* points AFTER trailing ws */ 78 79 void d_pass(D_Parser *p, D_ParseNode *pn, int pass_number); 80 81 int resolve_amb_greedy(D_Parser *dp, int n, D_ParseNode **v); 82 83 char *d_dup_pathname_str(const char *str); 84 85 #if defined(__cplusplus) 86 } 87 #endif 88 89 #endif 90