tpkg 2.3.3 → 2.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/Portfile +39 -0
- data/Portfile.template +39 -0
- data/README.md +43 -0
- data/Rakefile +468 -18
- data/bin/gem2tpkg +2 -2
- data/bin/tpkg +18 -13
- data/bin/tpkg_uploader +132 -0
- data/ca.pem +1 -0
- data/control +7 -0
- data/depend +3 -0
- data/externals-etch/authorized_keys +40 -0
- data/externals-etch/group +9 -0
- data/externals-etch/iptables +38 -0
- data/externals-etch/limits +30 -0
- data/externals-etch/nfs +30 -0
- data/externals-etch/sudo +30 -0
- data/externals-etch/supplemental_groups +8 -0
- data/externals-etch/sysctl +30 -0
- data/externals-etch/user +41 -0
- data/externals/group +39 -0
- data/externals/supplemental_groups +48 -0
- data/externals/user +39 -0
- data/lib/tpkg.rb +260 -991
- data/lib/tpkg/os.rb +164 -0
- data/lib/tpkg/os/debian.rb +159 -0
- data/lib/tpkg/os/freebsd.rb +113 -0
- data/lib/tpkg/os/macosx.rb +113 -0
- data/lib/tpkg/os/redhat.rb +173 -0
- data/lib/tpkg/os/solaris.rb +101 -0
- data/lib/tpkg/os/windows.rb +26 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify.rb +67 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/errors.rb +127 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/kwalify.schema.yaml +58 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/main.rb +442 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/messages.rb +173 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/meta-validator.rb +275 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/base.rb +127 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/parser/yaml.rb +841 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/rule.rb +559 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-java.eruby +222 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-php.eruby +104 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/templates/genclass-ruby.eruby +113 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/types.rb +156 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util.rb +158 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/assert-text-equal.rb +46 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hash-interface.rb +18 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/hashlike.rb +51 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/option-parser.rb +220 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/ordered-hash.rb +57 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/util/testcase-helper.rb +112 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/validator.rb +282 -0
- data/lib/tpkg/thirdparty/kwalify-0.7.2/lib/kwalify/yaml-parser.rb +870 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh.rb +219 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/agent.rb +179 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/constants.rb +18 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/key_manager.rb +219 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/abstract.rb +60 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/hostbased.rb +71 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/keyboard_interactive.rb +66 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/password.rb +39 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/methods/publickey.rb +92 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/pageant.rb +183 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/authentication/session.rb +134 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffer.rb +340 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/buffered_io.rb +198 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/config.rb +205 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/channel.rb +630 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/constants.rb +33 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/session.rb +597 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/connection/term.rb +178 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/errors.rb +85 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/key_factory.rb +102 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/known_hosts.rb +129 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/loggable.rb +61 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/packet.rb +102 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/prompt.rb +93 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/command.rb +75 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/errors.rb +14 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/http.rb +94 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks4.rb +70 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/proxy/socks5.rb +142 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/ruby_compat.rb +43 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/service/forward.rb +288 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test.rb +89 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/channel.rb +129 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/extensions.rb +152 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/kex.rb +44 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/local_packet.rb +51 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/packet.rb +81 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/remote_packet.rb +38 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/script.rb +157 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/test/socket.rb +64 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/algorithms.rb +384 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/cipher_factory.rb +97 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/constants.rb +30 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac.rb +31 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/abstract.rb +79 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5.rb +12 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/md5_96.rb +11 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/none.rb +15 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1.rb +13 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/hmac/sha1_96.rb +11 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/identity_cipher.rb +55 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex.rb +13 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group1_sha1.rb +208 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/kex/diffie_hellman_group_exchange_sha1.rb +77 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/openssl.rb +127 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/packet_stream.rb +235 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/server_version.rb +71 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/session.rb +276 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/state.rb +206 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/lenient.rb +30 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/null.rb +12 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/verifiers/strict.rb +53 -0
- data/lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/version.rb +62 -0
- data/lib/tpkg/version.rb +3 -0
- data/man/man1/cpan2tpkg.1 +82 -0
- data/man/man1/gem2tpkg.1 +120 -0
- data/man/man1/tpkg.1 +411 -0
- data/pkginfo +8 -0
- data/postinstall.solaris +11 -0
- data/postremove.solaris +16 -0
- data/schema/schema-1.0.5.yml +0 -0
- data/schema/schema-1.0.6.yml +0 -0
- data/schema/schema-1.0.7.yml +0 -0
- data/schema/schema-1.0.8.yml +0 -0
- data/schema/schema-1.0.9.yml +0 -0
- data/schema/schema.yml +0 -0
- data/schema/tpkg-1.0.0.dtd +0 -0
- data/schema/tpkg-1.0.1.dtd +0 -0
- data/schema/tpkg-1.0.2.dtd +0 -0
- data/schema/tpkg-1.0.3.dtd +0 -0
- data/schema/tpkg-1.0.4.dtd +0 -0
- data/schema/tpkg-1.0.5.dtd +0 -0
- data/schema/tpkg-1.0.6.dtd +0 -0
- data/schema/tpkg-1.0.7.dtd +0 -0
- data/schema/tpkg-1.0.8.dtd +0 -0
- data/schema/tpkg-1.0.9.dtd +0 -0
- data/schema/tpkg.dtd +0 -0
- data/test/TODO +30 -0
- data/test/premadetestpkg/pkg_without_file_metadata-1.0-1.tpkg +0 -0
- data/test/test_checksum.rb +53 -0
- data/test/test_compress.rb +55 -0
- data/test/test_conflict.rb +41 -0
- data/test/test_crontabs.rb +398 -0
- data/test/test_dependency.rb +1113 -0
- data/test/test_downgrade.rb +80 -0
- data/test/test_download.rb +95 -0
- data/test/test_encrypt.rb +136 -0
- data/test/test_filemetadata.rb +131 -0
- data/test/test_initscript.rb +93 -0
- data/test/test_install.rb +186 -0
- data/test/test_lock.rb +82 -0
- data/test/test_make.rb +410 -0
- data/test/test_metadata.rb +805 -0
- data/test/test_misc.rb +379 -0
- data/test/test_options.rb +1711 -0
- data/test/test_os.rb +193 -0
- data/test/test_os_debian.rb +99 -0
- data/test/test_os_freebsd.rb +89 -0
- data/test/test_os_macosx.rb +79 -0
- data/test/test_os_redhat.rb +124 -0
- data/test/test_os_solaris.rb +85 -0
- data/test/test_os_windows.rb +26 -0
- data/test/test_query.rb +134 -0
- data/test/test_remove.rb +539 -0
- data/test/test_tar.rb +99 -0
- data/test/test_unpack.rb +977 -0
- data/test/test_upgrade.rb +398 -0
- data/test/test_version.rb +54 -0
- data/test/testcmds/crontab +14 -0
- data/test/testcmds/debian/apt-cache +145 -0
- data/test/testcmds/debian/dpkg-query +16 -0
- data/test/testcmds/freebsd/pkg_info +13 -0
- data/test/testcmds/macosx/port +35 -0
- data/test/testcmds/redhat/rpmbuild +6 -0
- data/test/testcmds/redhat/yum +90 -0
- data/test/testcmds/solaris/pkginfo +25 -0
- data/test/testcmds/solaris/pkgutil +36 -0
- data/test/testpkg/reloc/encfile +2 -0
- data/test/testpkg/reloc/file +2 -0
- data/test/testpkg/reloc/precryptfile +1 -0
- data/test/testpkg/reloc/precryptfile.plaintext +3 -0
- data/test/testpkg/tpkg-bad-ownergroup.xml +25 -0
- data/test/testpkg/tpkg-bad-ownergroup.yml +18 -0
- data/test/testpkg/tpkg-default-perms.xml +28 -0
- data/test/testpkg/tpkg-default-perms.yml +20 -0
- data/test/testpkg/tpkg-good-ownergroup.xml +25 -0
- data/test/testpkg/tpkg-good-ownergroup.yml +18 -0
- data/test/testpkg/tpkg-nativedeps.yml +13 -0
- data/test/testpkg/tpkg-nofiles.xml +14 -0
- data/test/testpkg/tpkg-nofiles.yml +9 -0
- data/test/testpkg/tpkg.xml +35 -0
- data/test/testpkg/tpkg.yml +25 -0
- data/test/tpkgtest.rb +300 -0
- data/tpkg.conf +16 -0
- data/tpkg.gemspec +24 -0
- data/tpkg.spec +28 -0
- data/tpkg.xml +17 -0
- data/tpkg_profile.sh +32 -0
- metadata +306 -31
@@ -0,0 +1,870 @@
|
|
1
|
+
###
|
2
|
+
### $Rev$
|
3
|
+
### $Release: 0.7.2 $
|
4
|
+
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
|
5
|
+
###
|
6
|
+
|
7
|
+
require 'kwalify/messages'
|
8
|
+
require 'kwalify/errors'
|
9
|
+
require 'kwalify/types'
|
10
|
+
|
11
|
+
require 'date'
|
12
|
+
|
13
|
+
|
14
|
+
module Kwalify
|
15
|
+
|
16
|
+
##
|
17
|
+
## base class of yaml parser
|
18
|
+
##
|
19
|
+
## ex.
|
20
|
+
## str = ARGF.read()
|
21
|
+
## parser = Kwalify::PlainYamlParser.new(str)
|
22
|
+
## doc = parser.parse()
|
23
|
+
## p doc
|
24
|
+
##
|
25
|
+
class PlainYamlParser
|
26
|
+
|
27
|
+
class Alias
|
28
|
+
def initialize(label, linenum)
|
29
|
+
@label = label
|
30
|
+
@linenum = linenum
|
31
|
+
end
|
32
|
+
attr_reader :label, :linenum
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def initialize(yaml_str)
|
37
|
+
@lines = yaml_str.to_a()
|
38
|
+
@line = nil
|
39
|
+
@linenum = 0
|
40
|
+
@anchors = {}
|
41
|
+
@aliases = {}
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def parse()
|
46
|
+
data = parse_child(0)
|
47
|
+
if data.nil? && @end_flag == '---'
|
48
|
+
data = parse_child(0)
|
49
|
+
end
|
50
|
+
resolve_aliases(data) unless @aliases.empty?
|
51
|
+
return data
|
52
|
+
end
|
53
|
+
|
54
|
+
|
55
|
+
def has_next?
|
56
|
+
return @end_flag != 'EOF'
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
def parse_all
|
61
|
+
list = []
|
62
|
+
while has_next()
|
63
|
+
doc = parse()
|
64
|
+
list << doc
|
65
|
+
end
|
66
|
+
return list
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
protected
|
71
|
+
|
72
|
+
|
73
|
+
def create_sequence(linenum=nil)
|
74
|
+
return []
|
75
|
+
end
|
76
|
+
|
77
|
+
def add_to_seq(seq, value, linenum)
|
78
|
+
seq << value
|
79
|
+
end
|
80
|
+
|
81
|
+
def set_seq_at(seq, i, value, linenum)
|
82
|
+
seq[i] = value
|
83
|
+
end
|
84
|
+
|
85
|
+
def create_mapping(linenum=nil)
|
86
|
+
return {}
|
87
|
+
end
|
88
|
+
|
89
|
+
def add_to_map(map, key, value, linenum)
|
90
|
+
map[key] = value
|
91
|
+
end
|
92
|
+
|
93
|
+
def set_map_with(map, key, value, linenum)
|
94
|
+
map[key] = value
|
95
|
+
end
|
96
|
+
|
97
|
+
def set_default(map, value, linenum)
|
98
|
+
map.value = value
|
99
|
+
end
|
100
|
+
|
101
|
+
def merge_map(map, map2, linenum)
|
102
|
+
map2.each do |key, val|
|
103
|
+
map[key] = value unless map.key?(key)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def create_scalar(value, linenum=nil)
|
108
|
+
return value
|
109
|
+
end
|
110
|
+
|
111
|
+
|
112
|
+
def current_line
|
113
|
+
return @line
|
114
|
+
end
|
115
|
+
|
116
|
+
def current_linenum
|
117
|
+
return @linenum
|
118
|
+
end
|
119
|
+
|
120
|
+
|
121
|
+
private
|
122
|
+
|
123
|
+
|
124
|
+
def getline
|
125
|
+
line = _getline()
|
126
|
+
line = _getline() while line && line =~ /^\s*($|\#)/
|
127
|
+
return line
|
128
|
+
end
|
129
|
+
|
130
|
+
def _getline
|
131
|
+
@line = @lines[@linenum]
|
132
|
+
@linenum += 1
|
133
|
+
case @line
|
134
|
+
when nil ; @end_flag = 'EOF'
|
135
|
+
when /^\.\.\.$/ ; @end_flag = '...'; @line = nil
|
136
|
+
when /^---(\s+.*)?$/ ; @end_flag = '---'; @line = nil
|
137
|
+
else ; @end_flag = nil
|
138
|
+
end
|
139
|
+
return @line
|
140
|
+
end
|
141
|
+
|
142
|
+
|
143
|
+
def reset_sbuf(str)
|
144
|
+
@sbuf = str[-1] == ?\n ? str : str + "\n"
|
145
|
+
@index = -1
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
def _getchar
|
150
|
+
@index += 1
|
151
|
+
ch = @sbuf[@index]
|
152
|
+
while ch.nil?
|
153
|
+
break if (line = getline()).nil?
|
154
|
+
reset_sbuf(line)
|
155
|
+
@index += 1
|
156
|
+
ch = @sbuf[@index]
|
157
|
+
end
|
158
|
+
return ch
|
159
|
+
end
|
160
|
+
|
161
|
+
def getchar
|
162
|
+
ch = _getchar()
|
163
|
+
ch = _getchar() while ch && white?(ch)
|
164
|
+
return ch
|
165
|
+
end
|
166
|
+
|
167
|
+
def getchar_or_nl
|
168
|
+
ch = _getchar()
|
169
|
+
ch = _getchar() while ch && white?(ch) && ch != ?\n
|
170
|
+
return ch
|
171
|
+
end
|
172
|
+
|
173
|
+
def current_char
|
174
|
+
return @sbuf[@index]
|
175
|
+
end
|
176
|
+
|
177
|
+
def getlabel
|
178
|
+
if @sbuf[@index..-1] =~ /\A\w[-\w]*/
|
179
|
+
label = $&
|
180
|
+
@index += label.length
|
181
|
+
else
|
182
|
+
label = nil
|
183
|
+
end
|
184
|
+
return label
|
185
|
+
end
|
186
|
+
|
187
|
+
#--
|
188
|
+
#def syntax_error(error_symbol, linenum=@linenum)
|
189
|
+
# msg = Kwalify.msg(error_symbol) % [linenum]
|
190
|
+
# return Kwalify::YamlSyntaxError.new(msg, linenum,error_symbol)
|
191
|
+
#end
|
192
|
+
#++
|
193
|
+
def syntax_error(error_symbol, arg=nil, linenum=@linenum)
|
194
|
+
msg = Kwalify.msg(error_symbol)
|
195
|
+
msg = msg % arg.to_a unless arg.nil?
|
196
|
+
return Kwalify::YamlSyntaxError.new(msg, linenum, error_symbol)
|
197
|
+
end
|
198
|
+
|
199
|
+
def parse_child(column)
|
200
|
+
line = getline()
|
201
|
+
return create_scalar(nil) if !line
|
202
|
+
line =~ /^( *)(.*)/
|
203
|
+
indent = $1.length
|
204
|
+
return create_scalar(nil) if indent < column
|
205
|
+
value = $2
|
206
|
+
return parse_value(column, value, indent)
|
207
|
+
end
|
208
|
+
|
209
|
+
|
210
|
+
def parse_value(column, value, value_start_column)
|
211
|
+
case value
|
212
|
+
when /^-( |$)/
|
213
|
+
data = parse_sequence(value_start_column, value)
|
214
|
+
when /^(:?:?[-.\w]+\*?|'.*?'|".*?"|=|<<) *:( |$)/
|
215
|
+
#when /^:?["']?[-.\w]+["']? *:( |$)/ #'
|
216
|
+
data = parse_mapping(value_start_column, value)
|
217
|
+
when /^\[/, /^\{/
|
218
|
+
data = parse_flowstyle(column, value)
|
219
|
+
when /^\&[-\w]+( |$)/
|
220
|
+
data = parse_anchor(column, value)
|
221
|
+
when /^\*[-\w]+( |$)/
|
222
|
+
data = parse_alias(column, value)
|
223
|
+
when /^[|>]/
|
224
|
+
data = parse_block_text(column, value)
|
225
|
+
when /^!/
|
226
|
+
data = parse_tag(column, value)
|
227
|
+
when /^\#/
|
228
|
+
data = parse_child(column)
|
229
|
+
else
|
230
|
+
data = parse_scalar(column, value)
|
231
|
+
end
|
232
|
+
return data
|
233
|
+
end
|
234
|
+
|
235
|
+
def white?(ch)
|
236
|
+
return ch == ?\ || ch == ?\t || ch == ?\n || ch == ?\r
|
237
|
+
end
|
238
|
+
|
239
|
+
|
240
|
+
##
|
241
|
+
## flowstyle ::= flow_seq | flow_map | flow_scalar | alias
|
242
|
+
##
|
243
|
+
## flow_seq ::= '[' [ flow_seq_item { ',' sp flow_seq_item } ] ']'
|
244
|
+
## flow_seq_item ::= flowstyle
|
245
|
+
##
|
246
|
+
## flow_map ::= '{' [ flow_map_item { ',' sp flow_map_item } ] '}'
|
247
|
+
## flow_map_item ::= flowstyle ':' sp flowstyle
|
248
|
+
##
|
249
|
+
## flow_scalar ::= string | number | boolean | symbol | date
|
250
|
+
##
|
251
|
+
|
252
|
+
def parse_flowstyle(column, value)
|
253
|
+
reset_sbuf(value)
|
254
|
+
getchar()
|
255
|
+
data = parse_flow(0)
|
256
|
+
ch = current_char
|
257
|
+
assert ch == ?] || ch == ?}
|
258
|
+
ch = getchar_or_nl()
|
259
|
+
unless ch == ?\n || ch == ?# || ch.nil?
|
260
|
+
#* key=:flow_hastail msg="flow style sequence is closed but got '%s'."
|
261
|
+
raise syntax_error(:flow_hastail, [ch.chr])
|
262
|
+
end
|
263
|
+
getline() if !ch.nil?
|
264
|
+
return data
|
265
|
+
end
|
266
|
+
|
267
|
+
def parse_flow(depth)
|
268
|
+
ch = current_char()
|
269
|
+
#ch = getchar()
|
270
|
+
if ch.nil?
|
271
|
+
#* key=:flow_eof msg="found EOF when parsing flow style."
|
272
|
+
rase syntax_error(:flow_eof)
|
273
|
+
end
|
274
|
+
## alias
|
275
|
+
if ch == ?*
|
276
|
+
_getchar()
|
277
|
+
label = getlabel()
|
278
|
+
unless label
|
279
|
+
#* key=:flow_alias_label msg="alias name expected."
|
280
|
+
rase syntax_error(:flow_alias_label)
|
281
|
+
end
|
282
|
+
data = @anchors[label]
|
283
|
+
unless data
|
284
|
+
data = register_alias(label)
|
285
|
+
#raise syntax_error("anchor '#{label}' not found (cannot refer to backward or child anchor).")
|
286
|
+
end
|
287
|
+
return data
|
288
|
+
end
|
289
|
+
## anchor
|
290
|
+
label = nil
|
291
|
+
if ch == ?&
|
292
|
+
_getchar()
|
293
|
+
label = getlabel()
|
294
|
+
unless label
|
295
|
+
#* key=:flow_anchor_label msg="anchor name expected."
|
296
|
+
rase syntax_error(:flow_anchor_label)
|
297
|
+
end
|
298
|
+
ch = current_char()
|
299
|
+
ch = getchar() if white?(ch)
|
300
|
+
end
|
301
|
+
## flow data
|
302
|
+
if ch == ?[
|
303
|
+
data = parse_flow_seq(depth)
|
304
|
+
elsif ch == ?{
|
305
|
+
data = parse_flow_map(depth)
|
306
|
+
else
|
307
|
+
data = parse_flow_scalar(depth)
|
308
|
+
end
|
309
|
+
## register anchor
|
310
|
+
register_anchor(label, data) if label
|
311
|
+
return data
|
312
|
+
end
|
313
|
+
|
314
|
+
def parse_flow_seq(depth)
|
315
|
+
assert current_char() == ?[
|
316
|
+
seq = create_sequence() # []
|
317
|
+
ch = getchar()
|
318
|
+
if ch != ?}
|
319
|
+
linenum = current_linenum()
|
320
|
+
#seq << parse_flow_seq_item(depth + 1)
|
321
|
+
add_to_seq(seq, parse_flow_seq_item(depth + 1), linenum)
|
322
|
+
while (ch = current_char()) == ?,
|
323
|
+
ch = getchar()
|
324
|
+
if ch == ?]
|
325
|
+
#* key=:flow_noseqitem msg="sequence item required (or last comma is extra)."
|
326
|
+
raise syntax_error(:flow_noseqitem)
|
327
|
+
end
|
328
|
+
#break if ch == ?]
|
329
|
+
linenum = current_linenum()
|
330
|
+
#seq << parse_flow_seq_item(depth + 1)
|
331
|
+
add_to_seq(seq, parse_flow_seq_item(depth + 1), linenum)
|
332
|
+
end
|
333
|
+
end
|
334
|
+
unless current_char() == ?]
|
335
|
+
#* key=:flow_seqnotclosed msg="flow style sequence requires ']'."
|
336
|
+
raise syntax_error(:flow_seqnotclosed)
|
337
|
+
end
|
338
|
+
getchar() if depth > 0
|
339
|
+
return seq
|
340
|
+
end
|
341
|
+
|
342
|
+
def parse_flow_seq_item(depth)
|
343
|
+
return parse_flow(depth)
|
344
|
+
end
|
345
|
+
|
346
|
+
def parse_flow_map(depth)
|
347
|
+
assert current_char() == ?{ #}
|
348
|
+
map = create_mapping() # {}
|
349
|
+
ch = getchar()
|
350
|
+
if ch != ?}
|
351
|
+
linenum = current_linenum()
|
352
|
+
key, value = parse_flow_map_item(depth + 1)
|
353
|
+
#map[key] = value
|
354
|
+
add_to_map(map, key, value, linenum)
|
355
|
+
while (ch = current_char()) == ?,
|
356
|
+
ch = getchar()
|
357
|
+
if ch == ?}
|
358
|
+
#* key=:flow_mapnoitem msg="mapping item required (or last comma is extra)."
|
359
|
+
raise syntax_error(:flow_mapnoitem)
|
360
|
+
end
|
361
|
+
#break if ch == ?}
|
362
|
+
linenum = current_linenum()
|
363
|
+
key, value = parse_flow_map_item(depth + 1)
|
364
|
+
#map[key] = value
|
365
|
+
add_to_map(map, key, value, linenum)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
unless current_char() == ?}
|
369
|
+
#* key=:flow_mapnotclosed msg="flow style mapping requires '}'."
|
370
|
+
raise syntax_error(:flow_mapnotclosed)
|
371
|
+
end
|
372
|
+
getchar() if depth > 0
|
373
|
+
return map
|
374
|
+
end
|
375
|
+
|
376
|
+
def parse_flow_map_item(depth)
|
377
|
+
key = parse_flow(depth)
|
378
|
+
unless (ch = current_char()) == ?:
|
379
|
+
$stderr.puts "*** debug: key=#{key.inspect}"
|
380
|
+
s = ch ? "'#{ch.chr}'" : "EOF"
|
381
|
+
#* key=:flow_nocolon msg="':' expected but got %s."
|
382
|
+
raise syntax_error(:flow_nocolon, [s])
|
383
|
+
end
|
384
|
+
getchar()
|
385
|
+
value = parse_flow(depth)
|
386
|
+
return key, value
|
387
|
+
end
|
388
|
+
|
389
|
+
def parse_flow_scalar(depth)
|
390
|
+
case ch = current_char()
|
391
|
+
when ?", ?' #"
|
392
|
+
endch = ch
|
393
|
+
s = ''
|
394
|
+
while (ch = _getchar()) != nil && ch != endch
|
395
|
+
if ch == ?\\
|
396
|
+
ch = _getchar()
|
397
|
+
if ch.nil?
|
398
|
+
#* key=:flow_str_notclosed msg="%s: string not closed."
|
399
|
+
raise syntax_error(:flow_str_notclosed, endch == ?" ? "'\"'" : '"\'"')
|
400
|
+
end
|
401
|
+
if endch == ?"
|
402
|
+
case ch
|
403
|
+
when ?\\ ; s << "\\"
|
404
|
+
when ?" ; s << "\""
|
405
|
+
when ?n ; s << "\n"
|
406
|
+
when ?r ; s << "\r"
|
407
|
+
when ?t ; s << "\t"
|
408
|
+
when ?b ; s << "\b"
|
409
|
+
else ; s << "\\" << ch.chr
|
410
|
+
end
|
411
|
+
elsif endch == ?'
|
412
|
+
case ch
|
413
|
+
when ?\\ ; s << '\\'
|
414
|
+
when ?' ; s << '\''
|
415
|
+
else ; s << '\\' << ch.chr
|
416
|
+
end
|
417
|
+
end
|
418
|
+
else
|
419
|
+
s << ch.chr
|
420
|
+
end
|
421
|
+
end
|
422
|
+
getchar()
|
423
|
+
scalar = s
|
424
|
+
else
|
425
|
+
s = ch.chr
|
426
|
+
while (ch = _getchar()) != nil && ch != ?: && ch != ?, && ch != ?] && ch != ?}
|
427
|
+
s << ch.chr
|
428
|
+
end
|
429
|
+
scalar = to_scalar(s.strip)
|
430
|
+
end
|
431
|
+
return create_scalar(scalar)
|
432
|
+
end
|
433
|
+
|
434
|
+
|
435
|
+
def parse_tag(column, value)
|
436
|
+
assert value =~ /^!\S+/
|
437
|
+
value =~ /^!(\S+)((\s+)(.*))?$/
|
438
|
+
tag = $1
|
439
|
+
space = $3
|
440
|
+
value2 = $4
|
441
|
+
if value2 && !value2.empty?
|
442
|
+
value_start_column = column + 1 + tag.length + space.length
|
443
|
+
data = parse_value(column, value2, value_start_column)
|
444
|
+
else
|
445
|
+
data = parse_child(column)
|
446
|
+
end
|
447
|
+
return data
|
448
|
+
end
|
449
|
+
|
450
|
+
|
451
|
+
def parse_anchor(column, value)
|
452
|
+
assert value =~ /^\&([-\w]+)(( *)(.*))?$/
|
453
|
+
label = $1
|
454
|
+
space = $3
|
455
|
+
value2 = $4
|
456
|
+
if value2 && !value2.empty?
|
457
|
+
#column2 = column + 1 + label.length + space.length
|
458
|
+
#data = parse_value(column2, value2)
|
459
|
+
value_start_column = column + 1 + label.length + space.length
|
460
|
+
data = parse_value(column, value2, value_start_column)
|
461
|
+
else
|
462
|
+
#column2 = column + 1
|
463
|
+
#data = parse_child(column2)
|
464
|
+
data = parse_child(column)
|
465
|
+
end
|
466
|
+
register_anchor(label, data)
|
467
|
+
return data
|
468
|
+
end
|
469
|
+
|
470
|
+
def register_anchor(label, data)
|
471
|
+
if @anchors[label]
|
472
|
+
#* key=:anchor_duplicated msg="anchor '%s' is already used."
|
473
|
+
raise syntax_error(:anchor_duplicated, [label])
|
474
|
+
end
|
475
|
+
@anchors[label] = data
|
476
|
+
end
|
477
|
+
|
478
|
+
def parse_alias(column, value)
|
479
|
+
assert value =~ /^\*([-\w]+)(( *)(.*))?$/
|
480
|
+
label = $1
|
481
|
+
space = $3
|
482
|
+
value2 = $4
|
483
|
+
if value2 && !value2.empty? && value2[0] != ?\#
|
484
|
+
#* key=:alias_extradata msg="alias cannot take any data."
|
485
|
+
raise syntax_error(:alias_extradata)
|
486
|
+
end
|
487
|
+
data = @anchors[label]
|
488
|
+
unless data
|
489
|
+
data = register_alias(label)
|
490
|
+
#raise syntax_error("anchor '#{label}' not found (cannot refer to backward or child anchor).")
|
491
|
+
end
|
492
|
+
getline()
|
493
|
+
return data
|
494
|
+
end
|
495
|
+
|
496
|
+
def register_alias(label)
|
497
|
+
@aliases[label] ||= 0
|
498
|
+
@aliases[label] += 1
|
499
|
+
return Alias.new(label, @linenum)
|
500
|
+
end
|
501
|
+
|
502
|
+
|
503
|
+
def resolve_aliases(data)
|
504
|
+
@resolved ||= {}
|
505
|
+
return if @resolved[data.__id__]
|
506
|
+
@resolved[data.__id__] = data
|
507
|
+
case data
|
508
|
+
when Array
|
509
|
+
seq = data
|
510
|
+
seq.each_with_index do |val, i|
|
511
|
+
if val.is_a?(Alias)
|
512
|
+
anchor = val
|
513
|
+
if @anchors.key?(anchor.label)
|
514
|
+
#seq[i] = @anchors[anchor.label]
|
515
|
+
set_seq_at(seq, i, @anchors[anchor.label], anchor.linenum)
|
516
|
+
else
|
517
|
+
#* key=:anchor_notfound msg="anchor '%s' not found"
|
518
|
+
raise syntax_error(:anchor_notfound, [anchor.label], val.linenum)
|
519
|
+
end
|
520
|
+
elsif val.is_a?(Array) || val.is_a?(Hash)
|
521
|
+
resolve_aliases(val)
|
522
|
+
end
|
523
|
+
end
|
524
|
+
when Hash
|
525
|
+
map = data
|
526
|
+
map.each do |key, val|
|
527
|
+
if val.is_a?(Alias)
|
528
|
+
if @anchors.key?(val.label)
|
529
|
+
anchor = val
|
530
|
+
#map[key] = @anchors[anchor.label]
|
531
|
+
set_map_with(map, key, @anchors[anchor.label], anchor.linenum)
|
532
|
+
else
|
533
|
+
## :anchor_notfound is already defined on above
|
534
|
+
raise syntax_error(:anchor_notfound, [val.label], val.linenum)
|
535
|
+
end
|
536
|
+
elsif val.is_a?(Array) || val.is_a?(Hash)
|
537
|
+
resolve_aliases(val)
|
538
|
+
end
|
539
|
+
end
|
540
|
+
else
|
541
|
+
assert !data.is_a?(Alias)
|
542
|
+
end
|
543
|
+
end
|
544
|
+
|
545
|
+
|
546
|
+
def parse_block_text(column, value)
|
547
|
+
assert value =~ /^[>|\|]/
|
548
|
+
value =~ /^([>|\|])([-+]?)(\d+)?\s*(.*)$/
|
549
|
+
char = $1
|
550
|
+
indicator = $2
|
551
|
+
sep = char == "|" ? "\n" : " "
|
552
|
+
margin = $3 && !$3.empty? ? $3.to_i : nil
|
553
|
+
#text = $4.empty? ? '' : $4 + sep
|
554
|
+
text = $4
|
555
|
+
s = ''
|
556
|
+
empty = ''
|
557
|
+
min_indent = -1
|
558
|
+
while line = _getline()
|
559
|
+
line =~ /^( *)(.*)/
|
560
|
+
indent = $1.length
|
561
|
+
if $2.empty?
|
562
|
+
empty << "\n"
|
563
|
+
elsif indent < column
|
564
|
+
break
|
565
|
+
else
|
566
|
+
min_indent = indent if min_indent < 0 || min_indent > indent
|
567
|
+
s << empty << line
|
568
|
+
empty = ''
|
569
|
+
end
|
570
|
+
end
|
571
|
+
s << empty if indicator == '+' && char != '>'
|
572
|
+
s[-1] = "" if indicator == '-'
|
573
|
+
min_indent = column + margin - 1 if margin
|
574
|
+
if min_indent > 0
|
575
|
+
sp = ' ' * min_indent
|
576
|
+
s.gsub!(/^#{sp}/, '')
|
577
|
+
end
|
578
|
+
if char == '>'
|
579
|
+
s.gsub!(/([^\n])\n([^\n])/, '\1 \2')
|
580
|
+
s.gsub!(/\n(\n+)/, '\1')
|
581
|
+
s << empty if indicator == '+'
|
582
|
+
end
|
583
|
+
getline() if current_line() =~ /^\s*\#/
|
584
|
+
return create_scalar(text + s)
|
585
|
+
end
|
586
|
+
|
587
|
+
|
588
|
+
def parse_sequence(column, value)
|
589
|
+
assert value =~ /^-(( +)(.*))?$/
|
590
|
+
seq = create_sequence() # []
|
591
|
+
while true
|
592
|
+
unless value =~ /^-(( +)(.*))?$/
|
593
|
+
#* key=:sequence_noitem msg="sequence item is expected."
|
594
|
+
raise syntax_error(:sequence_noitem)
|
595
|
+
end
|
596
|
+
value2 = $3
|
597
|
+
space = $2
|
598
|
+
column2 = column + 1
|
599
|
+
linenum = current_linenum()
|
600
|
+
#
|
601
|
+
if !value2 || value2.empty?
|
602
|
+
elem = parse_child(column2)
|
603
|
+
else
|
604
|
+
value_start_column = column2 + space.length
|
605
|
+
elem = parse_value(column2, value2, value_start_column)
|
606
|
+
end
|
607
|
+
add_to_seq(seq, elem, linenum) #seq << elem
|
608
|
+
#
|
609
|
+
line = current_line()
|
610
|
+
break unless line
|
611
|
+
line =~ /^( *)(.*)/
|
612
|
+
indent = $1.length
|
613
|
+
if indent < column
|
614
|
+
break
|
615
|
+
elsif indent > column
|
616
|
+
#* key=:sequence_badindent msg="illegal indent of sequence."
|
617
|
+
raise syntax_error(:sequence_badindent)
|
618
|
+
end
|
619
|
+
value = $2
|
620
|
+
end
|
621
|
+
return seq
|
622
|
+
end
|
623
|
+
|
624
|
+
|
625
|
+
def parse_mapping(column, value)
|
626
|
+
#assert value =~ /^(:?["']?[-.\w]+["']? *):(( +)(.*))?$/ #'
|
627
|
+
assert value =~ /^((?::?[-.\w]+\*?|'.*?'|".*?"|=|<<) *):(( +)(.*))?$/
|
628
|
+
map = create_mapping() # {}
|
629
|
+
while true
|
630
|
+
#unless value =~ /^(:?["']?[-.\w]+["']? *):(( +)(.*))?$/ #'
|
631
|
+
unless value =~ /^((?::?[-.\w]+\*?|'.*?'|".*?"|=|<<) *):(( +)(.*))?$/
|
632
|
+
#* key=:mapping_noitem msg="mapping item is expected."
|
633
|
+
raise syntax_error(:mapping_noitem)
|
634
|
+
end
|
635
|
+
v = $1.strip
|
636
|
+
key = to_scalar(v)
|
637
|
+
value2 = $4
|
638
|
+
column2 = column + 1
|
639
|
+
linenum = current_linenum()
|
640
|
+
#
|
641
|
+
if !value2 || value2.empty?
|
642
|
+
elem = parse_child(column2)
|
643
|
+
else
|
644
|
+
value_start_column = column2 + $1.length + $3.length
|
645
|
+
elem = parse_value(column2, value2, value_start_column)
|
646
|
+
end
|
647
|
+
case v
|
648
|
+
when '='
|
649
|
+
set_default(map, elem, linenum)
|
650
|
+
when '<<'
|
651
|
+
merge_map(map, elem, linenum)
|
652
|
+
else
|
653
|
+
add_to_map(map, key, elem, linenum) # map[key] = elem
|
654
|
+
end
|
655
|
+
#
|
656
|
+
line = current_line()
|
657
|
+
break unless line
|
658
|
+
line =~ /^( *)(.*)/
|
659
|
+
indent = $1.length
|
660
|
+
if indent < column
|
661
|
+
break
|
662
|
+
elsif indent > column
|
663
|
+
#* key=:mapping_badindent msg="illegal indent of mapping."
|
664
|
+
raise syntax_error(:mapping_badindent)
|
665
|
+
end
|
666
|
+
value = $2
|
667
|
+
end
|
668
|
+
return map
|
669
|
+
end
|
670
|
+
|
671
|
+
|
672
|
+
def parse_scalar(indent, value)
|
673
|
+
data = create_scalar(to_scalar(value))
|
674
|
+
getline()
|
675
|
+
return data
|
676
|
+
end
|
677
|
+
|
678
|
+
|
679
|
+
def to_scalar(str)
|
680
|
+
case str
|
681
|
+
when /^"(.*)"([ \t]*\#.*$)?/ ; return $1
|
682
|
+
when /^'(.*)'([ \t]*\#.*$)?/ ; return $1
|
683
|
+
when /^(.*\S)[ \t]*\#/ ; str = $1
|
684
|
+
end
|
685
|
+
|
686
|
+
case str
|
687
|
+
when /^-?\d+$/ ; return str.to_i # integer
|
688
|
+
when /^-?\d+\.\d+$/ ; return str.to_f # float
|
689
|
+
when "true", "yes", "on" ; return true # true
|
690
|
+
when "false", "no", "off" ; return false # false
|
691
|
+
when "null", "~" ; return nil # nil
|
692
|
+
#when /^"(.*)"$/ ; return $1 # "string"
|
693
|
+
#when /^'(.*)'$/ ; return $1 # 'string'
|
694
|
+
when /^:(\w+)$/ ; return $1.intern # :symbol
|
695
|
+
when /^(\d\d\d\d)-(\d\d)-(\d\d)$/ # date
|
696
|
+
year, month, day = $1.to_i, $2.to_i, $3.to_i
|
697
|
+
return Date.new(year, month, day)
|
698
|
+
when /^(\d\d\d\d)-(\d\d)-(\d\d)(?:[Tt]|[ \t]+)(\d\d?):(\d\d):(\d\d)(\.\d*)?(?:Z|[ \t]*([-+]\d\d?)(?::(\d\d))?)?$/
|
699
|
+
year, mon, mday, hour, min, sec, usec, tzone_h, tzone_m = $1, $2, $3, $4, $5, $6, $7, $8, $9
|
700
|
+
#Time.utc(sec, min, hour, mday, mon, year, wday, yday, isdst, zone)
|
701
|
+
#t = Time.utc(sec, min, hour, mday, mon, year, nil, nil, nil, nil)
|
702
|
+
#Time.utc(year[, mon[, day[, hour[, min[, sec[, usec]]]]]])
|
703
|
+
time = Time.utc(year, mon, day, hour, min, sec, usec)
|
704
|
+
if tzone_h
|
705
|
+
diff_sec = tzone_h.to_i * 60 * 60
|
706
|
+
if tzone_m
|
707
|
+
if diff_sec > 0 ; diff_sec += tzone_m.to_i * 60
|
708
|
+
else ; diff_sec -= tzone_m.to_i * 60
|
709
|
+
end
|
710
|
+
end
|
711
|
+
p diff_sec
|
712
|
+
time -= diff_sec
|
713
|
+
end
|
714
|
+
return time
|
715
|
+
end
|
716
|
+
return str
|
717
|
+
end
|
718
|
+
|
719
|
+
|
720
|
+
def assert(bool_expr)
|
721
|
+
raise "*** assertion error" unless bool_expr
|
722
|
+
end
|
723
|
+
|
724
|
+
end
|
725
|
+
|
726
|
+
|
727
|
+
|
728
|
+
##
|
729
|
+
## (OBSOLETE) yaml parser
|
730
|
+
##
|
731
|
+
## this class has been obsoleted. use Kwalify::Yaml::Parser instead.
|
732
|
+
##
|
733
|
+
## ex.
|
734
|
+
## # load document with YamlParser
|
735
|
+
## str = ARGF.read()
|
736
|
+
## parser = Kwalify::YamlParser.new(str)
|
737
|
+
## document = parser.parse()
|
738
|
+
##
|
739
|
+
## # validate document
|
740
|
+
## schema = YAML.load(File.read('schema.yaml'))
|
741
|
+
## validator = Kwalify::Validator.new(schema)
|
742
|
+
## errors = validator.validate(document)
|
743
|
+
##
|
744
|
+
## # print validation result
|
745
|
+
## if errors && !errors.empty?
|
746
|
+
## parser.set_errors_linenum(errors)
|
747
|
+
## errors.sort.each do |error|
|
748
|
+
## print "line %d: path %s: %s" % [error.linenum, error.path, error.message]
|
749
|
+
## end
|
750
|
+
## end
|
751
|
+
##
|
752
|
+
class YamlParser < PlainYamlParser
|
753
|
+
|
754
|
+
def initialize(*args)
|
755
|
+
super
|
756
|
+
@linenums_table = {} # object_id -> hash or array
|
757
|
+
end
|
758
|
+
|
759
|
+
def parse()
|
760
|
+
@doc = super()
|
761
|
+
return @doc
|
762
|
+
end
|
763
|
+
|
764
|
+
def path_linenum(path)
|
765
|
+
return 1 if path.empty? || path == '/'
|
766
|
+
elems = path.split('/')
|
767
|
+
elems.shift if path[0] == ?/ # delete empty string on head
|
768
|
+
last_elem = elems.pop
|
769
|
+
c = @doc # collection
|
770
|
+
elems.each do |elem|
|
771
|
+
if c.is_a?(Array)
|
772
|
+
c = c[elem.to_i]
|
773
|
+
elsif c.is_a?(Hash)
|
774
|
+
c = c[elem]
|
775
|
+
else
|
776
|
+
assert false
|
777
|
+
end
|
778
|
+
end
|
779
|
+
linenums = @linenums_table[c.__id__]
|
780
|
+
if c.is_a?(Array)
|
781
|
+
linenum = linenums[last_elem.to_i]
|
782
|
+
elsif c.is_a?(Hash)
|
783
|
+
linenum = linenums[last_elem]
|
784
|
+
end
|
785
|
+
return linenum
|
786
|
+
end
|
787
|
+
|
788
|
+
def set_errors_linenum(errors)
|
789
|
+
errors.each do |error|
|
790
|
+
error.linenum = path_linenum(error.path)
|
791
|
+
end
|
792
|
+
end
|
793
|
+
|
794
|
+
def set_error_linenums(errors)
|
795
|
+
warn "*** Kwalify::YamlParser#set_error_linenums() is obsolete. You should use set_errors_linenum() instead."
|
796
|
+
set_errors_linenum(errors)
|
797
|
+
end
|
798
|
+
|
799
|
+
protected
|
800
|
+
|
801
|
+
def create_sequence(linenum=current_linenum())
|
802
|
+
seq = []
|
803
|
+
@linenums_table[seq.__id__] = []
|
804
|
+
return seq
|
805
|
+
end
|
806
|
+
|
807
|
+
def add_to_seq(seq, value, linenum)
|
808
|
+
seq << value
|
809
|
+
@linenums_table[seq.__id__] << linenum
|
810
|
+
end
|
811
|
+
|
812
|
+
def set_seq_at(seq, i, value, linenum)
|
813
|
+
seq[i] = value
|
814
|
+
@linenums_table[seq.__id__][i] = linenum
|
815
|
+
end
|
816
|
+
|
817
|
+
def create_mapping(linenum=current_linenum())
|
818
|
+
map = {}
|
819
|
+
@linenums_table[map.__id__] = {}
|
820
|
+
return map
|
821
|
+
end
|
822
|
+
|
823
|
+
def add_to_map(map, key, value, linenum)
|
824
|
+
map[key] = value
|
825
|
+
@linenums_table[map.__id__][key] = linenum
|
826
|
+
end
|
827
|
+
|
828
|
+
def set_map_with(map, key, value, linenum)
|
829
|
+
map[key] = value
|
830
|
+
@linenums_table[map.__id__][key] = linenum
|
831
|
+
end
|
832
|
+
|
833
|
+
def set_default(map, value, linenum)
|
834
|
+
map.default = value
|
835
|
+
@linenums_table[map.__id__][:'='] = linenum
|
836
|
+
end
|
837
|
+
|
838
|
+
def merge_map(map, collection, linenum)
|
839
|
+
t = @linenums_table[map.__id__]
|
840
|
+
list = collection.is_a?(Array) ? collection : [ collection ]
|
841
|
+
list.each do |m|
|
842
|
+
t2 = @linenums_table[m.__id__]
|
843
|
+
m.each do |key, val|
|
844
|
+
unless map.key?(key)
|
845
|
+
map[key] = val
|
846
|
+
t[key] = t2[key]
|
847
|
+
end
|
848
|
+
end
|
849
|
+
end
|
850
|
+
end
|
851
|
+
|
852
|
+
def create_scalar(value, linenum=current_linenum())
|
853
|
+
data = super(value)
|
854
|
+
#return Scalar.new(data, linenum)
|
855
|
+
return data
|
856
|
+
end
|
857
|
+
|
858
|
+
end
|
859
|
+
|
860
|
+
|
861
|
+
## alias of YamlParser class
|
862
|
+
class Parser < YamlParser
|
863
|
+
def initialize(yaml_str)
|
864
|
+
super(yaml_str)
|
865
|
+
#warn "*** class Kwalify::Parser is obsolete. Please use Kwalify::YamlParser instead."
|
866
|
+
end
|
867
|
+
end
|
868
|
+
|
869
|
+
|
870
|
+
end
|