Chrononaut-treetop-dcf 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/dcf.rb +5 -1
- data/lib/dcf_grammar.treetop +8 -8
- data/test/test_dcf.rb +6 -5
- metadata +3 -3
data/lib/dcf.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "treetop"
|
3
|
-
require "dcf_grammar"
|
3
|
+
require File.join(File.dirname(__FILE__) + "/dcf_grammar")
|
4
4
|
|
5
5
|
module Dcf
|
6
6
|
# @param [String] input
|
@@ -17,4 +17,8 @@ module Dcf
|
|
17
17
|
paragraph
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
def self.version
|
22
|
+
"0.2.0"
|
23
|
+
end
|
20
24
|
end
|
data/lib/dcf_grammar.treetop
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
grammar Dcf
|
2
2
|
rule paragraphs
|
3
|
-
(paragraph eol?)
|
3
|
+
(paragraph eol?)+
|
4
4
|
end
|
5
5
|
|
6
6
|
rule paragraph
|
@@ -8,25 +8,25 @@ grammar Dcf
|
|
8
8
|
end
|
9
9
|
|
10
10
|
rule field
|
11
|
-
attribute separator value
|
11
|
+
attribute separator value
|
12
12
|
end
|
13
13
|
|
14
14
|
rule attribute
|
15
|
-
(!
|
15
|
+
(!":" !eol .)+
|
16
16
|
end
|
17
17
|
|
18
18
|
rule value
|
19
|
-
eol?
|
19
|
+
eol? (!eol .)+ (eol white+ (!eol .)+)*
|
20
20
|
{
|
21
21
|
def text_value
|
22
22
|
# I don't really like this, but it works for the files I'm parsing, so..
|
23
|
-
super.strip.gsub(
|
23
|
+
super.strip.gsub(/\n */, ' ')
|
24
24
|
end
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
|
-
rule
|
29
|
-
|
28
|
+
rule next_record
|
29
|
+
"\n" [a-zA-Z]
|
30
30
|
end
|
31
31
|
|
32
32
|
rule separator
|
@@ -34,7 +34,7 @@ grammar Dcf
|
|
34
34
|
end
|
35
35
|
|
36
36
|
rule eol
|
37
|
-
"\
|
37
|
+
"\n"
|
38
38
|
end
|
39
39
|
|
40
40
|
rule white
|
data/test/test_dcf.rb
CHANGED
@@ -2,9 +2,6 @@
|
|
2
2
|
require File.dirname(__FILE__) + '/helper'
|
3
3
|
|
4
4
|
class TestDcfParser < Test::Unit::TestCase
|
5
|
-
should "not accept spaces in keys" do
|
6
|
-
assert_nil Dcf.parse("As df: Value\n")
|
7
|
-
end
|
8
5
|
|
9
6
|
should "parse a description file" do
|
10
7
|
description = <<EOF
|
@@ -113,15 +110,19 @@ EOF
|
|
113
110
|
|
114
111
|
should "parse file with UTF-8 data" do
|
115
112
|
sample = <<EOF
|
113
|
+
Author: Vincent Goulet, Sébastien Auclair, Christophe Dutang, Xavier
|
114
|
+
Milhaud, Tommy Ouellet, Louis-Philippe Pouliot, Mathieu Pigeon
|
116
115
|
Encoding: latin1
|
117
116
|
Packaged: Tue May 26 10:40:31 2009; Grömping
|
118
117
|
Repository: CRAN
|
119
118
|
Date/Publication: 2009-05-26 09:23:28
|
120
119
|
EOF
|
121
|
-
sample = (RUBY_VERSION =~ /1.9/) ? sample.force_encoding("
|
122
|
-
match = (RUBY_VERSION =~ /1.9/) ? "Grömping".force_encoding("
|
120
|
+
sample = (RUBY_VERSION =~ /1.9/) ? sample.force_encoding("utf-8") : sample
|
121
|
+
match = (RUBY_VERSION =~ /1.9/) ? "Grömping".force_encoding("utf-8") : "Grömping"
|
123
122
|
parse = Dcf.parse(sample).first
|
124
123
|
assert_not_nil parse
|
124
|
+
assert_match "Sébastien Auclair", parse["Author"]
|
125
125
|
assert_equal "Tue May 26 10:40:31 2009; #{match}", parse["Packaged"]
|
126
126
|
end
|
127
|
+
|
127
128
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Chrononaut-treetop-dcf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bjorn Arild Maeland
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-06-
|
12
|
+
date: 2009-06-25 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -61,6 +61,6 @@ signing_key:
|
|
61
61
|
specification_version: 3
|
62
62
|
summary: Easy to use parser for Debian Control Files.
|
63
63
|
test_files:
|
64
|
+
- test/test_dcf.rb
|
64
65
|
- test/helper.rb
|
65
66
|
- test/suite.rb
|
66
|
-
- test/test_dcf.rb
|