yamlt 0.0.28 → 0.0.29

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/yamlt/parser/line.rb +139 -54
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb7ea61c423e478497132fc64e8737f388f69354
4
- data.tar.gz: 8501760b1869a164f4f0fea670b018c437535043
3
+ metadata.gz: 6cbc2b20f7623fd3a4a04ab255d8b7839b250caa
4
+ data.tar.gz: 45e89e9d7b113a8cbf666fb37822a99501d775c8
5
5
  SHA512:
6
- metadata.gz: e6d0e974b023f3674fc2bdb95b880970bed80e24324d137cb12f1bfe77f195b64a97656c84d5fcd35f3d4ea49f4db849a2d6280404f884067a9840328d41f2aa
7
- data.tar.gz: 096d2aeb0c68046a79f02009b171cd0823a646d797b542b0352dc4f31afbba70c108b1155fcb0159de0bf4ad682508cc3ea3a081bc31d74ce5984d8b48b9ad08
6
+ metadata.gz: abeac73e1d7b005141b668bd06b8f74b20a3edc9ee70d3286e6a769aeb09eb9014eaffdab1452008d5696d7bf473b467d09683ec62dcbff9bf705f0f10f4828d
7
+ data.tar.gz: db8fc1c19fb33012af8326af4cd6d23357cc79dc8633d82f4cbb5d71918bb544a59083de2838bbff831463921e4ee598277cc13794e1f4fc80ed70cf12220f33
@@ -17,11 +17,6 @@ module Yamlt
17
17
  attr_reader :comment_prefix
18
18
  attr_accessor :full_path, :value
19
19
 
