diff --git a/engine/slc.h b/engine/slc.h index d0a4d3e..94ecc25 100644 --- a/engine/slc.h +++ b/engine/slc.h @@ -285,8 +285,8 @@ static inline slc_state slc_comment_statechange_in( char m = multiline_comment_opener[*multiline_i]; /* Check if we have finished processing */ - if(s == 0) return SLC_COMMENT; - if(m == 0) return SLC_MULTILINE_COMMENT; + if(s == 0) { *comment_i = 0; return SLC_COMMENT; } + if(m == 0) { *multiline_i = 0; return SLC_MULTILINE_COMMENT; } /* Single-line comment progress */ if(c == s) { @@ -305,6 +305,27 @@ static inline slc_state slc_comment_statechange_in( 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( slc_state current_state, char c, @@ -314,7 +335,7 @@ static inline slc_state slc_def_name_statechange( return current_state; } -static inline slc_state slc_word_name_statechange( +static inline slc_state slc_word_statechange( slc_state current_state, char c, int *wordname_i, @@ -385,8 +406,6 @@ static inline void slc( char is_indenting = 1; int indent = 0; - // TODO: Handle/count indentation for better error messages - slc_state state = SLC_START; int comment_i = 0; @@ -438,23 +457,27 @@ static inline void slc( c, prefix, &prefix_i); - } else goto process_char; /* new state might need 'c' too */ + } - /* state -> word_name */ + /* state -> word_name | word_var */ if(state == SLC_START) { - state = slc_word_name_statechange( + state = slc_word_statechange( state, c, &wordname_i, 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; case SLC_COMMENT: + if(endsline(c)) state = SLC_START; break; case SLC_MULTILINE_COMMENT: + state = slc_multiline_comment_statechange_out( + state, + c, + multiline_comment_closer, + &multiline_i); break; case SLC_DEF_NAME: break;