parent
							
								
									5a2c271bd4
								
							
						
					
					
						commit
						786045c7da
					
				|  | @ -667,10 +667,15 @@ pub fn (mut p Parser) top_stmt() ast.Stmt { | |||
| 					return p.error('unexpected eof') | ||||
| 				} | ||||
| 				if_expr := p.if_expr(true) | ||||
| 				return ast.ExprStmt{ | ||||
| 				cur_stmt := ast.ExprStmt{ | ||||
| 					expr: if_expr | ||||
| 					pos: if_expr.pos | ||||
| 				} | ||||
| 				if comptime_if_expr_contains_top_stmt(if_expr) { | ||||
| 					return cur_stmt | ||||
| 				} else { | ||||
| 					return p.other_stmts(cur_stmt) | ||||
| 				} | ||||
| 			} | ||||
| 			.hash { | ||||
| 				return p.hash() | ||||
|  | @ -688,6 +693,40 @@ pub fn (mut p Parser) top_stmt() ast.Stmt { | |||
| 				return p.comment_stmt() | ||||
| 			} | ||||
| 			else { | ||||
| 				return p.other_stmts(ast.empty_stmt()) | ||||
| 			} | ||||
| 		} | ||||
| 		if p.should_abort { | ||||
| 			break | ||||
| 		} | ||||
| 	} | ||||
| 	// TODO remove dummy return statement
 | ||||
| 	// the compiler complains if it's not there
 | ||||
| 	return ast.empty_stmt() | ||||
| } | ||||
| 
 | ||||
| fn comptime_if_expr_contains_top_stmt(if_expr ast.IfExpr) bool { | ||||
| 	for branch in if_expr.branches { | ||||
| 		for stmt in branch.stmts { | ||||
| 			if stmt is ast.ExprStmt { | ||||
| 				if stmt.expr is ast.IfExpr { | ||||
| 					if !comptime_if_expr_contains_top_stmt(stmt.expr) { | ||||
| 						return false | ||||
| 					} | ||||
| 				} else if stmt.expr is ast.CallExpr { | ||||
| 					return false | ||||
| 				} | ||||
| 			} else if stmt is ast.AssignStmt { | ||||
| 				return false | ||||
| 			} else if stmt is ast.HashStmt { | ||||
| 				return true | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| 	return true | ||||
| } | ||||
| 
 | ||||
| fn (mut p Parser) other_stmts(cur_stmt ast.Stmt) ast.Stmt { | ||||
| 	p.inside_fn = true | ||||
| 	if p.pref.is_script && !p.pref.is_test { | ||||
| 		p.script_mode = true | ||||
|  | @ -699,6 +738,9 @@ pub fn (mut p Parser) top_stmt() ast.Stmt { | |||
| 
 | ||||
| 		p.open_scope() | ||||
| 		mut stmts := []ast.Stmt{} | ||||
| 		if cur_stmt != ast.empty_stmt() { | ||||
| 			stmts << cur_stmt | ||||
| 		} | ||||
| 		for p.tok.kind != .eof { | ||||
| 			stmts << p.stmt(false) | ||||
| 		} | ||||
|  | @ -721,15 +763,6 @@ pub fn (mut p Parser) top_stmt() ast.Stmt { | |||
| 	} else { | ||||
| 		return p.error('bad top level statement ' + p.tok.str()) | ||||
| 	} | ||||
| 			} | ||||
| 		} | ||||
| 		if p.should_abort { | ||||
| 			break | ||||
| 		} | ||||
| 	} | ||||
| 	// TODO remove dummy return statement
 | ||||
| 	// the compiler complains if it's not there
 | ||||
| 	return ast.empty_stmt() | ||||
| } | ||||
| 
 | ||||
| // TODO [if vfmt]
 | ||||
|  |  | |||
|  | @ -0,0 +1 @@ | |||
| others | ||||
|  | @ -0,0 +1,5 @@ | |||
| $if vinix { | ||||
| 	println('vinix') | ||||
| } $else { | ||||
| 	println('others') | ||||
| } | ||||
		Loading…
	
		Reference in New Issue