finally all comment states seem to work well

This commit is contained in:
Richard Thier 2024-09-26 14:14:23 +02:00
parent 5ec1879796
commit 71619a7fde

View File

@ -285,8 +285,8 @@ static inline slc_state slc_comment_statechange_in(
char m = multiline_comment_opener[*multiline_i]; char m = multiline_comment_opener[*multiline_i];
/* Check if we have finished processing */ /* Check if we have finished processing */
if(s == 0) return SLC_COMMENT; if(s == 0) { *comment_i = 0; return SLC_COMMENT; }
if(m == 0) return SLC_MULTILINE_COMMENT; if(m == 0) { *multiline_i = 0; return SLC_MULTILINE_COMMENT; }
/* Single-line comment progress */ /* Single-line comment progress */
if(c == s) { if(c == s) {
@ -305,6 +305,27 @@ static inline slc_state slc_comment_statechange_in(
return current_state; return current_state;
} }
static inline slc_state slc_multiline_comment_statechange_out(
slc_state current_state,
char c,
const char *multiline_comment_closer,
int *multiline_i){
char m = multiline_comment_closer[*multiline_i];
/* Check if we have finished processing */
if(m == 0) { *multiline_i = 0; return SLC_START; }
/* Multi-line comment progress */
if(c == m) {
++(*multiline_i);
} else {
*multiline_i = 0;
}
return current_state;
}
static inline slc_state slc_def_name_statechange( static inline slc_state slc_def_name_statechange(
slc_state current_state, slc_state current_state,
char c, char c,
@ -314,7 +335,7 @@ static inline slc_state slc_def_name_statechange(
return current_state; return current_state;
} }
static inline slc_state slc_word_name_statechange( static inline slc_state slc_word_statechange(
slc_state current_state, slc_state current_state,
char c, char c,
int *wordname_i, int *wordname_i,
@ -385,8 +406,6 @@ static inline void slc(
char is_indenting = 1; char is_indenting = 1;
int indent = 0; int indent = 0;
// TODO: Handle/count indentation for better error messages
slc_state state = SLC_START; slc_state state = SLC_START;
int comment_i = 0; int comment_i = 0;
@ -438,23 +457,27 @@ static inline void slc(
c, c,
prefix, prefix,
&prefix_i); &prefix_i);
} else goto process_char; /* new state might need 'c' too */ }
/* state -> word_name */ /* state -> word_name | word_var */
if(state == SLC_START) { if(state == SLC_START) {
state = slc_word_name_statechange( state = slc_word_statechange(
state, state,
c, c,
&wordname_i, &wordname_i,
wordname); wordname);
if(state != SLC_START) goto process_char; /* new state might need 'c' too */ }
} else goto process_char; /* new state might need 'c' too */
/* Step to read next character */
break; break;
case SLC_COMMENT: case SLC_COMMENT:
if(endsline(c)) state = SLC_START;
break; break;
case SLC_MULTILINE_COMMENT: case SLC_MULTILINE_COMMENT:
state = slc_multiline_comment_statechange_out(
state,
c,
multiline_comment_closer,
&multiline_i);
break; break;
case SLC_DEF_NAME: case SLC_DEF_NAME:
break; break;