# SGF Parser library released

**URL:** <https://www.ruby-forum.com/t/sgf-parser-library-released/176657>\
**Category:** Ruby\
**Created:** [October 4, 2009, 7:21am UTC](https://www.ruby-forum.com/t/sgf-parser-library-released/176657 "2009-10-04T07:21:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [October 4, 2009, 7:21am UTC](https://www.ruby-forum.com/t/sgf-parser-library-released/176657/1 "2009-10-04T07:21:19Z")

</div>

> **[GitHub - Trevoke/SGFParser: A Ruby library to parse SGF (Smart Game Format)...](https://github.com/Trevoke/SGFParser)**
>
> A Ruby library to parse SGF (Smart Game Format) files, best-known for holding weiqi / go game records - GitHub - Trevoke/SGFParser: A Ruby library to parse SGF (Smart Game Format) files, best-known...

SGF stands for Smart Game Format, it’s best known for storing go games,  
but also stores chess, backgammon and a whole bunch of other similar  
games.

I’ve got a ‘working’ version of an SGF parser. I have issues with KGS  
records, I believe it’s due to the way I handle ‘]’ characters within  
comments.

If you have time, please take a look at the code (it’s quite short) and  
let me know what you think, or whatever suggestions you may have.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [October 4, 2009, 10:14am UTC](https://www.ruby-forum.com/t/sgf-parser-library-released/176657/2 "2009-10-04T10:14:50Z")

</div>

On Oct 3, 2009, at 22:21 , Aldric G. wrote:

> If you have time, please take a look at the code (it’s quite short)  
> and  
> let me know what you think, or whatever suggestions you may have.

Looks neat, but it really needs tests. Then it’ll go from “working” to  
working.

require ‘test/unit’

class TestSGFTree \< Test::Unit::TestCase  
def test\_load\_string  
input = “something”  
expected = SGFNode.new “…”

```
 assert_equal expected, SGFTree.new.load_string(something)

```

end  
end

# and build it out from there

P.S. You’re mixing tabs and spaces and your indentation looks  
absolutely wack as a result. Stick to 2 spaces per indent.

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [October 5, 2009, 2:15pm UTC](https://www.ruby-forum.com/t/sgf-parser-library-released/176657/3 "2009-10-05T14:15:58Z")

</div>

Ryan D. wrote:

> Looks neat, but it really needs tests. Then it’ll go from “working” to  
> working.
> 
> P.S. You’re mixing tabs and spaces and your indentation looks  
> absolutely wack as a result. Stick to 2 spaces per indent.

Hi Ryan, thanks for the input. I’ll fix that indentation. Do you know  
any particular place to read up on how to create tests, or will any  
appropriate google search get me something decent?

---

<div class="post-metadata">

**Author:** ![trevoke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@trevoke](https://www.ruby-forum.com/u/trevoke)\
**Post date:** [October 12, 2009, 6:54pm UTC](https://www.ruby-forum.com/t/sgf-parser-library-released/176657/4 "2009-10-12T18:54:49Z")

</div>

Ryan D. wrote:

> Looks neat, but it really needs tests. Then it’ll go from “working” to  
> working.

Ryan, or whomever else may be reading this, I’ve done some updates to  
the code, and it actually works as it should now, which is always nice.  
I’ve also implemented some basic cucumber testing, which turned out to  
almost be fun 🙂  
The library, again, is at [GitHub - Trevoke/SGFParser: A Ruby library to parse SGF (Smart Game Format) files, best-known for holding weiqi / go game records](http://github.com/Trevoke/SGFParser)

I was wondering if anyone had any better ideas for the implementation -  
the SGF format is pretty much a tree, and so I’ve basically implemented  
a linked list. It’s not particularly ruby-ish and that bugs me, but I  
couldn’t think of an elegant solution. Any ideas, however wacky they may  
be?
