(path string)
| 348 | } |
| 349 | |
| 350 | func readInstructions(path string) ([]rawInstruction, error) { |
| 351 | file, err := os.Open(path) |
| 352 | if err != nil { |
| 353 | return nil, err |
| 354 | } |
| 355 | defer file.Close() |
| 356 | |
| 357 | scanner := bufio.NewScanner(file) |
| 358 | var instructions []rawInstruction |
| 359 | var current strings.Builder |
| 360 | var currentLine int |
| 361 | |
| 362 | for line := 1; scanner.Scan(); line++ { |
| 363 | text := scanner.Text() |
| 364 | trimmed := strings.TrimSpace(text) |
| 365 | if trimmed == "" || strings.HasPrefix(trimmed, "#") { |
| 366 | continue |
| 367 | } |
| 368 | |
| 369 | lineWithoutInlineComment := removeInlineComment(trimmed) |
| 370 | if lineWithoutInlineComment == "" { |
| 371 | continue |
| 372 | } |
| 373 | |
| 374 | if current.Len() == 0 { |
| 375 | currentLine = line |
| 376 | } else { |
| 377 | current.WriteString(" ") |
| 378 | } |
| 379 | linePart, carries := stripContinuation(lineWithoutInlineComment) |
| 380 | current.WriteString(linePart) |
| 381 | |
| 382 | if !carries { |
| 383 | instructions = append(instructions, rawInstruction{ |
| 384 | line: currentLine, |
| 385 | text: current.String(), |
| 386 | }) |
| 387 | current.Reset() |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | if err := scanner.Err(); err != nil { |
| 392 | return nil, err |
| 393 | } |
| 394 | if current.Len() != 0 { |
| 395 | return nil, errors.New("unterminated line continuation at end of file") |
| 396 | } |
| 397 | |
| 398 | return instructions, nil |
| 399 | } |
| 400 | |
| 401 | func stripContinuation(line string) (string, bool) { |
| 402 | if strings.HasSuffix(line, "\\") { |
no test coverage detected