| 326 | } |
| 327 | |
| 328 | func parseInstruction(raw rawInstruction) (parsedInstruction, error) { |
| 329 | text := raw.text |
| 330 | trimmed := strings.TrimSpace(text) |
| 331 | if trimmed == "" { |
| 332 | return parsedInstruction{}, nil |
| 333 | } |
| 334 | idx := strings.IndexFunc(trimmed, unicode.IsSpace) |
| 335 | var keyword, args string |
| 336 | if idx == -1 { |
| 337 | keyword = trimmed |
| 338 | } else { |
| 339 | keyword = trimmed[:idx] |
| 340 | args = strings.TrimSpace(trimmed[idx:]) |
| 341 | } |
| 342 | return parsedInstruction{ |
| 343 | Line: raw.line, |
| 344 | Keyword: strings.ToUpper(keyword), |
| 345 | Args: args, |
| 346 | Raw: trimmed, |
| 347 | }, nil |
| 348 | } |
| 349 | |
| 350 | func readInstructions(path string) ([]rawInstruction, error) { |
| 351 | file, err := os.Open(path) |