Fix field parsing
This commit is contained in:
10
lexer.kl
10
lexer.kl
@@ -1,4 +1,14 @@
|
||||
Lex_Stream :: struct
|
||||
stream: String
|
||||
offset: int
|
||||
|
||||
lexc :: (s: *Lex_Stream): String // @todo U8 U S
|
||||
return s.stream + s.offset // @todo parsing fields wrong + s.offset // + s.offset @todo Actual string support
|
||||
|
||||
main :: ()
|
||||
string_to_lex := "Identifier 2425525 Not_Number"
|
||||
s := Lex_Stream(stream=string_to_lex)
|
||||
|
||||
for inf:=0, inf, inf // @todo for
|
||||
pass
|
||||
|
||||
|
||||
5
main.cpp
5
main.cpp
@@ -43,7 +43,6 @@ For now I don't thing it should be overloadable.
|
||||
[ ] - Switch
|
||||
[ ] - More basic types
|
||||
[ ] - Array of inferred size
|
||||
[ ] - Lexer: Need to insert scope endings when hitting End of file
|
||||
[ ] - Add single line lambda expressions
|
||||
|
||||
@ideas
|
||||
@@ -61,6 +60,7 @@ For now I don't thing it should be overloadable.
|
||||
[x] - Default values in calls
|
||||
[x] - Resolving calls with default values
|
||||
[x] - Pass statement
|
||||
[x] - Lexer: Need to insert scope endings when hitting End of file
|
||||
[x] - Resolving calls with named args, with indexed args
|
||||
[x] - Structs
|
||||
[x] - Struct field access
|
||||
@@ -109,11 +109,10 @@ int main(){
|
||||
#endif
|
||||
|
||||
result = compile_file("lexer.kl"_s);
|
||||
|
||||
FILE *f = fopen("program.c", "w");
|
||||
assert(f);
|
||||
fprintf(f, "%.*s", (int)result.len, result.str);
|
||||
fclose(f);
|
||||
|
||||
__debugbreak();
|
||||
// __debugbreak();
|
||||
}
|
||||
|
||||
@@ -208,7 +208,7 @@ function Ast_Named *parse_named(B32);
|
||||
function Ast_Block *
|
||||
parse_block(){
|
||||
Ast_Block *block = 0;
|
||||
if(token_match(OPEN_SCOPE)){
|
||||
if(token_expect(OPEN_SCOPE)){ // @todo: Fix error message here, it doesn't show proper token context
|
||||
Token *token_block = token_get();
|
||||
|
||||
Scratch scratch;
|
||||
@@ -392,7 +392,7 @@ left_denotation(Token *op, Ast_Expr *left){
|
||||
function S64
|
||||
postfix_binding_power(Token_Kind kind){
|
||||
switch(kind){
|
||||
case TK_Dot: case TK_Decrement: case TK_Increment: case TK_OpenBracket: case TK_OpenParen: return 1;
|
||||
case TK_Dot: case TK_Decrement: case TK_Increment: case TK_OpenBracket: case TK_OpenParen: return 3;
|
||||
default: return 0;
|
||||
}
|
||||
}
|
||||
@@ -405,17 +405,16 @@ parse_expr(S64 rbp){
|
||||
token = token_get();
|
||||
|
||||
// @note: parse postfix
|
||||
if(postfix_binding_power(token->kind) > rbp){
|
||||
S64 pbp = postfix_binding_power(token->kind);
|
||||
if(pbp > rbp){
|
||||
token_next();
|
||||
switch(token->kind){
|
||||
case TK_Dot: {
|
||||
// @note: making sure that we always get a configuration where
|
||||
// Identifier is in left node
|
||||
Ast_Expr *right = parse_expr();
|
||||
Ast_Expr *right = parse_expr(pbp-1);
|
||||
left = ast_expr_binary(left, right, token);
|
||||
}break;
|
||||
case TK_OpenBracket:{
|
||||
Ast_Expr *index = parse_expr();
|
||||
Ast_Expr *index = parse_expr(pbp-1);
|
||||
left = ast_expr_index(token, left, index);
|
||||
token_expect(TK_CloseBracket);
|
||||
}break;
|
||||
@@ -423,6 +422,7 @@ parse_expr(S64 rbp){
|
||||
left = parse_expr_call(left);
|
||||
}break;
|
||||
default:{
|
||||
assert(token->kind == TK_Increment || token->kind == TK_Decrement);
|
||||
if(token->kind == TK_Increment) token->kind = TK_PostIncrement;
|
||||
else if(token->kind == TK_Decrement) token->kind = TK_PostDecrement;
|
||||
left = ast_expr_unary(token, token->kind, left);
|
||||
|
||||
11
program.c
11
program.c
@@ -4,6 +4,17 @@
|
||||
#define NULL_LAMBDA 0
|
||||
//-------------------------------
|
||||
|
||||
struct Lex_Stream{
|
||||
String stream;
|
||||
int offset;
|
||||
};
|
||||
static String lexc(Lex_Stream *s){
|
||||
return s->stream;
|
||||
}
|
||||
static void main(){
|
||||
String string_to_lex = LIT("Identifier 2425525 Not_Number");
|
||||
Lex_Stream s = (Lex_Stream ){.stream = string_to_lex};
|
||||
for(int inf = 0;inf;inf){
|
||||
//pass
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user