242 * and ignores ';' inside comments and pragmas. This means that we cannot do this in a signle lex rule. |
242 * and ignores ';' inside comments and pragmas. This means that we cannot do this in a signle lex rule. |
243 * Body_state therefore stores ALL text we consume in every rule, so we can push it back into the buffer |
243 * Body_state therefore stores ALL text we consume in every rule, so we can push it back into the buffer |
244 * once we have decided if we are parsing ST or IL code. The following functions manage that buffer used by |
244 * once we have decided if we are parsing ST or IL code. The following functions manage that buffer used by |
245 * the body_state. |
245 * the body_state. |
246 */ |
246 */ |
247 void append_bodystate_buffer(const char *text); |
247 void append_bodystate_buffer(const char *text, int is_whitespace = 0); |
248 void unput_bodystate_buffer(void); |
248 void unput_bodystate_buffer(void); |
249 int isempty_bodystate_buffer(void); |
249 int isempty_bodystate_buffer(void); |
250 |
250 |
251 int GetNextChar(char *b, int maxBuffer); |
251 int GetNextChar(char *b, int maxBuffer); |
252 %} |
252 %} |
1196 * we simply store them for later processing! |
1196 * we simply store them for later processing! |
1197 * NOTE: we must return ALL text when in body_state, including |
1197 * NOTE: we must return ALL text when in body_state, including |
1198 * all comments and whitespace, so as not |
1198 * all comments and whitespace, so as not |
1199 * to lose track of the line_number and column number |
1199 * to lose track of the line_number and column number |
1200 * used when printing debugging messages. |
1200 * used when printing debugging messages. |
1201 * Note that some of the following rules depend on the fact that |
1201 * NOTE: some of the following rules depend on the fact that |
1202 * the body state buffer is either empty or only contains white space up to |
1202 * the body state buffer is either empty or only contains white space up to |
1203 * that point. However, since the vardecl_list_state will eat up all |
1203 * that point. Since the vardecl_list_state will eat up all |
1204 * whitespace before entering the body_state, the contents of the bodystate_buffer |
1204 * whitespace before entering the body_state, the contents of the bodystate_buffer |
1205 * will _never_ start with whitespace. |
1205 * will _never_ start with whitespace if the previous state was vardecl_list_state. |
|
1206 * However, it is possible to enter the body_state from other states (e.g. when |
|
1207 * parsing SFC code, that contains transitions or actions in other languages) |
1206 */ |
1208 */ |
1207 append_bodystate_buffer(yytext); |
1209 append_bodystate_buffer(yytext, 1 /* is whitespace */); |
1208 } |
1210 } |
1209 /* 'INITIAL_STEP' always used in beginning of SFCs !! */ |
1211 /* 'INITIAL_STEP' always used in beginning of SFCs !! */ |
1210 INITIAL_STEP { if (isempty_bodystate_buffer()) {unput_text(0); BEGIN(sfc_state);} |
1212 INITIAL_STEP { if (isempty_bodystate_buffer()) {unput_text(0); BEGIN(sfc_state);} |
1211 else {append_bodystate_buffer(yytext);} |
1213 else {append_bodystate_buffer(yytext);} |
1212 } |
1214 } |
2117 char *bodystate_buffer = NULL; |
2119 char *bodystate_buffer = NULL; |
2118 bool bodystate_is_whitespace = 1; // TRUE (1) if buffer is empty, or only contains whitespace. |
2120 bool bodystate_is_whitespace = 1; // TRUE (1) if buffer is empty, or only contains whitespace. |
2119 tracking_t bodystate_init_tracking; |
2121 tracking_t bodystate_init_tracking; |
2120 |
2122 |
2121 /* append text to bodystate_buffer */ |
2123 /* append text to bodystate_buffer */ |
2122 void append_bodystate_buffer(const char *text) { |
2124 void append_bodystate_buffer(const char *text, int is_whitespace) { |
2123 // printf("<<<append_bodystate_buffer>>> %d <%s><%s>\n", bodystate_buffer, text, (NULL != bodystate_buffer)?bodystate_buffer:"NULL"); |
2125 // printf("<<<append_bodystate_buffer>>> %d <%s><%s>\n", bodystate_buffer, text, (NULL != bodystate_buffer)?bodystate_buffer:"NULL"); |
2124 long int old_len = 0; |
2126 long int old_len = 0; |
2125 // make backup of tracking if we are starting off a new body_state_buffer |
2127 // make backup of tracking if we are starting off a new body_state_buffer |
2126 if (NULL == bodystate_buffer) bodystate_init_tracking = *current_tracking; |
2128 if (NULL == bodystate_buffer) bodystate_init_tracking = *current_tracking; |
|
2129 // set bodystate_is_whitespace flag if we are starting a new buffer |
|
2130 if (NULL == bodystate_buffer) bodystate_is_whitespace = 1; |
|
2131 // set bodystate_is_whitespace flag to FALSE if we are adding non white space to buffer |
|
2132 if (!is_whitespace) bodystate_is_whitespace = 0; |
2127 |
2133 |
2128 if (NULL != bodystate_buffer) old_len = strlen(bodystate_buffer); |
2134 if (NULL != bodystate_buffer) old_len = strlen(bodystate_buffer); |
2129 bodystate_buffer = (char *)realloc(bodystate_buffer, old_len + strlen(text) + 1); |
2135 bodystate_buffer = (char *)realloc(bodystate_buffer, old_len + strlen(text) + 1); |
2130 if (NULL == bodystate_buffer) ERROR; |
2136 if (NULL == bodystate_buffer) ERROR; |
2131 strcpy(bodystate_buffer + old_len, text); |
2137 strcpy(bodystate_buffer + old_len, text); |
2139 |
2145 |
2140 for (long int i = strlen(bodystate_buffer)-1; i >= 0; i--) |
2146 for (long int i = strlen(bodystate_buffer)-1; i >= 0; i--) |
2141 unput_char(bodystate_buffer[i]); |
2147 unput_char(bodystate_buffer[i]); |
2142 |
2148 |
2143 free(bodystate_buffer); |
2149 free(bodystate_buffer); |
2144 bodystate_buffer = NULL; |
2150 bodystate_buffer = NULL; |
|
2151 bodystate_is_whitespace = 1; |
2145 *current_tracking = bodystate_init_tracking; |
2152 *current_tracking = bodystate_init_tracking; |
2146 } |
2153 } |
2147 |
2154 |
2148 |
2155 |
2149 /* Return true if bodystate_buffer is empty or ony contains whitespace!! */ |
2156 /* Return true if bodystate_buffer is empty or ony contains whitespace!! */ |
2150 int isempty_bodystate_buffer(void) { |
2157 int isempty_bodystate_buffer(void) { |
2151 if (NULL == bodystate_buffer) return 1; |
2158 if (NULL == bodystate_buffer) return 1; |
|
2159 if (bodystate_is_whitespace) return 1; |
2152 return 0; |
2160 return 0; |
2153 } |
2161 } |
2154 |
2162 |
2155 |
2163 |
2156 |
2164 |