20
- CLEAN_LINE = /^\s*$/
21
- COMMENT_LINE = /^(?<prefix>\s*)#(?<comment>.*)$/
22
- FRAGMENT_WITHOUT_VALUE = /^(\s*)(\w+):(\s*&\S+)?(\s*)(#(.*))?$/
23
- FRAGMENT_WITH_VALUE = /^(\s*)(\w+):(\s*(!\s*)?)([\'\"])(.*)\5((\s*)#(.*))?$/
24
- FRAGMENT_WITH_MULTILINE_START = /^(\s*)(\w+):(\s*)\|(\s*)$/
25
20
 
26
21
  def as_text(opts={})
27
22
  serializer = Serializer.new(self, opts)
@@ -38,6 +33,9 @@ module Yamlt
38
33
  value.gsub(/\\\"/, "\"")
39
34
  end
40
35
 
36
+
37
+ CLEAN_LINE = /^\s*$/
38
+
41
39
  def clean_line
42
40
  if CLEAN_LINE === @text
43
41
  @clean = true
@@ -45,6 +43,15 @@ module Yamlt
45
43
  end
46
44
  end
47
45
 
46
+
47
+ COMMENT_LINE = /
48
+ ^
49
+ (?<prefix>\s*)
50
+ \#
51
+ (?<comment>.*)
52
+ $
53
+ /x
54
+
48
55
  def comment_line
49
56
  if COMMENT_LINE === @text
50
57
  @comment = $~[:comment]
@@ -53,59 +60,137 @@ module Yamlt
53
60
  end
54
61
  end
55
62
 
56
- def parse
57
- # clean_line ||
58
- # comment_line ||
59
- # fragment_without_value ||
60
- # fragment_with_value ||
61
- # fragment_with_multiline_start
62
- # # etc.
63
-
64
- case @text
65
- when CLEAN_LINE
66
- @clean = true
67
- when COMMENT_LINE
63
+
64
+ FRAGMENT_WITHOUT_VALUE = /
65
+ ^
66
+ (?<indent>\s*)
67
+ (?<fragment>\w+)
68
+ :
69
+ (?<anchor>\s*&\S+)?
70
+ (?<prefix>\s*)
71
+ (?<comment_wrapper>
72
+ \#
73
+ (?<comment>.*)
74
+ )?
75
+ $
76
+ /x
77
+
78
+ def fragment_without_value
79
+ if FRAGMENT_WITHOUT_VALUE === @text && $~[:indent].length % 2 == 0
80
+ @fragment = $~[:fragment]
81
+ @level = $~[:indent].length / 2
82
+ @anchor = $~[:anchor]
83
+ @prefix = $~[:prefix]
68
84
  @comment = $~[:comment]
85
+
86
+ true
87
+ end
88
+ end
89
+
90
+
91
+ FRAGMENT_WITH_VALUE = /
92
+ ^
93
+ (?<indent>\s*)
94
+ (?<fragment>\w+)
95
+ :
96
+ (?<prefix>\s*(?<escaped_prefix>!\s*)?)
97
+ (?<quote>[\'\"])
98
+ (?<value>.*?)
99
+ \k<quote>
100
+ (?<comment_content>(?<comment_prefix>\s*)\#(?<comment>.*))?
101
+ $
102
+ /x
103
+
104
+ def fragment_with_value
105
+ if FRAGMENT_WITH_VALUE === @text && $~[:indent].length % 2 == 0
106
+ @fragment = $~[:fragment]
107
+ @level = $~[:indent].length / 2
69
108
  @prefix = $~[:prefix]
70
- when FRAGMENT_WITHOUT_VALUE
71
- if $~[1].length % 2 == 0
72
- @fragment = $~[2]
73
- @level = $~[1].length / 2
74
- @anchor = $~[3]
75
- @prefix = $~[4]
76
- @comment = $~[6]
77
- end
78
- when FRAGMENT_WITH_VALUE
79
- if $~[1].length % 2 == 0
80
- @fragment = $~[2]
81
- @level = $~[1].length / 2
82
- @prefix = $~[3]
83
- @value = unescape($~[6])
84
- @comment_prefix = $~[8]
85
- @comment = $~[9]
86
- end
87
- when FRAGMENT_WITH_MULTILINE_START
88
- if $~[1].length % 2 == 0
89
- @fragment = $~[2]
90
- @level = $~[1].length / 2
91
- @prefix = $~[3] || $~[4]
92
- @multiline = true
93
- end
94
- when /^(\s*)(\<\<:(\s+\*\w+\s*))(#(.*))?$/
95
- if $~[1].length % 2 == 0
96
- @fragment = "<<"
97
- @level = $~[1].length / 2
98
- @anchor = $~[3]
99
- @comment = $~[5]
100
- end
101
- when /^(\s*)(['"]?)(.*)\2\s*$/ #
102
- if $~[1].length % 2 == 0
103
- @level = $~[1].length / 2
104
- @value = unescape($~[3])
105
- @multiline = true
106
- end
109
+ @value = unescape($~[:value])
110
+ @comment_prefix = $~[:comment_prefix]
111
+ @comment = $~[:comment]
112
+
113
+ true
107
114
  end
108
115
  end
116
+
117
+
118
+ FRAGMENT_WITH_MULTILINE_START = /
119
+ ^
120
+ (?<indent>\s*)
121
+ (?<fragment>\w+)
122
+ :
123
+ (?<left_prefix>\s*)
124
+ \|
125
+ (?<right_prefix>\s*)
126
+ $
127
+ /x
128
+
129
+ def fragment_with_multiline_start
130
+ if FRAGMENT_WITH_MULTILINE_START === @text && $~[:indent].length % 2 == 0
131
+ @fragment = $~[:fragment]
132
+ @level = $~[:indent].length / 2
133
+ @prefix = $~[:left_prefix] || $~[:right_prefix]
134
+ @multiline = true
135
+
136
+ true
137
+ end
138
+ end
139
+
140
+
141
+ FRAGMENT_WITH_REFERENCE = /
142
+ ^
143
+ (?<indent>\s*)
144
+ (?<x0>\<\<:
145
+ (?<anchor>\s+\*\w+\s*)
146
+ )
147
+ (?<x1>
148
+ \#
149
+ (?<comment>.*)
150
+ )?
151
+ $
152
+ /x
153
+
154
+ def fragment_with_reference
155
+ if FRAGMENT_WITH_REFERENCE === @text && $~[:indent].length % 2 == 0
156
+ @fragment = "<<"
157
+ @level = $~[:indent].length / 2
158
+ @anchor = $~[:anchor]
159
+ @comment = $~[:comment]
160
+
161
+ true
162
+ end
163
+ end
164
+
165
+
166
+ MULTILINE_VALUE = /
167
+ ^
168
+ (?<indent>\s*)
169
+ (?<quote>['"]?) # '
170
+ (?<value>.*)
171
+ \k<quote>
172
+ \s*
173
+ $
174
+ /x
175
+
176
+ def multiline_value
177
+ if MULTILINE_VALUE === @text && $~[:indent].length % 2 == 0
178
+ @level = $~[:indent].length / 2
179
+ @value = unescape($~[:value])
180
+ @multiline = true
181
+ end
182
+ end
183
+
184
+
185
+ def parse
186
+ clean_line ||
187
+ comment_line ||
188
+ fragment_without_value ||
189
+ fragment_with_value ||
190
+ fragment_with_multiline_start ||
191
+ fragment_with_reference ||
192
+ multiline_value
193
+ end
109
194
  end
110
195
  end
111
196
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yamlt
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.28
4
+ version: 0.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tangerine Cat
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-07 00:00:00.000000000 Z
11
+ date: 2015-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -69,3 +69,4 @@ signing_key:
69
69
  specification_version: 4
70
70
  summary: Take yaml structure from locale file and apply to another one
71
71
  test_files: []
72
+ has_rdoc: