zig 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
1
  # ZIG
2
2
 
3
- ZIG is a simple data format. It is designed to be edited by hand.
4
- (Is is also quite easy to parse and generate, though.)
3
+ ZIG is a simple data format. It is designed to be easily edited by hand.
4
+ It is also pretty easy to parse and generate, though.
5
+
6
+ ZIG is indentation-based, like Python or Coffeescript.
5
7
 
6
8
  Here is a short example:
7
9
 
@@ -15,7 +17,8 @@ Here is a short example:
15
17
  description: "
16
18
  Check your Internet connection. Restart any router, modem,
17
19
  or other network devices you may be using.
20
+ # TODO: do we need these any more?
18
21
  codes: [
19
22
  118
20
23
  192
21
- ```
24
+ ```
@@ -15,15 +15,18 @@ class ZIG::Parser
15
15
  return object if spaces.size < indent
16
16
  raise "[line #{lines.num}] illegal indent" if spaces.size > indent
17
17
  lines.next
18
- if object.is_a?(Hash)
19
- key, value = value.scan(KEY_VALUE).flatten
20
- raise "[line #{lines.num}] missing key" if key.nil?
21
- object[key.strip.to_sym] = parse_value(indent, lines, value)
22
- elsif object.is_a?(Array)
23
- object << parse_value(indent, lines, value)
24
- else
18
+ if object.is_a?(String)
25
19
  object << "\n" unless object.empty?
26
20
  object << value
21
+ else
22
+ next if value[0] == '#'
23
+ if object.is_a?(Hash)
24
+ key, value = value.scan(KEY_VALUE).flatten
25
+ raise "[line #{lines.num}] missing key" if key.nil?
26
+ object[key.strip.to_sym] = parse_value(indent, lines, value)
27
+ else
28
+ object << parse_value(indent, lines, value)
29
+ end
27
30
  end
28
31
  end
29
32
  end
@@ -1,3 +1,3 @@
1
1
  module ZIG
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -159,6 +159,41 @@ describe ZIG do
159
159
  end
160
160
 
161
161
  describe "comments" do
162
+ it "should skip comment lines inside hashes" do
163
+ doc =
164
+ "{
165
+ a: 1
166
+ #b: 2
167
+ c: 3"
168
+ assert_equal Hash[a: 1, c: 3], ZIG.parse(doc)
169
+ end
170
+
171
+ it "should skip comment lines inside arrays" do
172
+ doc =
173
+ "[
174
+ 'one'
175
+ #'two'
176
+ 'three'"
177
+ assert_equal %w[one three], ZIG.parse(doc)
178
+ end
179
+
180
+ it "should ignore comment lines inside multiline strings" do
181
+ doc =
182
+ %{"
183
+ one house
184
+ #two houses
185
+ three houses}
186
+ assert_equal "one house\n#two houses\nthree houses", ZIG.parse(doc)
187
+ end
188
+ it "should reject comments if not properly idented" do
189
+ doc =
190
+ "{
191
+ a: 1
192
+ # TODO: check c
193
+ c: 3"
194
+ assert_raises(RuntimeError) { ZIG.parse(doc) }
195
+ end
196
+
162
197
  end
163
198
 
164
199
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-07 00:00:00.000000000 Z
12
+ date: 2012-11-08 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A parser for the ZIG data format.
15
15
  email:
@@ -54,7 +54,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
54
54
  version: '0'
55
55
  requirements: []
56
56
  rubyforge_project:
57
- rubygems_version: 1.8.24
57
+ rubygems_version: 1.8.10
58
58
  signing_key:
59
59
  specification_version: 3
60
60
  summary: A parser for the ZIG data format.