bracket_notation 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/Manifest +17 -1
- data/README.rdoc +31 -7
- data/Rakefile +2 -1
- data/bracket_notation.gemspec +9 -6
- data/init.rb +1 -1
- data/lib/bracket_notation.rb +3 -1
- data/lib/bracket_notation/evaluator.rb +2 -1
- data/lib/bracket_notation/expressions.rb +1 -1
- data/lib/bracket_notation/expressions/expression.rb +1 -1
- data/lib/bracket_notation/expressions/identifier.rb +1 -1
- data/lib/bracket_notation/expressions/terminal.rb +1 -1
- data/lib/bracket_notation/geometry.rb +31 -0
- data/lib/bracket_notation/geometry/point.rb +69 -0
- data/lib/bracket_notation/geometry/rect.rb +64 -0
- data/lib/bracket_notation/geometry/size.rb +69 -0
- data/lib/bracket_notation/parser.rb +1 -1
- data/lib/bracket_notation/scanner.rb +1 -1
- data/lib/bracket_notation/token.rb +1 -1
- data/lib/bracket_notation/version.rb +3 -3
- data/lib/bracket_notation/views.rb +33 -0
- data/lib/bracket_notation/views/branch.rb +40 -0
- data/lib/bracket_notation/views/leaf.rb +34 -0
- data/lib/bracket_notation/views/node.rb +152 -0
- data/lib/bracket_notation/views/tree.rb +181 -0
- data/test/functional/evaluator_test.rb +1 -1
- data/test/functional/node_test.rb +132 -0
- data/test/functional/parser_test.rb +1 -1
- data/test/functional/scanner_test.rb +1 -1
- data/test/functional/tree_test.rb +67 -0
- data/test/integration/layout_test.rb +151 -0
- data/test/integration/parsing_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/expression_test.rb +1 -1
- data/test/unit/point_test.rb +69 -0
- data/test/unit/rect_test.rb +58 -0
- data/test/unit/size_test.rb +69 -0
- data/test/unit/token_test.rb +1 -1
- metadata +48 -7
data/CHANGELOG
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
= Version History
|
2
2
|
|
3
|
+
== 1.1.0 / 2011-03-23:
|
4
|
+
|
5
|
+
* Added basic geometry classes: Point, Size, Rect
|
6
|
+
* Added basic view classes: Tree, Node, Branch, Leaf
|
7
|
+
* Added tests for the new classes and new behavior, including unit tests for the
|
8
|
+
geometry classes, functional tests for the view classes, and an integration
|
9
|
+
test for the tree layout algorithm
|
10
|
+
|
3
11
|
== 1.0.5 / 2011-03-09:
|
4
12
|
|
5
13
|
* Removed an extraneous space from the #pretty_print output that has always
|
data/Manifest
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
CHANGELOG
|
2
2
|
COPYING
|
3
|
+
Manifest
|
3
4
|
README.rdoc
|
4
5
|
Rakefile
|
6
|
+
bracket_notation.gemspec
|
5
7
|
init.rb
|
6
8
|
lib/bracket_notation.rb
|
7
9
|
lib/bracket_notation/evaluator.rb
|
@@ -9,15 +11,29 @@ lib/bracket_notation/expressions.rb
|
|
9
11
|
lib/bracket_notation/expressions/expression.rb
|
10
12
|
lib/bracket_notation/expressions/identifier.rb
|
11
13
|
lib/bracket_notation/expressions/terminal.rb
|
14
|
+
lib/bracket_notation/geometry.rb
|
15
|
+
lib/bracket_notation/geometry/point.rb
|
16
|
+
lib/bracket_notation/geometry/rect.rb
|
17
|
+
lib/bracket_notation/geometry/size.rb
|
12
18
|
lib/bracket_notation/parser.rb
|
13
19
|
lib/bracket_notation/scanner.rb
|
14
20
|
lib/bracket_notation/token.rb
|
15
21
|
lib/bracket_notation/version.rb
|
22
|
+
lib/bracket_notation/views.rb
|
23
|
+
lib/bracket_notation/views/branch.rb
|
24
|
+
lib/bracket_notation/views/leaf.rb
|
25
|
+
lib/bracket_notation/views/node.rb
|
26
|
+
lib/bracket_notation/views/tree.rb
|
16
27
|
test/functional/evaluator_test.rb
|
28
|
+
test/functional/node_test.rb
|
17
29
|
test/functional/parser_test.rb
|
18
30
|
test/functional/scanner_test.rb
|
31
|
+
test/functional/tree_test.rb
|
32
|
+
test/integration/layout_test.rb
|
19
33
|
test/integration/parsing_test.rb
|
20
34
|
test/test_helper.rb
|
21
35
|
test/unit/expression_test.rb
|
36
|
+
test/unit/point_test.rb
|
37
|
+
test/unit/rect_test.rb
|
38
|
+
test/unit/size_test.rb
|
22
39
|
test/unit/token_test.rb
|
23
|
-
Manifest
|
data/README.rdoc
CHANGED
@@ -9,16 +9,16 @@ BracketNotation was inspired by Yoichiro Hasebe's RSyntaxTree[http://yohasebe.co
|
|
9
9
|
and small portions of his code have been incorporated in the parser.
|
10
10
|
|
11
11
|
Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
12
|
-
Copyright:: Copyright (c) 2010 Cody Brimhall
|
12
|
+
Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
13
13
|
License:: Distributed under the terms of the GNU General Public License, v. 3
|
14
14
|
|
15
|
-
== Using
|
15
|
+
== Using the Parser
|
16
16
|
|
17
|
-
To use BracketNotation, simply initialize a Parser instance with the
|
18
|
-
want to parse, and call the #parse method. Parser performs some basic
|
19
|
-
before attempting to evaluate the string. If validation fails, Parser
|
20
|
-
ValidationError. If the evaluator encounters a syntax error in the
|
21
|
-
raises an EvaluationError.
|
17
|
+
To use the BracketNotation parser, simply initialize a Parser instance with the
|
18
|
+
string you want to parse, and call the #parse method. Parser performs some basic
|
19
|
+
validation before attempting to evaluate the string. If validation fails, Parser
|
20
|
+
raises a ValidationError. If the evaluator encounters a syntax error in the
|
21
|
+
string, it raises an EvaluationError.
|
22
22
|
|
23
23
|
require 'bracket_notation'
|
24
24
|
include BracketNotation
|
@@ -45,6 +45,30 @@ raises an EvaluationError.
|
|
45
45
|
puts "Evaluation failed: #{$!}"
|
46
46
|
end
|
47
47
|
|
48
|
+
== Using the Geometry Classes
|
49
|
+
|
50
|
+
The geometry classes are a set of simple constructions to make working with
|
51
|
+
layouts in a cartesian plane a little easier. The three classes are Point, Size
|
52
|
+
and Rect; they are immutable, and their use is straightforward:
|
53
|
+
|
54
|
+
require 'bracket_notation'
|
55
|
+
include BracketNotation::Geometry
|
56
|
+
|
57
|
+
point1 = Point.new(0, 0) => {x: 0, y: 0}
|
58
|
+
point2 = point1.point_by_adding_to_x(42) => {x: 42, y: 0}
|
59
|
+
size1 = Size.new(0, 0) => {width: 0, height: 0}
|
60
|
+
size2 = size1.size_by_adding_to_height(42) => {width: 0, height: 42}
|
61
|
+
rect1 = Rect.new(point1, size2) => {origin: {x: 0, y: 0}, size: {width: 0, height: 42}}
|
62
|
+
rect2 = Rect.new(42, 42, 42, 42) => {origin: {x: 42, y: 42}, size: {width: 42, height: 42}}
|
63
|
+
|
64
|
+
== Using the View Classes
|
65
|
+
|
66
|
+
In order to make it easier to represent a tree visually, BracketNotation
|
67
|
+
includes some basic view classes: Node (and its subclasses Branch and Leaf) and
|
68
|
+
Tree. These classes implement a basic n-ary tree, with methods and attributes
|
69
|
+
for laying the nodes out on a cartesian plane and tracking their locations and
|
70
|
+
dimensions. See the documentation for Tree and Node for details.
|
71
|
+
|
48
72
|
== Bugs, Feature Requests, Et Cetera
|
49
73
|
|
50
74
|
If you have any bugs, feature requests, or glowing praise, you can
|
data/Rakefile
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
# and small portions of his code have been incorporated in the parser.
|
24
24
|
#
|
25
25
|
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
-
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
26
|
+
# Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
27
27
|
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
28
|
|
29
29
|
($:.unshift File.expand_path(File.join( File.dirname(__FILE__), 'lib' ))).uniq!
|
@@ -39,4 +39,5 @@ Echoe.new('bracket_notation', BracketNotation::Version) do |p|
|
|
39
39
|
p.email = "zbrimhall@gmail.com"
|
40
40
|
p.ignore_pattern = %w(tmp/* script/* *.bbprojectd/*)
|
41
41
|
p.development_dependencies = ['shoulda >=2.11.3']
|
42
|
+
p.runtime_dependencies = ['rmagick >=2.13.1']
|
42
43
|
end
|
data/bracket_notation.gemspec
CHANGED
@@ -2,32 +2,35 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{bracket_notation}
|
5
|
-
s.version = "1.0
|
5
|
+
s.version = "1.1.0"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Cody Brimhall"]
|
9
|
-
s.date = %q{2011-03-
|
9
|
+
s.date = %q{2011-03-23}
|
10
10
|
s.description = %q{Generates a representation of a syntax tree using a string of bracket notation.}
|
11
11
|
s.email = %q{zbrimhall@gmail.com}
|
12
|
-
s.extra_rdoc_files = ["CHANGELOG", "COPYING", "README.rdoc", "lib/bracket_notation.rb", "lib/bracket_notation/evaluator.rb", "lib/bracket_notation/expressions.rb", "lib/bracket_notation/expressions/expression.rb", "lib/bracket_notation/expressions/identifier.rb", "lib/bracket_notation/expressions/terminal.rb", "lib/bracket_notation/parser.rb", "lib/bracket_notation/scanner.rb", "lib/bracket_notation/token.rb", "lib/bracket_notation/version.rb"]
|
13
|
-
s.files = ["CHANGELOG", "COPYING", "README.rdoc", "Rakefile", "init.rb", "lib/bracket_notation.rb", "lib/bracket_notation/evaluator.rb", "lib/bracket_notation/expressions.rb", "lib/bracket_notation/expressions/expression.rb", "lib/bracket_notation/expressions/identifier.rb", "lib/bracket_notation/expressions/terminal.rb", "lib/bracket_notation/parser.rb", "lib/bracket_notation/scanner.rb", "lib/bracket_notation/token.rb", "lib/bracket_notation/version.rb", "test/functional/evaluator_test.rb", "test/functional/parser_test.rb", "test/functional/scanner_test.rb", "test/integration/parsing_test.rb", "test/test_helper.rb", "test/unit/expression_test.rb", "test/unit/
|
12
|
+
s.extra_rdoc_files = ["CHANGELOG", "COPYING", "README.rdoc", "lib/bracket_notation.rb", "lib/bracket_notation/evaluator.rb", "lib/bracket_notation/expressions.rb", "lib/bracket_notation/expressions/expression.rb", "lib/bracket_notation/expressions/identifier.rb", "lib/bracket_notation/expressions/terminal.rb", "lib/bracket_notation/geometry.rb", "lib/bracket_notation/geometry/point.rb", "lib/bracket_notation/geometry/rect.rb", "lib/bracket_notation/geometry/size.rb", "lib/bracket_notation/parser.rb", "lib/bracket_notation/scanner.rb", "lib/bracket_notation/token.rb", "lib/bracket_notation/version.rb", "lib/bracket_notation/views.rb", "lib/bracket_notation/views/branch.rb", "lib/bracket_notation/views/leaf.rb", "lib/bracket_notation/views/node.rb", "lib/bracket_notation/views/tree.rb"]
|
13
|
+
s.files = ["CHANGELOG", "COPYING", "Manifest", "README.rdoc", "Rakefile", "bracket_notation.gemspec", "init.rb", "lib/bracket_notation.rb", "lib/bracket_notation/evaluator.rb", "lib/bracket_notation/expressions.rb", "lib/bracket_notation/expressions/expression.rb", "lib/bracket_notation/expressions/identifier.rb", "lib/bracket_notation/expressions/terminal.rb", "lib/bracket_notation/geometry.rb", "lib/bracket_notation/geometry/point.rb", "lib/bracket_notation/geometry/rect.rb", "lib/bracket_notation/geometry/size.rb", "lib/bracket_notation/parser.rb", "lib/bracket_notation/scanner.rb", "lib/bracket_notation/token.rb", "lib/bracket_notation/version.rb", "lib/bracket_notation/views.rb", "lib/bracket_notation/views/branch.rb", "lib/bracket_notation/views/leaf.rb", "lib/bracket_notation/views/node.rb", "lib/bracket_notation/views/tree.rb", "test/functional/evaluator_test.rb", "test/functional/node_test.rb", "test/functional/parser_test.rb", "test/functional/scanner_test.rb", "test/functional/tree_test.rb", "test/integration/layout_test.rb", "test/integration/parsing_test.rb", "test/test_helper.rb", "test/unit/expression_test.rb", "test/unit/point_test.rb", "test/unit/rect_test.rb", "test/unit/size_test.rb", "test/unit/token_test.rb"]
|
14
14
|
s.homepage = %q{http://github.com/zbrimhall/bracket_notation}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Bracket_notation", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.rubyforge_project = %q{bracket_notation}
|
18
|
-
s.rubygems_version = %q{1.6.
|
18
|
+
s.rubygems_version = %q{1.6.2}
|
19
19
|
s.summary = %q{Provides a parser for strings that have been marked up with the bracket notation commonly used by syntacticians. The parser generates an abstract tree representation of the syntax of the string.}
|
20
|
-
s.test_files = ["test/functional/evaluator_test.rb", "test/functional/parser_test.rb", "test/functional/scanner_test.rb", "test/integration/parsing_test.rb", "test/test_helper.rb", "test/unit/expression_test.rb", "test/unit/token_test.rb"]
|
20
|
+
s.test_files = ["test/functional/evaluator_test.rb", "test/functional/node_test.rb", "test/functional/parser_test.rb", "test/functional/scanner_test.rb", "test/functional/tree_test.rb", "test/integration/layout_test.rb", "test/integration/parsing_test.rb", "test/test_helper.rb", "test/unit/expression_test.rb", "test/unit/point_test.rb", "test/unit/rect_test.rb", "test/unit/size_test.rb", "test/unit/token_test.rb"]
|
21
21
|
|
22
22
|
if s.respond_to? :specification_version then
|
23
23
|
s.specification_version = 3
|
24
24
|
|
25
25
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
26
|
+
s.add_runtime_dependency(%q<rmagick>, [">= 2.13.1"])
|
26
27
|
s.add_development_dependency(%q<shoulda>, [">= 2.11.3"])
|
27
28
|
else
|
29
|
+
s.add_dependency(%q<rmagick>, [">= 2.13.1"])
|
28
30
|
s.add_dependency(%q<shoulda>, [">= 2.11.3"])
|
29
31
|
end
|
30
32
|
else
|
33
|
+
s.add_dependency(%q<rmagick>, [">= 2.13.1"])
|
31
34
|
s.add_dependency(%q<shoulda>, [">= 2.11.3"])
|
32
35
|
end
|
33
36
|
end
|
data/init.rb
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
# and small portions of his code have been incorporated in the parser.
|
24
24
|
#
|
25
25
|
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
-
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
26
|
+
# Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
27
27
|
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
28
|
|
29
29
|
require './lib/bracket_notation'
|
data/lib/bracket_notation.rb
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
# and small portions of his code have been incorporated in the parser.
|
24
24
|
#
|
25
25
|
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
-
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
26
|
+
# Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
27
27
|
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
28
|
|
29
29
|
require 'bracket_notation/evaluator'
|
@@ -32,3 +32,5 @@ require 'bracket_notation/parser'
|
|
32
32
|
require 'bracket_notation/scanner'
|
33
33
|
require 'bracket_notation/token'
|
34
34
|
require 'bracket_notation/version'
|
35
|
+
require 'bracket_notation/geometry'
|
36
|
+
require 'bracket_notation/views'
|
@@ -23,7 +23,7 @@
|
|
23
23
|
# and small portions of his code have been incorporated in the parser.
|
24
24
|
#
|
25
25
|
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
-
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
26
|
+
# Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
27
27
|
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
28
|
|
29
29
|
module BracketNotation # :nodoc:
|
@@ -100,3 +100,4 @@ module BracketNotation # :nodoc:
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
103
|
+
|
@@ -23,7 +23,7 @@
|
|
23
23
|
# and small portions of his code have been incorporated in the parser.
|
24
24
|
#
|
25
25
|
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
-
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
26
|
+
# Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
27
27
|
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
28
|
|
29
29
|
require 'bracket_notation/expressions/expression'
|
@@ -23,7 +23,7 @@
|
|
23
23
|
# and small portions of his code have been incorporated in the parser.
|
24
24
|
#
|
25
25
|
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
-
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
26
|
+
# Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
27
27
|
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
28
|
|
29
29
|
module BracketNotation # :nodoc:
|
@@ -23,7 +23,7 @@
|
|
23
23
|
# and small portions of his code have been incorporated in the parser.
|
24
24
|
#
|
25
25
|
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
-
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
26
|
+
# Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
27
27
|
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
28
|
|
29
29
|
module BracketNotation # :nodoc:
|
@@ -23,7 +23,7 @@
|
|
23
23
|
# and small portions of his code have been incorporated in the parser.
|
24
24
|
#
|
25
25
|
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
-
# Copyright:: Copyright (c) 2010 Cody Brimhall
|
26
|
+
# Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
27
27
|
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
28
|
|
29
29
|
module BracketNotation # :nodoc:
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#--
|
2
|
+
# This file is part of BracketNotation.
|
3
|
+
#
|
4
|
+
# BracketNotation is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# BracketNotation is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with BracketNotation. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#++
|
17
|
+
# BracketNotation is a parser for generating syntax trees from sentences
|
18
|
+
# annotated with the kind of bracket notation that is commonly used by
|
19
|
+
# linguists. The result is a tree structure with nodes that describe the phrases
|
20
|
+
# and constituents of the sentence.
|
21
|
+
#
|
22
|
+
# BracketNotation was inspired by Yoichiro Hasebe's RSyntaxTree[http://yohasebe.com/rsyntaxtree/],
|
23
|
+
# and small portions of his code have been incorporated in the parser.
|
24
|
+
#
|
25
|
+
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
+
# Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
27
|
+
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
|
+
|
29
|
+
require 'bracket_notation/geometry/point'
|
30
|
+
require 'bracket_notation/geometry/size'
|
31
|
+
require 'bracket_notation/geometry/rect'
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#--
|
2
|
+
# This file is part of BracketNotation.
|
3
|
+
#
|
4
|
+
# BracketNotation is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# BracketNotation is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with BracketNotation. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#++
|
17
|
+
# BracketNotation is a parser for generating syntax trees from sentences
|
18
|
+
# annotated with the kind of bracket notation that is commonly used by
|
19
|
+
# linguists. The result is a tree structure with nodes that describe the phrases
|
20
|
+
# and constituents of the sentence.
|
21
|
+
#
|
22
|
+
# BracketNotation was inspired by Yoichiro Hasebe's RSyntaxTree[http://yohasebe.com/rsyntaxtree/],
|
23
|
+
# and small portions of his code have been incorporated in the parser.
|
24
|
+
#
|
25
|
+
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
+
# Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
27
|
+
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
|
+
|
29
|
+
module BracketNotation # :nodoc:
|
30
|
+
module Geometry # :nodoc:
|
31
|
+
# Point represents a point on a cartesian plane using an x and y fields.
|
32
|
+
class Point
|
33
|
+
attr_reader :x, :y
|
34
|
+
|
35
|
+
def initialize(x = 0, y = 0)
|
36
|
+
@x = x
|
37
|
+
@y = y
|
38
|
+
end
|
39
|
+
|
40
|
+
# Test to see if two points are equal, where equality is defined as having
|
41
|
+
# identical X and Y values
|
42
|
+
def ==(rvalue)
|
43
|
+
@x == rvalue.x && @y == rvalue.y
|
44
|
+
end
|
45
|
+
|
46
|
+
# Create a new point by adding the given amount to the current point's X value
|
47
|
+
def point_by_adding_to_x(delta_x)
|
48
|
+
self.class.new(@x + delta_x, @y)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Create a new point by adding the given amount to the current point's Y value
|
52
|
+
def point_by_adding_to_y(delta_y)
|
53
|
+
self.class.new(@x, @y + delta_y)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Create a new point by adding the given amounts to the current point's X and
|
57
|
+
# Y values
|
58
|
+
def point_by_adding_to_x_and_y(delta_x, delta_y)
|
59
|
+
self.class.new(@x + delta_x, @y + delta_y)
|
60
|
+
end
|
61
|
+
|
62
|
+
def inspect
|
63
|
+
"{x: #{@x}, y: #{@y}}"
|
64
|
+
end
|
65
|
+
|
66
|
+
alias :to_s :inspect
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#--
|
2
|
+
# This file is part of BracketNotation.
|
3
|
+
#
|
4
|
+
# BracketNotation is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# BracketNotation is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with BracketNotation. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#++
|
17
|
+
# BracketNotation is a parser for generating syntax trees from sentences
|
18
|
+
# annotated with the kind of bracket notation that is commonly used by
|
19
|
+
# linguists. The result is a tree structure with nodes that describe the phrases
|
20
|
+
# and constituents of the sentence.
|
21
|
+
#
|
22
|
+
# BracketNotation was inspired by Yoichiro Hasebe's RSyntaxTree[http://yohasebe.com/rsyntaxtree/],
|
23
|
+
# and small portions of his code have been incorporated in the parser.
|
24
|
+
#
|
25
|
+
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
+
# Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
27
|
+
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
|
+
|
29
|
+
module BracketNotation # :nodoc:
|
30
|
+
module Geometry # :nodoc:
|
31
|
+
# Rect represents a rectangle by means of origin and size fields.
|
32
|
+
class Rect
|
33
|
+
attr_reader :origin, :size
|
34
|
+
|
35
|
+
# Initialize the new instance. If the first two parameters are a Point and
|
36
|
+
# a Size, they will be used as the origin and size of the node rect
|
37
|
+
# respectively. If not, it is assumed that they are numeric values
|
38
|
+
# corresponding to the new node's origin coordinates, and they along with
|
39
|
+
# the optional last two parameters will be used to initialize new Point
|
40
|
+
# and Size objects to use for the rect.
|
41
|
+
def initialize(origin_or_x = Point.new, size_or_y = Size.new, width = 0, height = 0)
|
42
|
+
if origin_or_x.kind_of? Point and size_or_y.kind_of? Size
|
43
|
+
@origin = origin_or_x
|
44
|
+
@size = size_or_y
|
45
|
+
else
|
46
|
+
@origin = Point.new(origin_or_x, size_or_y)
|
47
|
+
@size = Size.new(width, height)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Test to see if two points are equal, where equality is defined as having
|
52
|
+
# identical origins and sizes
|
53
|
+
def ==(rvalue)
|
54
|
+
@origin == rvalue.origin && @size == rvalue.size
|
55
|
+
end
|
56
|
+
|
57
|
+
def inspect
|
58
|
+
"{origin: #{@origin.inspect}, size: #{@size.inspect}}"
|
59
|
+
end
|
60
|
+
|
61
|
+
alias :to_s :inspect
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#--
|
2
|
+
# This file is part of BracketNotation.
|
3
|
+
#
|
4
|
+
# BracketNotation is free software: you can redistribute it and/or modify
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
7
|
+
# (at your option) any later version.
|
8
|
+
#
|
9
|
+
# BracketNotation is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with BracketNotation. If not, see <http://www.gnu.org/licenses/>.
|
16
|
+
#++
|
17
|
+
# BracketNotation is a parser for generating syntax trees from sentences
|
18
|
+
# annotated with the kind of bracket notation that is commonly used by
|
19
|
+
# linguists. The result is a tree structure with nodes that describe the phrases
|
20
|
+
# and constituents of the sentence.
|
21
|
+
#
|
22
|
+
# BracketNotation was inspired by Yoichiro Hasebe's RSyntaxTree[http://yohasebe.com/rsyntaxtree/],
|
23
|
+
# and small portions of his code have been incorporated in the parser.
|
24
|
+
#
|
25
|
+
# Author:: Cody Brimhall (mailto:brimhall@somuchwit.com)
|
26
|
+
# Copyright:: Copyright (c) 2010-2011 Cody Brimhall
|
27
|
+
# License:: Distributed under the terms of the GNU General Public License, v. 3
|
28
|
+
|
29
|
+
module BracketNotation # :nodoc:
|
30
|
+
module Geometry # :nodoc:
|
31
|
+
# Size represents the size of a rectangle using a width and height field.
|
32
|
+
class Size
|
33
|
+
attr_reader :width, :height
|
34
|
+
|
35
|
+
def initialize(width = 0, height = 0)
|
36
|
+
@width = width
|
37
|
+
@height = height
|
38
|
+
end
|
39
|
+
|
40
|
+
# Test to see of two sizes are equal, where equality is defined as having
|
41
|
+
# identical widths and heights
|
42
|
+
def ==(rvalue)
|
43
|
+
@width == rvalue.width && @height == rvalue.height
|
44
|
+
end
|
45
|
+
|
46
|
+
# Create a new size by adding the given amount to the current size's width
|
47
|
+
def size_by_adding_to_width(delta_width)
|
48
|
+
self.class.new(@width + delta_width, @height)
|
49
|
+
end
|
50
|
+
|
51
|
+
# Create a new size by adding the given amount to the current size's height
|
52
|
+
def size_by_adding_to_height(delta_height)
|
53
|
+
self.class.new(@width, @height + delta_height)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Create a new size by adding the given amounts to the current size's width
|
57
|
+
# and height
|
58
|
+
def size_by_adding_to_width_and_height(delta_width, delta_height)
|
59
|
+
self.class.new(@width + delta_width, @height + delta_height)
|
60
|
+
end
|
61
|
+
|
62
|
+
def inspect
|
63
|
+
"{width: #{@width}, height: #{@height}}"
|
64
|
+
end
|
65
|
+
|
66
|
+
alias :to_s :inspect
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|