handle indentation + minor cleanup, words should know their indentation for pythonlikes..
This commit is contained in:
parent
5d2f0d187b
commit
5ec1879796
32
engine/slc.h
32
engine/slc.h
@ -38,11 +38,17 @@ enum SLC_WORDTYP {
|
|||||||
};
|
};
|
||||||
typedef enum SLC_WORDTYP SLC_WORDTYP;
|
typedef enum SLC_WORDTYP SLC_WORDTYP;
|
||||||
|
|
||||||
|
/** Gets padding bytes for a memory address to be padded to alignment */
|
||||||
static inline int get_padding(uint8_t *ptr, int alignment) {
|
static inline int get_padding(uint8_t *ptr, int alignment) {
|
||||||
// return (alignment - (ptr % alignment)) % alignment;
|
// return (alignment - (ptr % alignment)) % alignment;
|
||||||
return (ptrdiff_t)(ptr + alignment - 1) / alignment * alignment;
|
return (ptrdiff_t)(ptr + alignment - 1) / alignment * alignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Tells if c ends a line (that is either \n or \r) */
|
||||||
|
static inline char endsline(char c) {
|
||||||
|
return (c == '\n') || (c == '\r');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A word definition starts right after this. After processing it, we inline overwrite random parts of it in memory...
|
* A word definition starts right after this. After processing it, we inline overwrite random parts of it in memory...
|
||||||
*
|
*
|
||||||
@ -375,7 +381,9 @@ static inline void slc(
|
|||||||
|
|
||||||
char last_is_endl = 0;
|
char last_is_endl = 0;
|
||||||
int line = 0;
|
int line = 0;
|
||||||
int col_plus_one = -1;
|
int col = -1;
|
||||||
|
char is_indenting = 1;
|
||||||
|
int indent = 0;
|
||||||
|
|
||||||
// TODO: Handle/count indentation for better error messages
|
// TODO: Handle/count indentation for better error messages
|
||||||
|
|
||||||
@ -389,18 +397,28 @@ static inline void slc(
|
|||||||
|
|
||||||
char c = 0;
|
char c = 0;
|
||||||
while(((c = code_src()) != 0)) {
|
while(((c = code_src()) != 0)) {
|
||||||
/* Handle lines and columns */
|
/* Handle lines and columns, parts of indenting */
|
||||||
if(c == '\n' || c == '\r') {
|
if(endsline(c)) {
|
||||||
if(!last_is_endl) {
|
if(!last_is_endl) {
|
||||||
++line;
|
++line;
|
||||||
col_plus_one = 0;
|
col = 0;
|
||||||
|
/* Indent part */
|
||||||
|
is_indenting = 1;
|
||||||
|
indent = 0;
|
||||||
}
|
}
|
||||||
last_is_endl = 1;
|
last_is_endl = 1;
|
||||||
} else { last_is_endl = 0; ++col_plus_one; }
|
} else { last_is_endl = 0; ++col; }
|
||||||
|
|
||||||
|
/* Handle indenting */
|
||||||
|
if((c == ' ') || (c == ' ')) {
|
||||||
|
indent += is_indenting;
|
||||||
|
} else {
|
||||||
|
/* Defends against state-changer endline */
|
||||||
|
is_indenting = endsline(c);
|
||||||
|
}
|
||||||
process_char:
|
process_char:
|
||||||
int col = col_plus_one;
|
|
||||||
#ifdef SLC_DEBUG
|
#ifdef SLC_DEBUG
|
||||||
printf("%c state:%c @ line:%d col:%d\n", c, state, line, col);
|
fprintf(stderr, "%c state:%c @ line:%d col:%d indent:%d\n", c, state, line, col, indent);
|
||||||
#endif
|
#endif
|
||||||
switch(state) {
|
switch(state) {
|
||||||
case SLC_START:
|
case SLC_START:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user