1 /* vifm 2 * Copyright (C) 2012 xaizek. 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 17 */ 18 19 #ifndef VIFM__ENGINE__PARSING_H__ 20 #define VIFM__ENGINE__PARSING_H__ 21 22 #include "var.h" 23 24 /* An enumeration of possible parsing errors. */ 25 typedef enum 26 { 27 PE_NO_ERROR, /* No error occurred. */ 28 PE_INVALID_EXPRESSION, /* Wrong expression construct. */ 29 PE_INVALID_SUBEXPRESSION, /* Wrong subexpression construct. */ 30 PE_MISSING_QUOTE, /* Missing closing quote. */ 31 PE_MISSING_PAREN, /* Missing closing paren. */ 32 PE_INTERNAL, /* Internal error (e.g. not enough memory). */ 33 } 34 ParsingErrors; 35 36 /* A type of function that will be used to resolve environment variable 37 * value. If variable doesn't exist the function should return an empty 38 * string. The function should not allocate new string. */ 39 typedef const char * (*getenv_func)(const char *envname); 40 41 /* A type of function that will be used to print error messages. */ 42 typedef void (*print_error_func)(const char msg[]); 43 44 /* Can be called several times. getenv_f can be NULL. */ 45 void init_parser(getenv_func getenv_f); 46 47 /* Returns logical (e.g. beginning of wrong expression) position in a string, 48 * where parser has stopped. */ 49 const char * get_last_position(void); 50 51 /* Returns actual position in a string, where parser has stopped. */ 52 const char * get_last_parsed_char(void); 53 54 /* Performs parsing. After calling this function get_last_position() will 55 * return useful information. Returns error code and puts result of expression 56 * evaluation in the result parameter. */ 57 ParsingErrors parse(const char input[], int interactive, var_t *result); 58 59 /* Returns evaluation result, may be used to get value on error. */ 60 var_t get_parsing_result(void); 61 62 /* Returns non-zero if previously read token was whitespace. */ 63 int is_prev_token_whitespace(void); 64 65 /* Appends error message with details to the error stream. */ 66 void report_parsing_error(ParsingErrors error); 67 68 #endif /* VIFM__ENGINE__PARSING_H__ */ 69 70 /* vim: set tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab cinoptions-=(0 : */ 71 /* vim: set cinoptions+=t0 filetype=c : */ 72