line and column handling + better debug log
This commit is contained in:
parent
aaa8b2fb9c
commit
5d2f0d187b
37
engine/slc.h
37
engine/slc.h
@ -246,23 +246,24 @@ typedef iores (*ioconn)(SLC_IO_OP op, const char *param);
|
||||
*/
|
||||
typedef char (*coderead)();
|
||||
|
||||
enum slc_state : uint32_t {
|
||||
/** States the main state-engine can pick up - use characters for debugging better */
|
||||
enum slc_state : uint8_t {
|
||||
/** Before things */
|
||||
SLC_START = 0,
|
||||
SLC_START = 's',
|
||||
/** In a comment */
|
||||
SLC_COMMENT = 1,
|
||||
SLC_COMMENT = 'c',
|
||||
/** In multi-line comment */
|
||||
SLC_MULTILINE_COMMENT = 2,
|
||||
SLC_MULTILINE_COMMENT = 'm',
|
||||
/** Name part of word-definition (after ':') - whitespace ends it */
|
||||
SLC_DEF_NAME = 3,
|
||||
SLC_DEF_NAME = 'd',
|
||||
/** Variable-listing part of word-definition - endline, '(', '[' or '{' ends it */
|
||||
SLC_DEF_VAR = 4,
|
||||
SLC_DEF_VAR = 'D',
|
||||
/** Raw body part of the word definition - these can contain local variable accesses + words, depth counted by vars */
|
||||
SLC_DEF_BODY = 5,
|
||||
SLC_DEF_BODY = 'b',
|
||||
/** Name part of a word "call" (non-definition). Ends by whitespace, '@' (in case of variable) or various parentheses */
|
||||
SLC_WORD_NAME = 6,
|
||||
SLC_WORD_NAME = 'w',
|
||||
/** Variable call (MYWORD@MYVAR) - we get to be here from SLC_WORD_NAME or from START */
|
||||
SLC_WORD_VAR = 7,
|
||||
SLC_WORD_VAR = 'W',
|
||||
};
|
||||
typedef enum slc_state slc_state;
|
||||
|
||||
@ -372,11 +373,14 @@ static inline void slc(
|
||||
const char *ender,
|
||||
const char *varprefix) {
|
||||
|
||||
slc_state state = SLC_START;
|
||||
char last_is_endl = 0;
|
||||
int line = 0;
|
||||
int col_plus_one = -1;
|
||||
|
||||
// TODO: Count line numbers
|
||||
// TODO: Handle/count indentation for better error messages
|
||||
|
||||
slc_state state = SLC_START;
|
||||
|
||||
int comment_i = 0;
|
||||
int multiline_i = 0;
|
||||
int prefix_i = 0;
|
||||
@ -385,9 +389,18 @@ static inline void slc(
|
||||
|
||||
char c = 0;
|
||||
while(((c = code_src()) != 0)) {
|
||||
/* Handle lines and columns */
|
||||
if(c == '\n' || c == '\r') {
|
||||
if(!last_is_endl) {
|
||||
++line;
|
||||
col_plus_one = 0;
|
||||
}
|
||||
last_is_endl = 1;
|
||||
} else { last_is_endl = 0; ++col_plus_one; }
|
||||
process_char:
|
||||
int col = col_plus_one;
|
||||
#ifdef SLC_DEBUG
|
||||
printf("%c @ %d\n", c, state);
|
||||
printf("%c state:%c @ line:%d col:%d\n", c, state, line, col);
|
||||
#endif
|
||||
switch(state) {
|
||||
case SLC_START:
|
||||
|
Loading…
x
Reference in New Issue
Block a user