VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkParseString.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00015 /*------------------------------------------------------------------------- 00016 Copyright (c) 2012 David Gobbi. 00017 00018 Contributed to the VisualizationToolkit by the author in April 2012 00019 under the terms of the Visualization Toolkit 2008 copyright. 00020 -------------------------------------------------------------------------*/ 00021 00043 #ifndef VTK_PARSE_STRING_H 00044 #define VTK_PARSE_STRING_H 00045 00046 #include <stddef.h> 00047 00048 #ifdef __cplusplus 00049 extern "C" { 00050 #endif 00051 00055 typedef enum _parse_char_type 00056 { 00057 CPRE_ID = 0x01, /* A-Z a-z and _ */ 00058 CPRE_DIGIT = 0x02, /* 0-9 */ 00059 CPRE_IDGIT = 0x03, /* 0-9 A-Z a-z and _ */ 00060 CPRE_HEX = 0x04, /* 0-9A-Fa-f */ 00061 CPRE_EXP = 0x08, /* EPep (exponents for floats) */ 00062 CPRE_SIGN = 0x10, /* +- (sign for floats) */ 00063 CPRE_QUOTE = 0x20, /* " and ' */ 00064 CPRE_HSPACE = 0x40, /* space, tab, carriage return */ 00065 CPRE_VSPACE = 0x80, /* newline, vertical tab, form feed */ 00066 CPRE_WHITE = 0xC0, /* all whitespace characters */ 00067 } parse_char_type; 00068 00072 extern unsigned char parse_charbits[256]; 00073 00077 #define vtkParse_CharType(c, bits) \ 00078 ((parse_charbits[(unsigned char)(c)] & (bits)) != 0) 00079 00086 typedef enum _parse_space_t 00087 { 00088 WS_DEFAULT = CPRE_WHITE, /* skip all whitespace */ 00089 WS_PREPROC = CPRE_HSPACE, /* skip horizontal whitespace only */ 00090 WS_COMMENT = (CPRE_WHITE | 0x100), /* comments as tokens */ 00091 } parse_space_t; 00092 00096 typedef enum _preproc_token_t 00097 { 00098 TOK_OTHER = 257, 00099 TOK_ID, /* any id */ 00100 TOK_CHAR, /* char literal */ 00101 TOK_STRING, /* string literal */ 00102 TOK_NUMBER, /* any numeric literal */ 00103 TOK_COMMENT, /* C or C++ comment */ 00104 TOK_DBLHASH, /* ## */ 00105 TOK_SCOPE, /* :: */ 00106 TOK_INCR, /* ++ */ 00107 TOK_DECR, /* -- */ 00108 TOK_RSHIFT, /* >> */ 00109 TOK_LSHIFT, /* << */ 00110 TOK_AND, /* && */ 00111 TOK_OR, /* || */ 00112 TOK_EQ, /* == */ 00113 TOK_NE, /* != */ 00114 TOK_GE, /* >= */ 00115 TOK_LE, /* <= */ 00116 TOK_ADD_EQ, /* += */ 00117 TOK_SUB_EQ, /* -= */ 00118 TOK_MUL_EQ, /* *= */ 00119 TOK_DIV_EQ, /* /= */ 00120 TOK_MOD_EQ, /* %= */ 00121 TOK_AND_EQ, /* &= */ 00122 TOK_OR_EQ, /* |= */ 00123 TOK_XOR_EQ, /* ^= */ 00124 TOK_ARROW, /* -> */ 00125 TOK_DOT_STAR, /* .* */ 00126 TOK_ARROW_STAR,/* ->* */ 00127 TOK_RSHIFT_EQ, /* >>= */ 00128 TOK_LSHIFT_EQ, /* <<= */ 00129 TOK_ELLIPSIS, /* ... */ 00130 } preproc_token_t; 00131 00141 typedef struct _StringTokenizer 00142 { 00143 int tok; /* the current token */ 00144 unsigned int hash; /* the hash of the current token, if it is an id */ 00145 const char *text; /* the text for the current token, not null-teminated */ 00146 size_t len; /* the length of the current token */ 00147 parse_space_t ws; /* controls what to consider as whitespace */ 00148 } StringTokenizer; 00149 00153 void vtkParse_InitTokenizer( 00154 StringTokenizer *tokens, const char *text, parse_space_t wstype); 00155 00159 int vtkParse_NextToken(StringTokenizer *tokens); 00160 00166 size_t vtkParse_SkipWhitespace( 00167 const char *cp, parse_space_t spacetype); 00168 00173 size_t vtkParse_SkipComment(const char *cp); 00174 00179 size_t vtkParse_SkipQuotes(const char *cp); 00180 00185 size_t vtkParse_SkipNumber(const char *cp); 00186 00191 size_t vtkParse_SkipId(const char *cp); 00192 00200 unsigned int vtkParse_HashId(const char *cp); 00201 00202 00208 typedef struct _StringCache 00209 { 00210 unsigned long NumberOfChunks; 00211 char **Chunks; 00212 size_t ChunkSize; 00213 size_t Position; 00214 } StringCache; 00215 00219 void vtkParse_InitStringCache(StringCache *cache); 00220 00225 char *vtkParse_NewString(StringCache *cache, size_t n); 00226 00233 const char *vtkParse_CacheString( 00234 StringCache *cache, const char *cp, size_t n); 00235 00240 void vtkParse_FreeStringCache(StringCache *cache); 00241 00242 #ifdef __cplusplus 00243 } /* extern "C" */ 00244 #endif 00245 00246 #endif