vfmt: handle comments after last const field
							parent
							
								
									f5c245ceb8
								
							
						
					
					
						commit
						7476428def
					
				| 
						 | 
					@ -162,6 +162,7 @@ pub:
 | 
				
			||||||
	pos    token.Position
 | 
						pos    token.Position
 | 
				
			||||||
pub mut:
 | 
					pub mut:
 | 
				
			||||||
	fields []ConstField
 | 
						fields []ConstField
 | 
				
			||||||
 | 
						end_comments []Comment
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub struct StructDecl {
 | 
					pub struct StructDecl {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -677,8 +677,13 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		f.write('\n')
 | 
							f.write('\n')
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						f.comments_after_last_field(node.end_comments)
 | 
				
			||||||
 | 
						f.writeln('}\n')
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn (mut f Fmt) comments_after_last_field(comments []ast.Comment) {
 | 
				
			||||||
	// Handle comments after last field
 | 
						// Handle comments after last field
 | 
				
			||||||
	for comment in node.end_comments {
 | 
						for comment in comments {
 | 
				
			||||||
		f.indent++
 | 
							f.indent++
 | 
				
			||||||
		f.empty_line = true
 | 
							f.empty_line = true
 | 
				
			||||||
		f.comment(comment, {
 | 
							f.comment(comment, {
 | 
				
			||||||
| 
						 | 
					@ -687,7 +692,6 @@ pub fn (mut f Fmt) struct_decl(node ast.StructDecl) {
 | 
				
			||||||
		f.writeln('')
 | 
							f.writeln('')
 | 
				
			||||||
		f.indent--
 | 
							f.indent--
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	f.writeln('}\n')
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
 | 
					pub fn (mut f Fmt) interface_decl(node ast.InterfaceDecl) {
 | 
				
			||||||
| 
						 | 
					@ -1814,6 +1818,7 @@ pub fn (mut f Fmt) const_decl(it ast.ConstDecl) {
 | 
				
			||||||
		f.expr(field.expr)
 | 
							f.expr(field.expr)
 | 
				
			||||||
		f.writeln('')
 | 
							f.writeln('')
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						f.comments_after_last_field(it.end_comments)
 | 
				
			||||||
	f.indent--
 | 
						f.indent--
 | 
				
			||||||
	f.writeln(')\n')
 | 
						f.writeln(')\n')
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,4 @@
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						fsm_state_array = ['init', 'state_a', 'state_b', 'state_c', 'exit'] // use as a first half key for map see fsm_state_ev_fn, the same order as in enum FSM_state
 | 
				
			||||||
 | 
						fsm_event_array = ['ev1', 'ev2', 'ev3', 'ev4', 'ev5'] // use as a second half key for map see fsm_state_ev_fn, the same order as in enum FSM_event
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
| 
						 | 
					@ -1602,14 +1602,12 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	p.next() // (
 | 
						p.next() // (
 | 
				
			||||||
	mut fields := []ast.ConstField{}
 | 
						mut fields := []ast.ConstField{}
 | 
				
			||||||
	for p.tok.kind != .rpar {
 | 
					 | 
				
			||||||
	mut comments := []ast.Comment{}
 | 
						mut comments := []ast.Comment{}
 | 
				
			||||||
		for p.tok.kind == .comment {
 | 
						for {
 | 
				
			||||||
			comments << p.comment()
 | 
							comments = p.eat_comments()
 | 
				
			||||||
		if p.tok.kind == .rpar {
 | 
							if p.tok.kind == .rpar {
 | 
				
			||||||
			break
 | 
								break
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		pos := p.tok.position()
 | 
							pos := p.tok.position()
 | 
				
			||||||
		name := p.check_name()
 | 
							name := p.check_name()
 | 
				
			||||||
		if util.contains_capital(name) {
 | 
							if util.contains_capital(name) {
 | 
				
			||||||
| 
						 | 
					@ -1630,6 +1628,7 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		fields << field
 | 
							fields << field
 | 
				
			||||||
		p.global_scope.register(field.name, field)
 | 
							p.global_scope.register(field.name, field)
 | 
				
			||||||
 | 
							comments = []
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	p.top_level_statement_end()
 | 
						p.top_level_statement_end()
 | 
				
			||||||
	p.check(.rpar)
 | 
						p.check(.rpar)
 | 
				
			||||||
| 
						 | 
					@ -1637,6 +1636,7 @@ fn (mut p Parser) const_decl() ast.ConstDecl {
 | 
				
			||||||
		pos: start_pos.extend(end_pos)
 | 
							pos: start_pos.extend(end_pos)
 | 
				
			||||||
		fields: fields
 | 
							fields: fields
 | 
				
			||||||
		is_pub: is_pub
 | 
							is_pub: is_pub
 | 
				
			||||||
 | 
							end_comments: comments
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue