00001
00005 #ifndef FISH_PARSER_H
00006 #define FISH_PARSER_H
00007
00008 #include <wchar.h>
00009
00010 #include "proc.h"
00011 #include "util.h"
00012 #include "parser.h"
00013 #include "event.h"
00014
00015 #define PARSER_TEST_ERROR 1
00016 #define PARSER_TEST_INCOMPLETE 2
00017
00021 typedef struct event_block
00022 {
00031 int type;
00032
00036 struct event_block *next;
00037 }
00038 event_block_t;
00039
00040
00041
00045 typedef struct block
00046 {
00047 int type;
00048 int skip;
00049 int tok_pos;
00050 int had_command;
00055 int loop_status;
00056
00060 job_t *job;
00061
00065 void *data;
00066
00070 union
00071 {
00072 int while_state;
00073 wchar_t *for_variable;
00074 int if_state;
00075 wchar_t *switch_value;
00076 const wchar_t *source_dest;
00077 event_t *event;
00078 wchar_t *function_call_name;
00079 } param1;
00080
00084 union
00085 {
00086 array_list_t for_vars;
00087 int switch_taken;
00088 process_t *function_call_process;
00089 } param2;
00090
00091
00095 const wchar_t *src_filename;
00096
00100 int src_lineno;
00101
00105 event_block_t *first_event_block;
00106
00110 struct block *outer;
00111 } block_t;
00112
00116 enum block_type
00117 {
00118 WHILE,
00119 FOR,
00120 IF,
00121 FUNCTION_DEF,
00122 FUNCTION_CALL,
00123 FUNCTION_CALL_NO_SHADOW,
00124 SWITCH,
00125 FAKE,
00126 SUBST,
00127 TOP,
00128 BEGIN,
00129 SOURCE,
00130 EVENT,
00131 BREAKPOINT,
00132 }
00133 ;
00134
00138 enum loop_status
00139 {
00140 LOOP_NORMAL,
00141 LOOP_BREAK,
00142 LOOP_CONTINUE,
00143 };
00144
00145
00149 enum while_status
00150 {
00151 WHILE_TEST_FIRST,
00152 WHILE_TEST_AGAIN,
00153 WHILE_TESTED,
00154 }
00155 ;
00156
00157
00158
00162 enum parser_error
00163 {
00167 NO_ERR=0,
00171 SYNTAX_ERROR,
00175 EVAL_ERROR,
00179 CMDSUBST_ERROR,
00180 }
00181 ;
00182
00184 extern block_t *current_block;
00185
00187 extern event_block_t *global_event_block;
00188
00192 extern io_data_t *block_io;
00193
00203 int eval( const wchar_t *cmd, io_data_t *io, int block_type );
00204
00212 int eval_args( const wchar_t *line,
00213 array_list_t *output );
00214
00222 void error( int ec, int p, const wchar_t *str, ... );
00223
00224
00231 wchar_t *parser_current_line();
00232
00236 int parser_get_lineno();
00237
00241 int parser_get_pos();
00242
00246 int parser_get_job_pos();
00247
00251 void parser_set_pos( int p);
00252
00256 const wchar_t *parser_get_buffer();
00257
00261 void parser_push_block( int type);
00262
00266 void parser_pop_block();
00267
00271 const wchar_t *parser_get_block_desc( int block );
00272
00273
00286 int parser_test( const wchar_t * buff, int *block_level, string_buffer_t *out, const wchar_t *prefix );
00287
00294 int parser_test_args( const wchar_t * buff, string_buffer_t *out, const wchar_t *prefix );
00295
00301 void parser_forbid_function( wchar_t *function );
00305 void parser_allow_function();
00306
00310 void parser_init();
00311
00315 void parser_destroy();
00316
00323 int parser_is_help( wchar_t *s, int min_match );
00324
00330 const wchar_t *parser_current_filename();
00331
00335 void parser_stack_trace( block_t *b, string_buffer_t *buff);
00336
00337 int parser_get_block_type( const wchar_t *cmd );
00338 const wchar_t *parser_get_block_command( int type );
00339
00340
00341 #endif