Fix compile errors when compiling for msvc

This commit is contained in:
Krzosa Karol
2022-05-26 16:55:07 +02:00
parent c88b38cc44
commit 3cd79040bc
6 changed files with 48 additions and 32 deletions

View File

@@ -291,7 +291,7 @@ lex_last_indent_token(Lex_Stream *s){
}
function B32
token_is_scope(Token *t){
lex_is_scope(Token *t){
B32 result = t->kind == OPEN_SCOPE || t->kind == CLOSE_SCOPE || t->kind == SAME_SCOPE;
return result;
}
@@ -303,7 +303,7 @@ lex__stream(Intern_Table *table, Array<Token> *array, Lex_Stream *s){
if(s->iter >= s->stream.len) // End of stream
break;
// @note: for now the lexer is going to be a 2 stage process
// @note: the lexer is going to be a 2 stage process
// first we tokenize the indentation and then proceed to tokenize
// the good stuff
@@ -326,6 +326,7 @@ lex__stream(Intern_Table *table, Array<Token> *array, Lex_Stream *s){
switch(lexc(s)){
case '\t': case ' ': lex_advance(s); t.indent++; break;
case '\r': lex_advance(s); break;
case '/': {
if(lexci(s,1) == '/'){
lex_advance(s); lex_advance(s);
@@ -351,11 +352,34 @@ lex__stream(Intern_Table *table, Array<Token> *array, Lex_Stream *s){
}
}
} break;
case ';' : {
Token semi = token_make(lexcp(s), s->file, s->line, s->line_begin);
Token *last = lex_last_indent_token(s);
semi.kind = SAME_SCOPE;
semi.indent = last->indent;
lex_advance(s);
array->add(semi);
} break;
case '\n':{
lex_advance(s);
should_emit = true;
t = token_make(lexcp(s), s->file, s->line, s->line_begin);
} break;
// @todo: add open and close brace handling as OPEN_SCOPE CLOSE_SCOPE
// when it comes to compound statements it's going to check for scopes
// and then it's going to specialize and look for brace string
// case '{': {
// s->inside_brace_paren++; t.kind = TK_OpenBrace;
// } break;
// case '}': {
// s->inside_brace_paren--;
// t.kind = CLOSE_SCOPE;
// } break;
default:{
if(s->inside_brace_paren) should_emit = false;
if(should_emit){
@@ -365,10 +389,11 @@ lex__stream(Intern_Table *table, Array<Token> *array, Lex_Stream *s){
array->add(t);
s->indent_stack.add(array->last());
}
else if(t.indent < last->indent){
for(S64 i = s->indent_stack.len-1; i >= 0; i-=1){
auto it = s->indent_stack.data[i];
assert(token_is_scope(it));
assert(lex_is_scope(it));
if(it->indent == t.indent){
t.kind = SAME_SCOPE;
array->add(t);
@@ -422,10 +447,6 @@ lex__stream(Intern_Table *table, Array<Token> *array, Lex_Stream *s){
CASE3('+', TK_Add, TK_AddAssign, TK_Increment);
CASE3('&', TK_BitAnd, TK_AndAssign, TK_And);
CASE3('|', TK_BitOr, TK_OrAssign, TK_Or);
case ';': {
t.kind = TK_Semicolon;
}break;
case '.': {
if(lexc(s) == '.' && lexci(s,1) == '.') {
lex_advance(s); lex_advance(s);
@@ -608,7 +629,7 @@ lex_stream(Allocator *token_string_arena, Allocator *map_allocator, String istre
function void
lex_test(){
Scratch scratch;
String test = "Keyword //R\n 18446744073709551616\n {}\n)(@?&+-;....->,:::/**/\"Thing\" Thingy"
String test = "Keyword //R\n 18446744073709551616\n {}\n)(@?&+-....->,:::/**/\"Thing\" Thingy"
"\"Test_Meme\"+=-===42524 4294967295 18446744073709551615"
"for if while switch :="_s;
@@ -627,7 +648,7 @@ lex_test(){
Token_Kind kind[] = {
SAME_SCOPE,
TK_Keyword, OPEN_SCOPE, TK_Error, OPEN_SCOPE, TK_OpenBrace,TK_CloseBrace,CLOSE_SCOPE, CLOSE_SCOPE, SAME_SCOPE, TK_CloseParen,TK_OpenParen,
TK_At,TK_Question,TK_BitAnd,TK_Add,TK_Sub,TK_Semicolon,
TK_At,TK_Question,TK_BitAnd,TK_Add,TK_Sub,
TK_ThreeDots, TK_Dot, TK_Arrow, TK_Comma, TK_DoubleColon, TK_Colon,
TK_StringLit, TK_Identifier, TK_StringLit, TK_AddAssign, TK_SubAssign,
TK_Equals, TK_Integer, TK_Integer, TK_Integer,
@@ -636,7 +657,7 @@ lex_test(){
};
String strs[] = {
""_s, "Keyword"_s, ""_s, "18446744073709551616"_s, ""_s, "{"_s,"}"_s, ""_s, ""_s, ""_s, ")"_s, "("_s,
"@"_s,"?"_s,"&"_s,"+"_s,"-"_s,";"_s,
"@"_s,"?"_s,"&"_s,"+"_s,"-"_s,
"..."_s,"."_s,"->"_s,","_s,"::"_s,":"_s,
"Thing"_s,"Thingy"_s,"Test_Meme"_s, "+="_s,"-="_s,
"=="_s,"42524"_s,"4294967295"_s,"18446744073709551615"_s,