| 1 | import semver // as sv |
| 2 | |
| 3 | enum Abc { |
| 4 | a |
| 5 | b // after a value |
| 6 | c |
| 7 | // between values |
| 8 | d |
| 9 | } |
| 10 | |
| 11 | struct User { |
| 12 | name string // name |
| 13 | // middle comment |
| 14 | age int |
| 15 | // last comment |
| 16 | // last comment2 |
| 17 | } |
| 18 | |
| 19 | fn main() { |
| 20 | u := User{ |
| 21 | name: 'Peter' |
| 22 | } |
| 23 | n := sizeof(User) |
| 24 | // else |
| 25 | // else { |
| 26 | // } |
| 27 | _ := User{ |
| 28 | name: 'Henry' // comment after name |
| 29 | // on the next line |
| 30 | age: 42 |
| 31 | // after age line |
| 32 | // after line2 |
| 33 | } |
| 34 | _ := User{ |
| 35 | // Just a comment |
| 36 | } |
| 37 | ////// |
| 38 | // / |
| 39 | // 123 |
| 40 | match 0 { |
| 41 | 0 { |
| 42 | 0 // comment after an expression inside match |
| 43 | } |
| 44 | else {} |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | fn assign_comments() { |
| 49 | a := 123 // comment after assign |
| 50 | b := 'foo' // also comment after assign |
| 51 | c := true |
| 52 | // Between two assigns |
| 53 | d := false |
| 54 | // at the end |
| 55 | } |
| 56 | |
| 57 | fn linebreaks_in_ascii_art_block_comments() { |
| 58 | /* |
| 59 | +++ |
| 60 | */ |
| 61 | /***** |
| 62 | +++ |
| 63 | *****/ |
| 64 | /**** |
| 65 | +++ |
| 66 | */ |
| 67 | /* |
| 68 | +++ |
| 69 | ****/ |
| 70 | } |
| 71 | |
| 72 | fn map_comments() { |
| 73 | mymap := { |
| 74 | // pre |
| 75 | `:`: 1 |
| 76 | `!`: 2 // after |
| 77 | // and between |
| 78 | `%`: 3 |
| 79 | // between |
| 80 | // between second |
| 81 | `$`: 4 |
| 82 | `&`: 5 |
| 83 | // post |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | fn ifs_comments_and_empty_lines() { |
| 88 | if true { |
| 89 | } |
| 90 | // some comment direct after an if without else |
| 91 | if false { |
| 92 | } else { |
| 93 | } |
| 94 | // some comment direct after an else |
| 95 | if false { |
| 96 | } |
| 97 | |
| 98 | // this is parsed as post_comment of the if but does not really belong there |
| 99 | // thereore keep the empty line |
| 100 | something_else() |
| 101 | } |
| 102 | |
| 103 | fn call_expr_with_single_line_comment_in_or_expr(arr []int) int { |
| 104 | i := arr[0] or { |
| 105 | arr.count() // 1 |
| 106 | } |
| 107 | return i |
| 108 | } |
| 109 | |