rsyntaxtree 0.8.1 → 0.8.2a
Sign up to get free protection for your applications and to get access to all the features.
- 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 +1 -1
- data/lib/rsyntaxtree/tree_graph.rb +6 -1
- data/lib/rsyntaxtree/version.rb +1 -1
- data/lib/rsyntaxtree.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8467331de91fe3c6cbd77462780d08fe23d540bc0cc25e9d65f3583ac523f882
|
4
|
+
data.tar.gz: 8021b25938b4a1b5a014fc89a4ae2a7f6b8da379e5d1432fb84771c29808a888
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4586e403663e95ad871b22b45833a6b956068f8e8f300324b8b67cb96a30b83ac83b47f7a3de76823c1b230a3ceb99f36b3d1a7a38928228d4f8d824eafb172
|
7
|
+
data.tar.gz: 745ea742aa872d4def42bd6ee9bff0b1d7813db20006f6a2c0ac7cbd4fbb657fa91e3bfb85b0dad6eddd452d839feda85623367e9cdfd971b78f48783610d3f5
|
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
|
@@ -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
|
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.2a
|
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
|
@@ -106,11 +106,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - "
|
109
|
+
- - ">"
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
111
|
+
version: 1.3.1
|
112
112
|
requirements: []
|
113
|
-
rubygems_version: 3.2.
|
113
|
+
rubygems_version: 3.2.32
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: RSyntaxTree is a graphical syntax tree generator written in Ruby
|