Skip to content

Parser fixes#20

Open
knivey wants to merge 5 commits into
chzchzchz:masterfrom
knivey:master
Open

Parser fixes#20
knivey wants to merge 5 commits into
chzchzchz:masterfrom
knivey:master

Conversation

@knivey
Copy link
Copy Markdown
Contributor

@knivey knivey commented Jan 3, 2025

No description provided.

Comment thread ascii/ascii.go Outdated
case '\n':
bold, underline, strikethrough, italic = false, false, false, false
cells = append(cells, row)
chompState, fg, bg = 0, -1, -1
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chompState, fg, bg, fgs, bgs := 0, -1, -1, 0, 0 so it matches the initialization at the beginning of the function

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in df8451a

Comment thread ascii/ascii.go
if v == ',' {
chompState, bg = 2, -1
continue
if len(dat) > i+1 && dat[i+1] >= '0' && dat[i+1] <= '9' {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

peaking ahead like this breaks the fsm formulation; I think the handling should be in case 2 as like if v >= ... {} else if bgs == 0 { chompState = 0; break }

Comment thread ascii/ascii_test.go
s := "hello \x0315,01hello"
// 012345 6789
a, _ := NewASCII(s)
if c := a.Get(2, 0); c == nil || c.Value != 'l' {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too much repetition-- idiomatic go uses a table driven test pattern like https://github.com/chzchzchz/sitbot/blob/master/msl/grammar_test.go#L49

Struct would be like

struct {
input string
col []int
expected []Cell
}

Driver would be like

for _, tt := range tests {
a, _ := NewAscii(tt.input);
for i := range tt.col {
c := a.Get(tt.col[i], 0)
if c == nil || c != tt.expected[i] {
t.Errorf("got %+v, want %+v at %d for %q",  c, tt.expected[i], tt.col[i], tt.input)
}
}

Comment thread ascii/ascii.go Outdated
}
case 1:
if v == '\x03' {
if fgs > 0 {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if fgs == 0 { bg = -1 }
fg, fgs = -1, 0
continue

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 5c52340

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants