rsyntaxtree 0.8.1 → 0.8.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dbad02f72d4b84bdaaf1db6ed5506ed4bb3c447b9b15651dc4878a8e276f3e5
4
- data.tar.gz: 3b3c54cc2f174a4be46b827cb42f7f871e6334a28cb2df6099bf4d9521a4fbf6
3
+ metadata.gz: 4606912993b73a0aafb6b6be73cbad23109df14ee1509c6c686c61990acff33c
4
+ data.tar.gz: 073a6ecee37e7ce9aa67c329aee75da916dcac4a2cce101f4389cad85e82ed65
5
5
  SHA512:
6
- metadata.gz: 8b36dab4e18a88cf7db1874512236e8d049ddec1f06157b92215e329f323587d6055daf7e8011ada31c5533f0e71a901359db872cd367bf86a1d1065c4ab878c
7
- data.tar.gz: e68eb7afa8b4714ab1e48861fdf5ce2237669afc0350f28f642626f9f40274fd15d4169a9cf44f418afdcbe42abaea121329503b714625a38d436a375f801f60
6
+ metadata.gz: 569d8c208901a62379792019b9cd528e0a4ffff5c237c30c40244b70502a1852f3921d78f69e6b868ac2fa5096cf6ef1d550795dc74bce160951b3d610d30cc9
7
+ data.tar.gz: d15c6e7481e277621b32003a93356f146e3e22bda6c23730889aac5f08d1192b28e5d0dd92681326aff3249f6470fe3c17a91507a17c01c40e7960554a2b72af
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
 
@@ -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
@@ -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
 
@@ -239,22 +238,7 @@ class Graph
239
238
  right = k.indent + kw
240
239
  draw_element(left, curlevel, right - left, j.content, j.type)
241
240
  @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
241
 
257
- unless children.empty?
258
242
  k = @e_list.get_id(children[0])
259
243
  words = k.content.split(" ")
260
244
  dw = img_get_txt_width(k.content, @font, @font_size)
@@ -273,7 +257,33 @@ class Graph
273
257
  line_to_parent(k.indent, curlevel + 1, dw, j.indent, tw)
274
258
  end
275
259
  end
260
+
261
+ else
262
+ parent = @e_list.get_id(j.parent)
263
+ pw = img_get_txt_width(parent.content, @font, @font_size)
264
+ pleft = parent.indent
265
+ pright = pleft + pw
266
+ if curlevel == (h - 1)
267
+ e_arr.select{|l|l.level == curlevel}.each do |l|
268
+ lw = img_get_txt_width(l.content, @font, @font_size)
269
+ left = l.indent
270
+ right = left + lw
271
+ draw_element(left, curlevel, right - left, l.content, l.type)
272
+ @e_list.set_indent(l.id, left + (right - left) / 2 - tw / 2)
273
+ end
274
+ break
275
+ else
276
+ left = j.indent
277
+ right = left + tw
278
+ if pw > tw
279
+ left = pleft
280
+ right = pright
281
+ end
282
+ draw_element(left, curlevel, right - left, j.content, j.type)
283
+ @e_list.set_indent(j.id, left + (right - left) / 2 - tw / 2)
284
+ end
276
285
  end
286
+
277
287
  end
278
288
  end
279
289
  end
@@ -287,7 +297,7 @@ class Graph
287
297
 
288
298
  def get_txt_only(text)
289
299
  text = text.strip
290
- if /\A([\+\-\=\*\#]+).+/ =~ text
300
+ if /\A([\+\-\=\*\#\~]+).+/ =~ text
291
301
  prefix = $1
292
302
  prefix_l = Regexp.escape(prefix)
293
303
  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
@@ -1,4 +1,4 @@
1
1
  module RSyntaxTree
2
- VERSION = "0.8.1"
2
+ VERSION = "0.8.2"
3
3
  end
4
4
 
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.1
4
+ version: 0.8.2
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-29 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rmagick