slc comment start state machine

This commit is contained in:
Richard Thier 2024-09-26 11:52:28 +02:00
parent 844a9165dd
commit ceabdee697

View File

@ -5,6 +5,9 @@
#include<string.h> // memcpy, strlen..
#include<stddef.h> // NULL
/* Define this if you want to debug the engine doing its thing */
/* #define SLC_DEBUG */
/* Session offset type - defaults to 64 bit because of union types enable storage for it often, but you can override */
#ifndef SLOFFS_T
#define SLOFFS_T uint64_t
@ -268,11 +271,30 @@ static inline slc_state slc_comment_statechange_in(
char c,
const char *singleline_comment,
const char *multiline_comment_opener,
int singleline_comment_len,
int multiline_comment_len,
int *comment_i,
int *multiline_i){
// FIXME: Implement
char s = singleline_comment[*comment_i];
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;
/* Single-line comment progress */
if(c == s) {
++(*comment_i);
} else {
*comment_i = 0;
}
/* Multi-line comment progress */
if(c == m) {
++(*multiline_i);
} else {
*multiline_i = 0;
}
return current_state;
}
@ -351,8 +373,6 @@ static inline void slc(
const char *varprefix) {
slc_state state = SLC_START;
int singleline_comment_len = strlen(singleline_comment);
int multiline_comment_opener_len = strlen(multiline_comment_opener);
// TODO: Count line numbers
// TODO: Handle/count indentation for better error messages
@ -374,8 +394,6 @@ static inline void slc(
c,
singleline_comment,
multiline_comment_opener,
singleline_comment_len,
multiline_comment_opener_len,
&comment_i,
&multiline_i);