ParseFile will parse a whole G-Code file from the passed reader.
(r io.Reader)
| 11 | |
| 12 | // ParseFile will parse a whole G-Code file from the passed reader. |
| 13 | func ParseFile(r io.Reader) (*File, error) { |
| 14 | s := bufio.NewScanner(r) |
| 15 | |
| 16 | // prepare file |
| 17 | file := &File{} |
| 18 | |
| 19 | // read line by line |
| 20 | for s.Scan() { |
| 21 | // parse lin |
| 22 | line, err := ParseLine(s.Text()) |
| 23 | if err != nil { |
| 24 | return file, err |
| 25 | } |
| 26 | |
| 27 | // add line |
| 28 | file.Lines = append(file.Lines, line) |
| 29 | } |
| 30 | |
| 31 | // check error |
| 32 | if err := s.Err(); err != nil { |
| 33 | return file, err |
| 34 | } |
| 35 | |
| 36 | return file, nil |
| 37 | } |
| 38 | |
| 39 | // ParseLine will parse the specified string as a line of G-Codes. |
| 40 | func ParseLine(s string) (Line, error) { |