SgfParser 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.autotest +13 -0
- data/.gitignore +9 -0
- data/.rspec +3 -1
- data/.ruby-version +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG +12 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +42 -16
- data/README.md +97 -0
- data/SgfParser.gemspec +5 -8
- data/bin/sgf_indent.rb +5 -4
- data/examples/simple_iteration_of_games_in_a_directory.rb +3 -3
- data/lib/sgf.rb +18 -9
- data/lib/sgf/collection.rb +75 -0
- data/lib/sgf/collection_assembler.rb +32 -0
- data/lib/sgf/error.rb +1 -2
- data/lib/sgf/error_checkers.rb +15 -0
- data/lib/sgf/gametree.rb +64 -0
- data/lib/sgf/node.rb +139 -83
- data/lib/sgf/parser.rb +57 -157
- data/lib/sgf/parsing_tokens.rb +40 -0
- data/lib/sgf/properties.rb +80 -83
- data/lib/sgf/stream.rb +50 -0
- data/lib/sgf/variation.rb +16 -0
- data/lib/sgf/version.rb +1 -1
- data/lib/sgf/writer.rb +35 -37
- data/spec/acceptance_spec.rb +27 -0
- data/spec/collection_spec.rb +65 -0
- data/spec/gametree_spec.rb +99 -0
- data/spec/node_spec.rb +174 -68
- data/spec/parser_spec.rb +76 -74
- data/spec/spec_helper.rb +90 -9
- data/spec/variation_spec.rb +15 -0
- data/spec/writer_spec.rb +22 -21
- data/wercker.yml +21 -0
- metadata +77 -39
- data/.rvmrc +0 -1
- data/README.rdoc +0 -18
- data/lib/sgf/game.rb +0 -64
- data/lib/sgf/tree.rb +0 -77
- data/spec/game_spec.rb +0 -70
- data/spec/tree_spec.rb +0 -36
data/spec/spec_helper.rb
CHANGED
@@ -1,9 +1,86 @@
|
|
1
|
-
|
2
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
3
|
-
require 'sgf'
|
1
|
+
require_relative '../lib/sgf'
|
4
2
|
require 'fileutils'
|
5
|
-
require '
|
6
|
-
|
3
|
+
require 'pry' if ENV['PRY']
|
4
|
+
|
5
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
6
|
+
RSpec.configure do |config|
|
7
|
+
# rspec-expectations config goes here. You can use an alternate
|
8
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
9
|
+
# assertions if you prefer.
|
10
|
+
config.expect_with :rspec do |expectations|
|
11
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
12
|
+
# and `failure_message` of custom matchers include text for helper methods
|
13
|
+
# defined using `chain`, e.g.:
|
14
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
15
|
+
# # => "be bigger than 2 and smaller than 4"
|
16
|
+
# ...rather than:
|
17
|
+
# # => "be bigger than 2"
|
18
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
19
|
+
end
|
20
|
+
|
21
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
22
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
23
|
+
config.mock_with :rspec do |mocks|
|
24
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
25
|
+
# a real object. This is generally recommended, and will default to
|
26
|
+
# `true` in RSpec 4.
|
27
|
+
mocks.verify_partial_doubles = true
|
28
|
+
end
|
29
|
+
|
30
|
+
# The settings below are suggested to provide a good initial experience
|
31
|
+
# with RSpec, but feel free to customize to your heart's content.
|
32
|
+
|
33
|
+
# These two settings work together to allow you to limit a spec run
|
34
|
+
# to individual examples or groups you care about by tagging them with
|
35
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
36
|
+
# get run.
|
37
|
+
config.filter_run :focus
|
38
|
+
config.run_all_when_everything_filtered = true
|
39
|
+
|
40
|
+
# Allows RSpec to persist some state between runs in order to support
|
41
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
42
|
+
# you configure your source control system to ignore this file.
|
43
|
+
config.example_status_persistence_file_path = ".spec-examples.txt"
|
44
|
+
|
45
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
46
|
+
# recommended. For more details, see:
|
47
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
48
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
49
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
50
|
+
config.disable_monkey_patching!
|
51
|
+
|
52
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
53
|
+
# be too noisy due to issues in dependencies.
|
54
|
+
config.warnings = true
|
55
|
+
|
56
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
57
|
+
# file, and it's useful to allow more verbose output when running an
|
58
|
+
# individual spec file.
|
59
|
+
if config.files_to_run.one?
|
60
|
+
# Use the documentation formatter for detailed output,
|
61
|
+
# unless a formatter has already been configured
|
62
|
+
# (e.g. via a command-line flag).
|
63
|
+
config.default_formatter = 'doc'
|
64
|
+
end
|
65
|
+
|
66
|
+
# Print the 10 slowest examples and example groups at the
|
67
|
+
# end of the spec run, to help surface which specs are running
|
68
|
+
# particularly slow.
|
69
|
+
# config.profile_examples = 10
|
70
|
+
|
71
|
+
# Run specs in random order to surface order dependencies. If you find an
|
72
|
+
# order dependency and want to debug it, you can fix the order by providing
|
73
|
+
# the seed, which is printed after each run.
|
74
|
+
# --seed 1234
|
75
|
+
config.order = :random
|
76
|
+
|
77
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
78
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
79
|
+
# test failures related to randomization by passing the same `--seed` value
|
80
|
+
# as the one that triggered the failure.
|
81
|
+
Kernel.srand config.seed
|
82
|
+
end
|
83
|
+
|
7
84
|
|
8
85
|
ONE_LINE_SIMPLE_SAMPLE_SGF= "(;FF[4]AP[Primiview:3.1]GM[1]SZ[19](;DD[kq:os][dq:hs]AR[aa:sc][sa:ac][aa:sa][aa:ac][cd:cj][gd:md][fh:ij][kj:nh]LN[pj:pd][nf:ff][ih:fj][kh:nj]C[Arrows, lines and dimmed points.])(;B[qd]N[Style & text type]))(;FF[4]AP[Primiview:3.1]GM[1]SZ[19])"
|
9
86
|
|
@@ -20,11 +97,15 @@ SIMPLIFIED_SAMPLE_SGF= <<EOF
|
|
20
97
|
EOF
|
21
98
|
|
22
99
|
def get_first_game_from file
|
23
|
-
|
24
|
-
|
100
|
+
collection = get_collection_from file
|
101
|
+
collection.gametrees.first
|
25
102
|
end
|
26
103
|
|
27
|
-
def
|
104
|
+
def get_collection_from file
|
28
105
|
parser = SGF::Parser.new
|
29
106
|
parser.parse File.read(file)
|
30
|
-
end
|
107
|
+
end
|
108
|
+
|
109
|
+
def full_path_to_file(relative_file_path, starting_point:)
|
110
|
+
File.expand_path(File.join(File.dirname(starting_point), relative_file_path))
|
111
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module SGF
|
4
|
+
RSpec.describe Variation do
|
5
|
+
subject { Variation.new }
|
6
|
+
it 'begins with a Node' do
|
7
|
+
expect(subject.root).to be_an_instance_of Node
|
8
|
+
end
|
9
|
+
|
10
|
+
it "accepts more nodes" do
|
11
|
+
subject.append Node.new
|
12
|
+
expect(subject.size).to eq 2
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/spec/writer_spec.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe
|
3
|
+
RSpec.describe SGF::Writer do
|
4
|
+
|
5
|
+
let(:parser) { SGF::Parser.new }
|
4
6
|
|
5
7
|
TEMP_FILE = 'spec/data/temp.sgf'
|
6
8
|
|
7
|
-
after
|
8
|
-
FileUtils.rm_f TEMP_FILE
|
9
|
-
end
|
9
|
+
after { FileUtils.rm_f TEMP_FILE }
|
10
10
|
|
11
11
|
it "should save a simple tree properly" do
|
12
12
|
sgf = File.read('spec/data/simple.sgf')
|
@@ -32,17 +32,17 @@ describe "SGF::Writer" do
|
|
32
32
|
|
33
33
|
it "should indent a simple SGF nicely" do
|
34
34
|
sgf = save_to_temp_file_and_read '(;FF[4])'
|
35
|
-
sgf.
|
35
|
+
expect(sgf).to eq "\n(\n ;FF[4]\n)"
|
36
36
|
end
|
37
37
|
|
38
38
|
it "should indent a one-node SGF with two properties" do
|
39
39
|
sgf = save_to_temp_file_and_read '(;FF[4]PW[Cho Chikun])'
|
40
|
-
sgf.
|
40
|
+
expect(sgf).to eq "\n(\n ;FF[4]\n PW[Cho Chikun]\n)"
|
41
41
|
end
|
42
42
|
|
43
43
|
it "should indent two nodes on same column" do
|
44
44
|
sgf = save_to_temp_file_and_read '(;FF[4];PB[qq])'
|
45
|
-
sgf.
|
45
|
+
expect(sgf).to eq "\n(\n ;FF[4]\n ;PB[qq]\n)"
|
46
46
|
end
|
47
47
|
|
48
48
|
it "should indent branches further" do
|
@@ -58,7 +58,7 @@ describe "SGF::Writer" do
|
|
58
58
|
;PB[qa]
|
59
59
|
)
|
60
60
|
)}
|
61
|
-
sgf.
|
61
|
+
expect(sgf).to eq expected
|
62
62
|
end
|
63
63
|
|
64
64
|
it "should indent two gametrees" do
|
@@ -73,25 +73,26 @@ describe "SGF::Writer" do
|
|
73
73
|
;FF[4]
|
74
74
|
;PB[dd]
|
75
75
|
)}
|
76
|
-
sgf.
|
76
|
+
expect(sgf).to eq expected
|
77
77
|
end
|
78
78
|
|
79
79
|
private
|
80
80
|
|
81
81
|
def parse_save_load_and_compare_to_saved string
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
tree2 = get_tree_from TEMP_FILE
|
86
|
-
tree2.should == tree
|
82
|
+
collection = parse_and_save string
|
83
|
+
collection2 = get_collection_from TEMP_FILE
|
84
|
+
expect(collection2).to eq collection
|
87
85
|
end
|
88
86
|
|
87
|
+
def save_to_temp_file_and_read string
|
88
|
+
parse_and_save string
|
89
|
+
File.read TEMP_FILE
|
90
|
+
end
|
89
91
|
|
90
|
-
def
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
sgf
|
92
|
+
def parse_and_save string
|
93
|
+
collection = parser.parse string
|
94
|
+
collection.save TEMP_FILE
|
95
|
+
collection
|
95
96
|
end
|
96
97
|
|
97
|
-
end
|
98
|
+
end
|
data/wercker.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
box: wercker/ruby
|
2
|
+
# Build definition
|
3
|
+
build:
|
4
|
+
# The steps that will be executed on build
|
5
|
+
steps:
|
6
|
+
# A step that executes `bundle install` command
|
7
|
+
- bundle-install
|
8
|
+
|
9
|
+
# A custom script step, name value is used in the UI
|
10
|
+
# and the code value contains the command that get executed
|
11
|
+
- script:
|
12
|
+
name: echo ruby information
|
13
|
+
code: |
|
14
|
+
echo "ruby version $(ruby --version) running"
|
15
|
+
echo "from location $(which ruby)"
|
16
|
+
echo -p "gem list: $(gem list)"
|
17
|
+
|
18
|
+
# Add more steps here:
|
19
|
+
- script:
|
20
|
+
name: rspec
|
21
|
+
code: bundle exec rake spec
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: SgfParser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 3.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Aldric Giacomoni
|
@@ -13,122 +12,161 @@ date: 2011-08-01 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rspec
|
16
|
-
requirement:
|
17
|
-
none: false
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
|
-
version_requirements:
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
25
27
|
- !ruby/object:Gem::Dependency
|
26
|
-
name:
|
27
|
-
requirement:
|
28
|
-
none: false
|
28
|
+
name: simplecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
|
-
- -
|
31
|
+
- - ">="
|
31
32
|
- !ruby/object:Gem::Version
|
32
33
|
version: '0'
|
33
34
|
type: :development
|
34
35
|
prerelease: false
|
35
|
-
version_requirements:
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
36
41
|
- !ruby/object:Gem::Dependency
|
37
42
|
name: rake
|
38
|
-
requirement:
|
39
|
-
none: false
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
40
44
|
requirements:
|
41
|
-
- -
|
45
|
+
- - ">="
|
42
46
|
- !ruby/object:Gem::Version
|
43
47
|
version: '0'
|
44
48
|
type: :development
|
45
49
|
prerelease: false
|
46
|
-
version_requirements:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
47
55
|
- !ruby/object:Gem::Dependency
|
48
56
|
name: rdoc
|
49
|
-
requirement:
|
50
|
-
none: false
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
51
58
|
requirements:
|
52
|
-
- -
|
59
|
+
- - ">="
|
53
60
|
- !ruby/object:Gem::Version
|
54
61
|
version: '0'
|
55
62
|
type: :development
|
56
63
|
prerelease: false
|
57
|
-
version_requirements:
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
58
83
|
description: SGF::Parser does standard stream parsing of the SGF file, instead of
|
59
|
-
using an AG or some other auto-generated
|
60
|
-
|
84
|
+
using an AG or some other auto-generated parser. It is therefore faster to use.
|
85
|
+
It also intends to be very object-oriented and hopefully will also be easier to
|
86
|
+
use.
|
61
87
|
email: trevoke@gmail.com
|
62
88
|
executables:
|
63
89
|
- sgf_indent.rb
|
64
90
|
extensions: []
|
65
91
|
extra_rdoc_files:
|
66
92
|
- LICENSE
|
67
|
-
- README.
|
93
|
+
- README.md
|
68
94
|
files:
|
69
|
-
- .
|
70
|
-
- .
|
71
|
-
- .
|
72
|
-
- .
|
95
|
+
- ".autotest"
|
96
|
+
- ".document"
|
97
|
+
- ".gitignore"
|
98
|
+
- ".rspec"
|
99
|
+
- ".ruby-version"
|
100
|
+
- ".travis.yml"
|
101
|
+
- CHANGELOG
|
73
102
|
- Gemfile
|
74
103
|
- Gemfile.lock
|
75
104
|
- LICENSE
|
76
|
-
- README.
|
105
|
+
- README.md
|
77
106
|
- Rakefile
|
78
107
|
- SgfParser.gemspec
|
79
108
|
- bin/sgf_indent.rb
|
80
109
|
- examples/simple_iteration_of_games_in_a_directory.rb
|
81
110
|
- lib/sgf.rb
|
111
|
+
- lib/sgf/collection.rb
|
112
|
+
- lib/sgf/collection_assembler.rb
|
82
113
|
- lib/sgf/error.rb
|
83
|
-
- lib/sgf/
|
114
|
+
- lib/sgf/error_checkers.rb
|
115
|
+
- lib/sgf/gametree.rb
|
84
116
|
- lib/sgf/node.rb
|
85
117
|
- lib/sgf/parser.rb
|
118
|
+
- lib/sgf/parsing_tokens.rb
|
86
119
|
- lib/sgf/properties.rb
|
87
|
-
- lib/sgf/
|
120
|
+
- lib/sgf/stream.rb
|
121
|
+
- lib/sgf/variation.rb
|
88
122
|
- lib/sgf/version.rb
|
89
123
|
- lib/sgf/writer.rb
|
124
|
+
- spec/acceptance_spec.rb
|
125
|
+
- spec/collection_spec.rb
|
90
126
|
- spec/data/example1.sgf
|
91
127
|
- spec/data/ff4_ex.sgf
|
92
128
|
- spec/data/redrose-tartrate.sgf
|
93
129
|
- spec/data/simple.sgf
|
94
|
-
- spec/
|
130
|
+
- spec/gametree_spec.rb
|
95
131
|
- spec/node_spec.rb
|
96
132
|
- spec/parser_spec.rb
|
97
133
|
- spec/spec_helper.rb
|
98
|
-
- spec/
|
134
|
+
- spec/variation_spec.rb
|
99
135
|
- spec/writer_spec.rb
|
136
|
+
- wercker.yml
|
100
137
|
homepage: http://github.com/Trevoke/SGFParser
|
101
138
|
licenses: []
|
139
|
+
metadata: {}
|
102
140
|
post_install_message:
|
103
141
|
rdoc_options: []
|
104
142
|
require_paths:
|
105
143
|
- lib
|
106
144
|
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
-
none: false
|
108
145
|
requirements:
|
109
|
-
- -
|
146
|
+
- - ">="
|
110
147
|
- !ruby/object:Gem::Version
|
111
148
|
version: '0'
|
112
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
150
|
requirements:
|
115
|
-
- -
|
151
|
+
- - ">="
|
116
152
|
- !ruby/object:Gem::Version
|
117
153
|
version: '0'
|
118
154
|
requirements: []
|
119
155
|
rubyforge_project:
|
120
|
-
rubygems_version:
|
156
|
+
rubygems_version: 2.5.1
|
121
157
|
signing_key:
|
122
|
-
specification_version:
|
158
|
+
specification_version: 4
|
123
159
|
summary: A library that parses and saves SGF (Smart Game Format) files.
|
124
160
|
test_files:
|
161
|
+
- spec/acceptance_spec.rb
|
162
|
+
- spec/collection_spec.rb
|
125
163
|
- spec/data/example1.sgf
|
126
164
|
- spec/data/ff4_ex.sgf
|
127
165
|
- spec/data/redrose-tartrate.sgf
|
128
166
|
- spec/data/simple.sgf
|
129
|
-
- spec/
|
167
|
+
- spec/gametree_spec.rb
|
130
168
|
- spec/node_spec.rb
|
131
169
|
- spec/parser_spec.rb
|
132
170
|
- spec/spec_helper.rb
|
133
|
-
- spec/
|
171
|
+
- spec/variation_spec.rb
|
134
172
|
- spec/writer_spec.rb
|
data/.rvmrc
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
rvm 1.9.3@sgfparser
|
data/README.rdoc
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
=INFORMATION
|
2
|
-
Author: Aldric Giacomoni || Email : trevoke@gmail.com
|
3
|
-
|
4
|
-
Build status {<img src="https://secure.travis-ci.org/Trevoke/SGFParser.png" />}[http://travis-ci.org/Trevoke/SGFParser]
|
5
|
-
|
6
|
-
Are you using this gem? Is there functionality you wish it had? Is something hard to do?
|
7
|
-
|
8
|
-
Let me know and I'll make it possible, or easier!
|
9
|
-
|
10
|
-
SGF: FF4 - may support earlier ones as well, but untested.
|
11
|
-
|
12
|
-
Ruby: >=1.8.7 (may work with 1.8.6)
|
13
|
-
|
14
|
-
WARNING: An implementation requirement is to make sure any closing bracket ']' inside a comment is escaped: '\\]'. If this is not done, you will be one sad panda! This library will do this for you upon saving, but will most likely die horribly when parsing anything which does not follow this rule.
|
15
|
-
|
16
|
-
I'm honestly hoping that this is and remains the fastest SGF parser in Ruby. On my desktop, loading the SGF library and parsing Kogo's Joseki dictionary takes a little under six seconds.
|
17
|
-
|
18
|
-
Documentation available at the Github wiki: https://github.com/Trevoke/SGFParser/wiki
|