cgraph: rewrite scanner to use an agxbuf
This is a reattempt of
2d7852a049b729fb0db71c5a8ef2366215ae2035. The original
change introduced a bug where unterminated strings (both `qstring` and
`hstring`) would not reset the buffer, causing an assertion failure the next
time a graph was parsed. This failed attempt was reverted in
16a04fe061bf6c9b3fe5fdc6250255a9b55cd337.
The approach taken here is essentially the same as
2d7852a049b729fb0db71c5a8ef2366215ae2035, except that it resets the buffer on
error conditions. This appears to be the only way to exit the `qstring` and
`hstring` states that was not covered by the original attempt.
Gitlab: related to #2272