fork download
  1. $/ = $\;
  2.  
  3. @tests = split /\*{30}/, <DATA>;
  4.  
  5. for (@tests){
  6.  
  7. /{(.*)}(.*)/ms;
  8.  
  9. ($kson, $table) = ("($1)", $2);
  10.  
  11. $kson =~ s/
  12. ".*?" \s* \K :
  13. /
  14. "=>"
  15. /xmsge;
  16.  
  17. %h = eval $kson;
  18.  
  19. $table =~ s/^\s+//ms;
  20.  
  21. @table = split /\n/, $table;
  22.  
  23. @plus = ();
  24. push @plus, pos $table[0] while $table[0] =~ m/\+/g;
  25.  
  26. @table = grep m/^\|/m, @table;
  27.  
  28. for $i (0 .. @table-1){
  29. for $j (0 .. @plus -2){
  30. $T[$i][$j] = substr $table[$i], $plus[$j], $plus[$j+1] - $plus[$j] - 1;
  31. $T[$i][$j] =~ s/
  32. ^ ( \s* Value: ( [.\w ]*? ) \s* ) $
  33. /
  34. $match = $1,
  35. $keys = $2,
  36. @keys = (split m!\.!, "$keys.A"),
  37. $space_fail = (grep m!^ | $!, @keys),
  38. $keys = eval '$h' . (join '', map qq[{"$_"}], @keys),
  39. defined $keys && ! (ref $keys) && ! $space_fail ?
  40. $keys
  41. :
  42. $match
  43. /xgmse
  44. }
  45. }
  46.  
  47. @jmax = ();
  48.  
  49. for $j (0 .. @plus -2){
  50. $max = 0;
  51. for $i (0 .. @table-1){
  52. $len = length $T[$i][$j];
  53. $max < $len and $max = $len;
  54. }
  55.  
  56. for $i (0 .. @table-1){
  57. $T[$i][$j] .= ' ' x ($max - length $T[$i][$j]);
  58. }
  59. push @jmax, $max;
  60. }
  61.  
  62. ( join '', map "$_\n", join '+', '', ( map '-' x $_, @jmax ), '' ),
  63. '',
  64. ( map "$_\n", map { join '|', '', @{ $T[$_] }, '' } 0 .. @table-1 ),
  65. '',
  66. );
  67.  
  68. undef @T;
  69. }
  70.  
  71.  
  72. __DATA__
  73. {}
  74. ++-------------+-------------------------+----------------------+--+
  75. || | Value: | Value:. | |
  76. ++-------------+-------------------------+----------------------+--+
  77. ******************************
  78. {
  79. }
  80. ++-------------+-------------------------+----------------------+--+
  81. || |Value: |Value:. | |
  82. ++-------------+-------------------------+----------------------+--+
  83. ******************************
  84. { "":"a b"
  85. }
  86. +-------------+-------------------------+----------------+---------+
  87. | Value:|Value: |Value:. | Value:.|
  88. +-------------+-------------------------+----------------+---------+
  89. ******************************
  90. { "b c":"a b"
  91. }
  92. +-------------+-------------------------+----------------+----------+
  93. | Value:b c | Value:b c|Value: b c |Value:.b c|
  94. +-------------+-------------------------+----------------+----------+
  95. ******************************
  96. { "" :
  97. "" }
  98. +-------------+-------------------------+----------------+----------+
  99. | Value: | Value:|Value: |Value:. |
  100. +-------------+-------------------------+----------------+----------+
  101. | Value : | value:|Value: .| Value:.|
  102. +-------------+-------------------------+----------------+----------+
  103. ******************************
  104. { "c d" :
  105. " fg " , "c" : "f","d" : ": ."
  106.  
  107. }
  108. +-------------+-------------------------+----------------+----------+
  109. | Value:c d| Value:c |Value:d |Value:. |
  110. +-------------+-------------------------+----------------+----------+
  111. | Value:d. | Value:.d |Value: d | Value:d.c|
  112. +-------------+-------------------------+----------------+----------+
  113. ******************************
  114. { "fg" : {}, "12 34" :
  115. "..." , "c" : { "d" : "cd", "e" : { } }
  116.  
  117. }
  118. +-------------+-------------------------+----------------+----------+
  119. | Value:fg | Value:12 34 |Value:c |Value:fg. |
  120. +-------------+-------------------------+----------------+----------+
  121. | Value:c.d | Value:d |Value:c.e | Value:e |
  122. +-------------+-------------------------+----------------+----------+
Success #stdin #stdout 0s 6044KB
stdin
Standard input is empty
stdout
++-------------+-------------------------+----------------------+--+
||             |   Value:                |  Value:.             |  |
++-------------+-------------------------+----------------------+--+
++-------------+-------------------------+----------------------+--+
||             |Value:                   |Value:.               |  |
++-------------+-------------------------+----------------------+--+
+----+----+----------------+---------+
|a  b|a  b|Value:.         |  Value:.|
+----+----+----------------+---------+
+----+----+----------------+----------+
|a  b|a  b|Value: b c      |Value:.b c|
+----+----+----------------+----------+
+-------------+-------------------------+----------------+----------+
|             |                         |                |Value:.   |
+-------------+-------------------------+----------------+----------+
|  Value :    |                   value:|Value:         .|   Value:.|
+-------------+-------------------------+----------------+----------+
+-------------+-------------------------+----------------+----------+
|   fg        |f                        |: .             |Value:.   |
+-------------+-------------------------+----------------+----------+
|  Value:d.   |               Value:.d  |Value: d        | Value:d.c|
+-------------+-------------------------+----------------+----------+
+-------------+-------------------------+----------------+----------+
|   Value:fg  |...                      |Value:c         |Value:fg. |
+-------------+-------------------------+----------------+----------+
|cd           |               Value:d   |Value:c.e       | Value:e  |
+-------------+-------------------------+----------------+----------+