1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
|
package main
var keywords = []string{"break", "default", "func", "select", "chan", "else", "const", "fallthrough", "type", "continue", "var", "goto", "defer", "go", "range"}
var identifiers = []string{"bool", "byte", "complex64", "complex128", "error", "float32", "float64", "int", "int8", "int16", "int32", "int64", "rune", "string", "uint", "uint8", "uint16", "uint32", "uint64", "uintptr", "true", "false", "iota", "nil", "err"}
var groups = []struct {
name string // name of the function / method
comment string // comment appended to name
variadic bool // is the parameter variadic?
opening string // opening token
closing string // closing token
separator string // separator token
multi bool // items are always on multiple lines
parameters []string // parameter names
preventFunc bool // prevent the fooFunc function/method
}{
{
name: "Parens",
comment: "renders a single item in parenthesis. Use for type conversion or to specify evaluation order.",
variadic: false,
opening: "(",
closing: ")",
separator: "",
parameters: []string{"item"},
},
{
name: "List",
comment: "renders a comma separated list. Use for multiple return functions.",
variadic: true,
opening: "",
closing: "",
separator: ",",
parameters: []string{"items"},
},
{
name: "Values",
comment: "renders a comma separated list enclosed by curly braces. Use for slice or composite literals.",
variadic: true,
opening: "{",
closing: "}",
separator: ",",
parameters: []string{"values"},
},
{
name: "Index",
comment: "renders a colon separated list enclosed by square brackets. Use for array / slice indexes and definitions.",
variadic: true,
opening: "[",
closing: "]",
separator: ":",
parameters: []string{"items"},
},
{
name: "Block",
comment: "renders a statement list enclosed by curly braces. Use for code blocks. A special case applies when used directly after Case or Default, where the braces are omitted. This allows use in switch and select statements.",
variadic: true,
opening: "{",
closing: "}",
multi: true,
parameters: []string{"statements"},
},
{
name: "Defs",
comment: "renders a statement list enclosed in parenthesis. Use for definition lists.",
variadic: true,
opening: "(",
closing: ")",
multi: true,
parameters: []string{"definitions"},
},
{
name: "Call",
comment: "renders a comma separated list enclosed by parenthesis. Use for function calls.",
variadic: true,
opening: "(",
closing: ")",
separator: ",",
parameters: []string{"params"},
},
{
name: "Params",
comment: "renders a comma separated list enclosed by parenthesis. Use for function parameters and method receivers.",
variadic: true,
opening: "(",
closing: ")",
separator: ",",
parameters: []string{"params"},
},
{
name: "Assert",
comment: "renders a period followed by a single item enclosed by parenthesis. Use for type assertions.",
variadic: false,
opening: ".(",
closing: ")",
separator: "",
parameters: []string{"typ"},
},
{
name: "Map",
comment: "renders the keyword followed by a single item enclosed by square brackets. Use for map definitions.",
variadic: false,
opening: "map[",
closing: "]",
separator: "",
parameters: []string{"typ"},
},
{
name: "If",
comment: "renders the keyword followed by a semicolon separated list.",
variadic: true,
opening: "if ",
closing: "",
separator: ";",
parameters: []string{"conditions"},
},
{
name: "Return",
comment: "renders the keyword followed by a comma separated list.",
variadic: true,
opening: "return ",
closing: "",
separator: ",",
parameters: []string{"results"},
},
{
name: "For",
comment: "renders the keyword followed by a semicolon separated list.",
variadic: true,
opening: "for ",
closing: "",
separator: ";",
parameters: []string{"conditions"},
},
{
name: "Switch",
comment: "renders the keyword followed by a semicolon separated list.",
variadic: true,
opening: "switch ",
closing: "",
separator: ";",
parameters: []string{"conditions"},
},
{
name: "Interface",
comment: "renders the keyword followed by a method list enclosed by curly braces.",
variadic: true,
opening: "interface{",
closing: "}",
multi: true,
parameters: []string{"methods"},
},
{
name: "Struct",
comment: "renders the keyword followed by a field list enclosed by curly braces.",
variadic: true,
opening: "struct{",
closing: "}",
multi: true,
parameters: []string{"fields"},
},
{
name: "Case",
comment: "renders the keyword followed by a comma separated list.",
variadic: true,
opening: "case ",
closing: ":",
separator: ",",
parameters: []string{"cases"},
},
{
name: "Append",
comment: "renders the append built-in function.",
variadic: true,
opening: "append(",
closing: ")",
separator: ",",
parameters: []string{"args"},
},
{
name: "Cap",
comment: "renders the cap built-in function.",
variadic: false,
opening: "cap(",
closing: ")",
separator: ",",
parameters: []string{"v"},
},
{
name: "Close",
comment: "renders the close built-in function.",
variadic: false,
opening: "close(",
closing: ")",
separator: ",",
parameters: []string{"c"},
},
{
name: "Complex",
comment: "renders the complex built-in function.",
variadic: false,
opening: "complex(",
closing: ")",
separator: ",",
parameters: []string{"r", "i"},
},
{
name: "Copy",
comment: "renders the copy built-in function.",
variadic: false,
opening: "copy(",
closing: ")",
separator: ",",
parameters: []string{"dst", "src"},
},
{
name: "Delete",
comment: "renders the delete built-in function.",
variadic: false,
opening: "delete(",
closing: ")",
separator: ",",
parameters: []string{"m", "key"},
},
{
name: "Imag",
comment: "renders the imag built-in function.",
variadic: false,
opening: "imag(",
closing: ")",
separator: ",",
parameters: []string{"c"},
},
{
name: "Len",
comment: "renders the len built-in function.",
variadic: false,
opening: "len(",
closing: ")",
separator: ",",
parameters: []string{"v"},
},
{
name: "Make",
comment: "renders the make built-in function. The final parameter of the make function is optional, so it is represented by a variadic parameter list.",
variadic: true,
opening: "make(",
closing: ")",
separator: ",",
parameters: []string{"args"},
preventFunc: true, // the underlying function is not variadic, so we prevent the MakeFunc variation
},
{
name: "New",
comment: "renders the new built-in function.",
variadic: false,
opening: "new(",
closing: ")",
separator: ",",
parameters: []string{"typ"},
},
{
name: "Panic",
comment: "renders the panic built-in function.",
variadic: false,
opening: "panic(",
closing: ")",
separator: ",",
parameters: []string{"v"},
},
{
name: "Print",
comment: "renders the print built-in function.",
variadic: true,
opening: "print(",
closing: ")",
separator: ",",
parameters: []string{"args"},
},
{
name: "Println",
comment: "renders the println built-in function.",
variadic: true,
opening: "println(",
closing: ")",
separator: ",",
parameters: []string{"args"},
},
{
name: "Real",
comment: "renders the real built-in function.",
variadic: false,
opening: "real(",
closing: ")",
separator: ",",
parameters: []string{"c"},
},
{
name: "Recover",
comment: "renders the recover built-in function.",
variadic: false,
opening: "recover(",
closing: ")",
separator: ",",
parameters: []string{},
},
}
|