Skip to content

Commit

Permalink
Better diagnostic upon abort for TAB char in input
Browse files Browse the repository at this point in the history
  • Loading branch information
dmullis authored and dmullis committed Jul 17, 2024
1 parent 029f2d5 commit d32cddf
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package goat

import (
"bufio"
"log"
"io"
"os"
)

type (
Expand Down Expand Up @@ -156,14 +158,19 @@ func NewCanvas(in io.Reader) (c Canvas) {
// https://go.dev/ref/spec#For_statements
// But yet, counterintuitively, type of lineStr[_index_] is 'byte'.
// https://go.dev/ref/spec#String_types
// XXXX Refactor to use []rune from above.
for _, r := range lineStr {
//if r > 255 {
// fmt.Printf("linestr=\"%s\"\n", lineStr)
// fmt.Printf("r == 0x%x\n", r)
//}
if r == ' ' {
panic("TAB character found on input")
file, isFile := in.(*os.File)
fileName := "unknown"
if isFile {
fileName = file.Name()
}
log.Panicf("\n\tFound TAB in %s, row %d, column %d\n",
fileName, height+1, w)
}
i := Index{w, height}
c.data[i] = r
Expand Down

0 comments on commit d32cddf

Please sign in to comment.