Lexer is not collecting hanging new lines

This commit is contained in:
Krzosa Karol
2022-05-24 22:13:53 +02:00
parent e032fefd07
commit 52910d5606
3 changed files with 19 additions and 14 deletions

View File

@@ -257,9 +257,8 @@ ast_expr_index(Token *pos, Ast_Expr *expr, Ast_Expr *index){
return result; return result;
} }
function Ast_Lambda * function Ast_Lambda *
ast_lambda(Token *pos, Array<Ast_Lambda_Arg *> params, Ast_Typespec *ret){ ast_lambda(Token *pos, Array<Ast_Lambda_Arg *> params, Ast_Typespec *ret, Ast_Block *block){
AST_NEW(Lambda, AST_LAMBDA, pos); AST_NEW(Lambda, AST_LAMBDA, pos);
result->args = params.tight_copy(pctx->perm); result->args = params.tight_copy(pctx->perm);
result->ret = ret; result->ret = ret;

View File

@@ -114,6 +114,7 @@ struct Lex_Stream{
String file; String file;
S32 line; S32 line;
S32 inside_brace_paren; S32 inside_brace_paren;
S32 last_valid_indent;
}; };
struct Lexer{ struct Lexer{
@@ -481,7 +482,11 @@ lex__stream(Intern_Table *table, Array<Token> *array, Lex_Stream *s){
if(t.len==0) if(t.len==0)
lex_set_len(s,&t); lex_set_len(s,&t);
B32 skip = t.kind == TK_NewLine && s->inside_brace_paren > 0; B32 skip = 0;
if(t.kind == TK_NewLine){
if(s->inside_brace_paren > 0) skip = 1;
if(array->len > 0 && array->last()->kind == TK_NewLine) array->pop();
}
if(!skip){ if(!skip){
array->add(t); array->add(t);
} }

View File

@@ -165,16 +165,16 @@ parse_optional_type(){
return result; return result;
} }
/*
function Ast_Block *
parse_block(){
Ast_Block *result = 0;
if(token_match(TK_NewScope)){
} // function Ast_Block *
return result; // parse_block(){
} // Ast_Block *result = 0;
*/ // if(token_match(TK_NewScope)){
// }
// return result;
// }
function Ast_Lambda * function Ast_Lambda *
parse_lambda(Token *token, B32 is_typespec = false){ // @Todo(Krzosa): is_typespec is not used currently parse_lambda(Token *token, B32 is_typespec = false){ // @Todo(Krzosa): is_typespec is not used currently
@@ -197,8 +197,9 @@ parse_lambda(Token *token, B32 is_typespec = false){ // @Todo(Krzosa): is_typesp
} }
token_expect(TK_CloseParen); token_expect(TK_CloseParen);
//Ast_Block *block = parse_block(); Ast_Typespec *ret = parse_optional_type();
Ast_Lambda *result = ast_lambda(token, params, parse_optional_type()); Ast_Block *block = 0;
Ast_Lambda *result = ast_lambda(token, params, ret, block);
return result; return result;
} }