CORE_Static
This commit is contained in:
@@ -3,59 +3,59 @@ force_inline B32 token_is_assign(Token *token){return token_is_assign(token->kin
|
||||
force_inline B32 token_is_compare(Token_Kind token){return token >= TK_FirstCompare && token <= TK_LastCompare;}
|
||||
force_inline B32 token_is_compare(Token *token){return token_is_compare(token->kind);}
|
||||
|
||||
function U8
|
||||
CORE_Static U8
|
||||
lexc(Lex_Stream *s){
|
||||
return s->stream.str[s->iter];
|
||||
}
|
||||
|
||||
function U8
|
||||
CORE_Static U8
|
||||
lexci(Lex_Stream *s, S32 i){
|
||||
return s->stream.str[s->iter+i];
|
||||
}
|
||||
|
||||
function U8 *
|
||||
CORE_Static U8 *
|
||||
lexcp(Lex_Stream *s){
|
||||
return s->stream.str + s->iter;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
lex_is_whitespace(U8 c){
|
||||
B32 result = c == ' ' || c == '\r';
|
||||
return result;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
lex_is_alphabetic(U8 c){
|
||||
B32 result = (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
|
||||
return result;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
lex_is_numeric(U8 c){
|
||||
B32 result = c >= '0' && c <= '9';
|
||||
return result;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
lex_is_numeric_base16(U8 c){
|
||||
B32 result = (c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') ||
|
||||
(c >= 'a' && c <= 'f');
|
||||
return result;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
lex_is_alphanumeric(U8 c){
|
||||
B32 result = lex_is_numeric(c) || lex_is_alphabetic(c);
|
||||
return result;
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
lex_set_len(Lex_Stream *s, Token *token){
|
||||
assert(lexcp(s) >= token->str);
|
||||
token->len = lexcp(s) - token->str;
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
lex_set_keywords(Lexer *lexer, Array<String> keywords){
|
||||
Intern_String keyword = {};
|
||||
For(keywords){
|
||||
@@ -66,19 +66,19 @@ lex_set_keywords(Lexer *lexer, Array<String> keywords){
|
||||
lexer->interns.last_keyword = keyword.str;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
lex_is_keyword(Intern_Table *lexer, Intern_String keyword){
|
||||
B32 result = keyword.str >= lexer->first_keyword && keyword.str <= lexer->last_keyword;
|
||||
return result;
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
token_error(Token *t, String error_val){
|
||||
t->kind = TK_Error;
|
||||
t->error_val = error_val;
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
lex_parse_u64(Lexer *lexer, Token *t, S64 base){
|
||||
Scratch scratch;
|
||||
Set_BigInt_Arena(scratch);
|
||||
@@ -103,7 +103,7 @@ lex_parse_u64(Lexer *lexer, Token *t, S64 base){
|
||||
t->int_val = bigint_copy(lexer->arena, &result);
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
lex_parse_f64(Token *t){
|
||||
t->kind = TK_Float;
|
||||
char buffer[128];
|
||||
@@ -113,7 +113,7 @@ lex_parse_f64(Token *t){
|
||||
t->f64_val = strtod(buffer, 0);
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
lex_advance(Lex_Stream *s){
|
||||
if(s->iter >= s->stream.len){
|
||||
return;
|
||||
@@ -128,7 +128,7 @@ lex_advance(Lex_Stream *s){
|
||||
}
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
lex_parse_string(Lex_Stream *s, Token *t, U8 c){
|
||||
for(;;){
|
||||
if(lexc(s) == '\\') lex_advance(s);
|
||||
@@ -145,7 +145,7 @@ lex_parse_string(Lex_Stream *s, Token *t, U8 c){
|
||||
}
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
lex_parse_ident(Intern_Table *table, Lex_Stream *s, Token *t){
|
||||
while(lex_is_alphanumeric(lexc(s)) || lexc(s) == '_')
|
||||
lex_advance(s);
|
||||
@@ -174,7 +174,7 @@ lex_parse_ident(Intern_Table *table, Lex_Stream *s, Token *t){
|
||||
} \
|
||||
break
|
||||
|
||||
function Token
|
||||
CORE_Static Token
|
||||
token_make(Lexer *lexer, U8 *str, Intern_String file, int line, U8 *line_begin){
|
||||
Token t = {};
|
||||
t.str = str;
|
||||
@@ -185,12 +185,12 @@ token_make(Lexer *lexer, U8 *str, Intern_String file, int line, U8 *line_begin){
|
||||
return t;
|
||||
}
|
||||
|
||||
function Token
|
||||
CORE_Static Token
|
||||
token_make(Lexer *lexer){
|
||||
return token_make(lexer, lexcp(&lexer->stream), lexer->stream.file, lexer->stream.line, lexer->stream.line_begin);
|
||||
}
|
||||
|
||||
function Token *
|
||||
CORE_Static Token *
|
||||
lex_last_indent_token(Lex_Stream *s){
|
||||
if(s->indent_stack.len > 0){
|
||||
return *s->indent_stack.last();
|
||||
@@ -198,13 +198,13 @@ lex_last_indent_token(Lex_Stream *s){
|
||||
return &token_null;
|
||||
}
|
||||
|
||||
function B32
|
||||
CORE_Static B32
|
||||
lex_is_scope(Token *t){
|
||||
B32 result = t->kind == OPEN_SCOPE || t->kind == CLOSE_SCOPE || t->kind == SAME_SCOPE;
|
||||
return result;
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
lex_unwind_indent_stack(Token *t, Lex_Stream *s, Array<Token> *array){
|
||||
for(S64 i = s->indent_stack.len-1; i >= 0; i-=1){
|
||||
auto it = s->indent_stack.data[i];
|
||||
@@ -227,7 +227,7 @@ lex_unwind_indent_stack(Token *t, Lex_Stream *s, Array<Token> *array){
|
||||
}
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
lex__stream(Lexer *lexer){
|
||||
Intern_Table *table = &lexer->interns;
|
||||
Array<Token> *array = &lexer->tokens;
|
||||
@@ -250,7 +250,7 @@ lex__stream(Lexer *lexer){
|
||||
// of same scope.
|
||||
// parse_decl doesn't require preceding new line
|
||||
//
|
||||
// in that way new lines act as commas in function params
|
||||
// in that way new lines act as commas in CORE_Static params
|
||||
// seeing a comma means that there is a next thing to parse
|
||||
// and it's easy to parse stuff using a do while loop
|
||||
|
||||
@@ -585,14 +585,14 @@ lex__stream(Lexer *lexer){
|
||||
#undef CASE3
|
||||
}
|
||||
|
||||
function Lexer
|
||||
CORE_Static Lexer
|
||||
lex_make(Arena *token_string_arena, Arena *map_allocator){
|
||||
Lexer result = {};
|
||||
lex_init(token_string_arena, map_allocator, &result);
|
||||
return result;
|
||||
}
|
||||
|
||||
function void
|
||||
CORE_Static void
|
||||
lex_restream(Lexer *lexer, String istream, String file){
|
||||
lexer->stream = {};
|
||||
lexer->stream.stream = istream;
|
||||
@@ -605,7 +605,7 @@ lex_restream(Lexer *lexer, String istream, String file){
|
||||
lex__stream(lexer);
|
||||
}
|
||||
|
||||
function Lexer
|
||||
CORE_Static Lexer
|
||||
lex_stream(Arena *token_string_arena, Arena *map_allocator, String istream, String file){
|
||||
Lexer result = lex_make(token_string_arena, map_allocator);
|
||||
lex_restream(&result, istream, file);
|
||||
@@ -616,7 +616,7 @@ lex_stream(Arena *token_string_arena, Arena *map_allocator, String istream, Stri
|
||||
// Token metadata
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
function const char *
|
||||
CORE_Static const char *
|
||||
name(Token_Kind kind){
|
||||
switch(kind){
|
||||
case TK_End: return "End of stream";
|
||||
|
||||
Reference in New Issue
Block a user