rsyntaxtree 0.8.1 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/fonts/NotoSansMath-Regular.ttf +0 -0
- data/fonts/latinmodern-math.otf +0 -0
- data/lib/rsyntaxtree/element.rb +1 -0
- data/lib/rsyntaxtree/graph.rb +30 -18
- data/lib/rsyntaxtree/svg_graph.rb +7 -1
- data/lib/rsyntaxtree/tree_graph.rb +6 -1
- data/lib/rsyntaxtree/version.rb +1 -1
- data/lib/rsyntaxtree.rb +1 -1
- data/syntree.svg +44 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46e87b5eb3718ca486b7db30381bf64d2c276f6e60173bbf686c150c3a40a54e
|
4
|
+
data.tar.gz: 24c796def12932596bd4a4df5b29a758e4a8f633b986cae1d33663bf19e2836c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf98fca2b5ce268499bfdea7a6d745de7f5bf6c0b26bacff1bea79d42df360dad1ec013d9f96b54f9111c951839d74c84a9725d12a81c364d504d39cec2432c2
|
7
|
+
data.tar.gz: 8efcf521ecb186456be69b8060c9a3b6c7724805897fb2aef6716aa5420f0da38fa4639c9798528d32b845498c2484cff56b95bb4e4a1df401972131910a315e
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# RSyntaxTree: yet another syntax tree generator in Ruby
|
1
|
+
# 🌲 RSyntaxTree: yet another syntax tree generator in Ruby
|
2
2
|
|
3
3
|
**RSyntaxTree** is a graphical syntax tree generator written in the Ruby programming language inspired by [phpSyntaxTree](http://ironcreek.net/phpsyntaxtree/).
|
4
4
|
|
File without changes
|
data/fonts/latinmodern-math.otf
CHANGED
File without changes
|
data/lib/rsyntaxtree/element.rb
CHANGED
@@ -31,6 +31,7 @@ class Element
|
|
31
31
|
@content = content.gsub("^"){""} # The actual element content
|
32
32
|
@triangle = false # draw triangle instead of stright bar when in auto mode
|
33
33
|
end
|
34
|
+
# workaround to save "[A [B [C] [D] ] [E [F] [G [H] [J] ] ] ]"
|
34
35
|
end
|
35
36
|
|
36
37
|
# Debug helper function
|
data/lib/rsyntaxtree/graph.rb
CHANGED
@@ -74,7 +74,6 @@ class Graph
|
|
74
74
|
else
|
75
75
|
metrics = gc.get_type_metrics(background, text)
|
76
76
|
end
|
77
|
-
|
78
77
|
return metrics
|
79
78
|
end
|
80
79
|
|
@@ -151,6 +150,7 @@ class Graph
|
|
151
150
|
e_arr = @e_list.get_elements
|
152
151
|
|
153
152
|
h = @e_list.get_level_height
|
153
|
+
|
154
154
|
h.times do |i|
|
155
155
|
x = 0
|
156
156
|
e_arr.each do |j|
|
@@ -190,6 +190,7 @@ class Graph
|
|
190
190
|
end
|
191
191
|
end
|
192
192
|
return true if !@symmetrize
|
193
|
+
|
193
194
|
h.times do |i|
|
194
195
|
curlevel = h - i - 1
|
195
196
|
indent = 0
|
@@ -239,26 +240,11 @@ class Graph
|
|
239
240
|
right = k.indent + kw
|
240
241
|
draw_element(left, curlevel, right - left, j.content, j.type)
|
241
242
|
@e_list.set_indent(j.id, left + (right - left) / 2 - tw / 2)
|
242
|
-
else
|
243
|
-
parent = @e_list.get_id(j.parent)
|
244
|
-
pw = img_get_txt_width(parent.content, @font, @font_size)
|
245
|
-
pleft = parent.indent
|
246
|
-
pright = pleft + pw
|
247
|
-
left = j.indent
|
248
|
-
right = left + tw
|
249
|
-
if pw > tw
|
250
|
-
left = pleft
|
251
|
-
right = pright
|
252
|
-
end
|
253
|
-
draw_element(left, curlevel, right - left, j.content, j.type)
|
254
|
-
@e_list.set_indent(j.id, left + (right - left) / 2 - tw / 2)
|
255
|
-
end
|
256
243
|
|
257
|
-
unless children.empty?
|
258
244
|
k = @e_list.get_id(children[0])
|
259
245
|
words = k.content.split(" ")
|
260
246
|
dw = img_get_txt_width(k.content, @font, @font_size)
|
261
|
-
unless @leafstyle == "nothing" && ETYPE_LEAF == k.type
|
247
|
+
unless (@leafstyle == "nothing" && ETYPE_LEAF == k.type)
|
262
248
|
if (@leafstyle == "triangle" && ETYPE_LEAF == k.type && words.length > 0)
|
263
249
|
txt_width = img_get_txt_width(k.content, @font, @font_size)
|
264
250
|
triangle_to_parent(k.indent, curlevel + 1, dw, txt_width)
|
@@ -273,7 +259,33 @@ class Graph
|
|
273
259
|
line_to_parent(k.indent, curlevel + 1, dw, j.indent, tw)
|
274
260
|
end
|
275
261
|
end
|
262
|
+
|
263
|
+
else
|
264
|
+
parent = @e_list.get_id(j.parent)
|
265
|
+
pw = img_get_txt_width(parent.content, @font, @font_size)
|
266
|
+
pleft = parent.indent
|
267
|
+
pright = pleft + pw
|
268
|
+
if curlevel == (h - 1) && e_arr.size == idx + 1
|
269
|
+
e_arr.select{|l|l.level == curlevel}.each do |l|
|
270
|
+
lw = img_get_txt_width(l.content, @font, @font_size)
|
271
|
+
left = l.indent
|
272
|
+
right = left + lw
|
273
|
+
@e_list.set_indent(l.id, left + (right - left) / 2 - tw / 2)
|
274
|
+
draw_element(left, curlevel, right - left, l.content, l.type)
|
275
|
+
end
|
276
|
+
break
|
277
|
+
else
|
278
|
+
left = j.indent
|
279
|
+
right = left + tw
|
280
|
+
if pw > tw
|
281
|
+
left = pleft
|
282
|
+
right = pright
|
283
|
+
end
|
284
|
+
draw_element(left, curlevel, right - left, j.content, j.type)
|
285
|
+
@e_list.set_indent(j.id, left + (right - left) / 2 - tw / 2)
|
286
|
+
end
|
276
287
|
end
|
288
|
+
|
277
289
|
end
|
278
290
|
end
|
279
291
|
end
|
@@ -287,7 +299,7 @@ class Graph
|
|
287
299
|
|
288
300
|
def get_txt_only(text)
|
289
301
|
text = text.strip
|
290
|
-
if /\A([
|
302
|
+
if /\A([\+\-\=\*\#\~]+).+/ =~ text
|
291
303
|
prefix = $1
|
292
304
|
prefix_l = Regexp.escape(prefix)
|
293
305
|
prefix_r = Regexp.escape(prefix.reverse)
|
@@ -18,7 +18,7 @@ require 'graph'
|
|
18
18
|
|
19
19
|
class SVGGraph < Graph
|
20
20
|
|
21
|
-
def initialize(e_list, metrics, symmetrize, color, leafstyle, multibyte, fontstyle, font, font_size)
|
21
|
+
def initialize(e_list, metrics, symmetrize, color, leafstyle, multibyte, fontstyle, font, font_cjk, font_size)
|
22
22
|
|
23
23
|
# Store class-specific parameters
|
24
24
|
@font = multibyte ? font_cjk : font
|
@@ -99,6 +99,9 @@ EOD
|
|
99
99
|
elsif /\A\-(.+)\-\z/ =~ main
|
100
100
|
main = $1
|
101
101
|
main_decoration= "underline"
|
102
|
+
elsif /\A\~(.+)\~\z/ =~ main
|
103
|
+
main = $1
|
104
|
+
main_decoration= "line-through"
|
102
105
|
else
|
103
106
|
main_decoration= ""
|
104
107
|
end
|
@@ -137,6 +140,9 @@ EOD
|
|
137
140
|
elsif /\A\-(.+)\-\z/ =~ sub
|
138
141
|
sub = $1
|
139
142
|
sub_decoration= "underline"
|
143
|
+
elsif /\A\~(.+)\~\z/ =~ sub
|
144
|
+
sub = $1
|
145
|
+
sub_decoration= "line-through"
|
140
146
|
else
|
141
147
|
sub_decoration= ""
|
142
148
|
end
|
@@ -100,6 +100,9 @@ class TreeGraph < Graph
|
|
100
100
|
elsif /\A\-(.+)\-\z/ =~ main
|
101
101
|
main = $1
|
102
102
|
main_decoration = UnderlineDecoration
|
103
|
+
elsif /\A\~(.+)\~\z/ =~ main
|
104
|
+
main = $1
|
105
|
+
main_decoration = LineThroughDecoration
|
103
106
|
else
|
104
107
|
main_decoration = NoDecoration
|
105
108
|
end
|
@@ -138,8 +141,10 @@ class TreeGraph < Graph
|
|
138
141
|
sub_decoration = OverlineDecoration
|
139
142
|
elsif /\A\-(.+)\-\z/ =~ sub
|
140
143
|
sub = $1
|
141
|
-
@gc.decorate(UnderlineDecoration)
|
142
144
|
sub_decoration = UnderlineDecoration
|
145
|
+
elsif /\A\~(.+)\~z/ =~ sub
|
146
|
+
sub = $1
|
147
|
+
sub_decoration = LineThroughDecoration
|
143
148
|
else
|
144
149
|
sub_decoration = NoDecoration
|
145
150
|
end
|
data/lib/rsyntaxtree/version.rb
CHANGED
data/lib/rsyntaxtree.rb
CHANGED
@@ -163,7 +163,7 @@ class RSGenerator
|
|
163
163
|
elist = sp.get_elementlist
|
164
164
|
graph = SVGGraph.new(elist, @metrics,
|
165
165
|
@params[:symmetrize], @params[:color], @params[:leafstyle], @params[:multibyte],
|
166
|
-
@params[:fontstyle], @params[:font], @params[:fontsize],
|
166
|
+
@params[:fontstyle], @params[:font], @params[:font_cjk], @params[:fontsize],
|
167
167
|
)
|
168
168
|
graph.svg_data
|
169
169
|
end
|
data/syntree.svg
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
<?xml version="1.0" standalone="no"?>
|
2
|
+
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
3
|
+
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
4
|
+
<svg width="1847.0" height="992.0" version="1.1" xmlns="http://www.w3.org/2000/svg">
|
5
|
+
<text style='fill: green; font-size: 64px; ; ;' x='536.0' y='961.0' text-decoration='' font-family='sans-serif'>the</text>
|
6
|
+
<text style='fill: green; font-size: 64px; ; ;' x='699.0' y='961.0' text-decoration='' font-family='sans-serif'>president</text>
|
7
|
+
<text style='fill: green; font-size: 64px; ; ;' x='408.0' y='785.0' text-decoration='' font-family='sans-serif'>of</text>
|
8
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='562.0' y='785.0' text-decoration='' font-family='sans-serif'>D</text>
|
9
|
+
<line style='stroke:black; stroke-width:2;' x1='586' y1='890' x2='586' y2='806' />
|
10
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='818.0' y='785.0' text-decoration='' font-family='sans-serif'>N</text>
|
11
|
+
<line style='stroke:black; stroke-width:2;' x1='843' y1='890' x2='843' y2='806' />
|
12
|
+
<text style='fill: green; font-size: 64px; ; ;' x='1243.0' y='785.0' text-decoration='' font-family='sans-serif'>blame</text>
|
13
|
+
<text style='fill: green; font-size: 64px; ; ;' x='1495.0' y='785.0' text-decoration='' font-family='sans-serif'>* himself</text>
|
14
|
+
<text style='fill: green; font-size: 64px; ; ;' x='10.0' y='609.0' text-decoration='line-through' font-family='sans-serif'>Supporters</text>
|
15
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='420.5' y='609.0' text-decoration='' font-family='sans-serif'>P</text>
|
16
|
+
<line style='stroke:black; stroke-width:2;' x1='440' y1='714' x2='440' y2='630' />
|
17
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='671.0' y='609.0' text-decoration='' font-family='sans-serif'>DP</text>
|
18
|
+
<line style='stroke:black; stroke-width:2;' x1='586' y1='714' x2='714' y2='630' />
|
19
|
+
<line style='stroke:black; stroke-width:2;' x1='843' y1='714' x2='714' y2='630' />
|
20
|
+
<text style='fill: green; font-size: 64px; ; ;' x='1050.0' y='609.0' text-decoration='' font-family='sans-serif'>may</text>
|
21
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='1317.5' y='609.0' text-decoration='' font-family='sans-serif'>V</text>
|
22
|
+
<line style='stroke:black; stroke-width:2;' x1='1337' y1='714' x2='1337' y2='630' />
|
23
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='1570.0' y='609.0' text-decoration='' font-family='sans-serif'>PRN</text>
|
24
|
+
<polygon style='fill: none; stroke: black; stroke-width:2;' points='1773 714 1495 714 1634 630' />
|
25
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='152.5' y='433.0' text-decoration='' font-family='sans-serif'>N</text>
|
26
|
+
<line style='stroke:black; stroke-width:2;' x1='177' y1='538' x2='177' y2='454' />
|
27
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='538.0' y='433.0' text-decoration='' font-family='sans-serif'>PP</text>
|
28
|
+
<line style='stroke:black; stroke-width:2;' x1='440' y1='538' x2='577' y2='454' />
|
29
|
+
<line style='stroke:black; stroke-width:2;' x1='714' y1='538' x2='577' y2='454' />
|
30
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='1096.5' y='433.0' text-decoration='' font-family='sans-serif'>T</text>
|
31
|
+
<line style='stroke:black; stroke-width:2;' x1='1115' y1='538' x2='1115' y2='454' />
|
32
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='1447.0' y='433.0' text-decoration='' font-family='sans-serif'>VP</text>
|
33
|
+
<line style='stroke:black; stroke-width:2;' x1='1337' y1='538' x2='1486' y2='454' />
|
34
|
+
<line style='stroke:black; stroke-width:2;' x1='1634' y1='538' x2='1486' y2='454' />
|
35
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='333.0' y='257.0' text-decoration='' font-family='sans-serif'>NP</text>
|
36
|
+
<line style='stroke:black; stroke-width:2;' x1='177' y1='362' x2='377' y2='278' />
|
37
|
+
<line style='stroke:black; stroke-width:2;' x1='577' y1='362' x2='377' y2='278' />
|
38
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='1275.0' y='257.0' text-decoration='' font-family='sans-serif'>T'</text>
|
39
|
+
<line style='stroke:black; stroke-width:2;' x1='1115' y1='362' x2='1300' y2='278' />
|
40
|
+
<line style='stroke:black; stroke-width:2;' x1='1486' y1='362' x2='1300' y2='278' />
|
41
|
+
<text style='fill: blue; font-size: 64px; ; ;' x='801.0' y='81.0' text-decoration='' font-family='sans-serif'>TP</text>
|
42
|
+
<line style='stroke:black; stroke-width:2;' x1='377' y1='186' x2='839' y2='102' />
|
43
|
+
<line style='stroke:black; stroke-width:2;' x1='1300' y1='186' x2='839' y2='102' />
|
44
|
+
</svg>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsyntaxtree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yoichiro Hasebe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rmagick
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- lib/rsyntaxtree/utils.rb
|
92
92
|
- lib/rsyntaxtree/version.rb
|
93
93
|
- rsyntaxtree.gemspec
|
94
|
+
- syntree.svg
|
94
95
|
homepage: http://github.com/yohasebe/rsyntaxtree
|
95
96
|
licenses:
|
96
97
|
- MIT
|
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
111
|
- !ruby/object:Gem::Version
|
111
112
|
version: '0'
|
112
113
|
requirements: []
|
113
|
-
rubygems_version: 3.2.
|
114
|
+
rubygems_version: 3.2.32
|
114
115
|
signing_key:
|
115
116
|
specification_version: 4
|
116
117
|
summary: RSyntaxTree is a graphical syntax tree generator written in Ruby
|