UGDK
|
00001 00002 #ifndef UGDK_UTIL_GDD_PARSERUTILITY_H_ 00003 #define UGDK_UTIL_GDD_PARSERUTILITY_H_ 00004 00005 // Does nothing. 00006 #define NO_MSG {} 00007 00008 // Asserts 'test'. If false, executes 'print_err' and returns 'err_value'. 00009 #define ASSERT_PARSE(test, print_err, err_value) \ 00010 do if (!(test)) { \ 00011 print_err; \ 00012 return err_value; \ 00013 } while(0) 00014 00015 // Checks if 'token' is a valid character for the beginning of a field name. 00016 #define VALID_NAME_BEGIN(token) ((isalnum((token))) || ((token) == '_')) 00017 00018 #define ERR_LOCATION(read) \ 00019 fprintf(stderr, "%s:%u: ", read.file_path().c_str(), (unsigned)(read.line())); 00020 00021 // Prints a bad name beginning error message. 00022 #define ERR_BAD_NAME_BEGIN(read) \ 00023 fprintf(stderr, \ 00024 "%s:%u: Names and types must begin with an alphanumeric character or '_'.", \ 00025 read.file_path().c_str(), \ 00026 (unsigned)(read.line())) 00027 00028 // Checks if 'token' is a valid field name character. 00029 #define VALID_NAME_TOKEN(token) ((isalnum((token))) || ((token) == '_')) 00030 00031 // Checks if 'token' is a valid value character. 00032 #define VALID_VALUE_TOKEN(token) ((isalnum((token))) || ((token) == '_') || ((token) == '.') || ((token) == '-')) 00033 00034 // Prints an empty field error, where the field is of type 'type'. 00035 #define ERR_EMPTY_FIELD(read, type) \ 00036 fprintf(stderr, \ 00037 "%s:%u: syntax error: %s name must not be empty.\n", \ 00038 read.file_path().c_str(), \ 00039 (unsigned)(read.line()), \ 00040 type) 00041 00042 #endif /* UGDK_UTIL_GDD_PARSERUTILITY_H_ */