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;
}
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);
result->args = params.tight_copy(pctx->perm);
result->ret = ret;

View File

@@ -114,6 +114,7 @@ struct Lex_Stream{
String file;
S32 line;
S32 inside_brace_paren;
S32 last_valid_indent;
};
struct Lexer{
@@ -481,7 +482,11 @@ lex__stream(Intern_Table *table, Array<Token> *array, Lex_Stream *s){
if(t.len==0)
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){
array->add(t);
}

View File

@@ -165,16 +165,16 @@ parse_optional_type(){
return result;
}
/*
function Ast_Block *
parse_block(){
Ast_Block *result = 0;
if(token_match(TK_NewScope)){
}
return result;
}
*/
// function Ast_Block *
// parse_block(){
// Ast_Block *result = 0;
// if(token_match(TK_NewScope)){
// }
// return result;
// }
function Ast_Lambda *
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);
//Ast_Block *block = parse_block();
Ast_Lambda *result = ast_lambda(token, params, parse_optional_type());
Ast_Typespec *ret = parse_optional_type();
Ast_Block *block = 0;
Ast_Lambda *result = ast_lambda(token, params, ret, block);
return result;
}