UGDK  0.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
parserutility.h
Go to the documentation of this file.
1 
2 #ifndef UGDK_UTIL_GDD_PARSERUTILITY_H_
3 #define UGDK_UTIL_GDD_PARSERUTILITY_H_
4 
5 // Does nothing.
6 #define NO_MSG {}
7 
8 // Asserts 'test'. If false, executes 'print_err' and returns 'err_value'.
9 #define ASSERT_PARSE(test, print_err, err_value) \
10  do if (!(test)) { \
11  print_err; \
12  return err_value; \
13  } while(0)
14 
15 // Checks if 'token' is a valid character for the beginning of a field name.
16 #define VALID_NAME_BEGIN(token) ((isalnum((token))) || ((token) == '_'))
17 
18 #define ERR_LOCATION(read) \
19  fprintf(stderr, "%s:%u: ", read.file_path().c_str(), (unsigned)(read.line()));
20 
21 // Prints a bad name beginning error message.
22 #define ERR_BAD_NAME_BEGIN(read) \
23  fprintf(stderr, \
24  "%s:%u: Names and types must begin with an alphanumeric character or '_'.", \
25  read.file_path().c_str(), \
26  (unsigned)(read.line()))
27 
28 // Checks if 'token' is a valid field name character.
29 #define VALID_NAME_TOKEN(token) ((isalnum((token))) || ((token) == '_'))
30 
31 // Checks if 'token' is a valid value character.
32 #define VALID_VALUE_TOKEN(token) ((isalnum((token))) || ((token) == '_') || ((token) == '.') || ((token) == '-'))
33 
34 // Prints an empty field error, where the field is of type 'type'.
35 #define ERR_EMPTY_FIELD(read, type) \
36  fprintf(stderr, \
37  "%s:%u: syntax error: %s name must not be empty.\n", \
38  read.file_path().c_str(), \
39  (unsigned)(read.line()), \
40  type)
41 
42 #endif /* UGDK_UTIL_GDD_PARSERUTILITY_H_ */