enolib 0.5.2 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -11
- data/lib/enolib/elements/element.rb +33 -2
- data/lib/enolib/elements/element_base.rb +8 -5
- data/lib/enolib/elements/section_element.rb +12 -2
- data/lib/enolib/lookup.rb +74 -5
- data/lib/enolib/messages/de.rb +2 -1
- data/lib/enolib/messages/en.rb +2 -1
- data/lib/enolib/messages/es.rb +2 -1
- data/lib/enolib/register.rb +4 -2
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b651313a82b9c6405bbd7153ee2950b72d1f62730591c4db46c4a63f8394096
|
4
|
+
data.tar.gz: 88bd6529c910af0cfdd1494a32201bab3080bce5ad1292431f0b277cfe693365
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b35969b8426c82b861d7ce6f318fd18dacfa29a1c8d287dc1c657612697984912bf4f89f772cc825f69758e9514f821bad6891a935b1a69d78f711839a08672f
|
7
|
+
data.tar.gz: 57cf90bb8901c0f0fd0d437a8aa1e2ebdbd307c020f95b2051351badb2b9660030634594c78a8639a46262a3df1a490c4eb8d81200dc116d2ff5dfce8fe3e946
|
data/README.md
CHANGED
@@ -39,14 +39,4 @@ puts document.field('Greeting').required_string_value #=> 'Hello World!'
|
|
39
39
|
|
40
40
|
## Documentation
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
## Beta notice
|
45
|
-
|
46
|
-
enolib is currently in beta, if you encounter any issues please report them in the issue tracker - thank you for your help!
|
47
|
-
|
48
|
-
## Compatibility notice
|
49
|
-
|
50
|
-
enolib supports the not yet completely ratified [final specification](https://github.com/eno-lang/eno/tree/master/rfcs-final-spec) for eno. You are encouraged to use it in your projects already, thereby helping us to gather insights on whether there are any remaining flaws in the proposed final specifications (you're very welcome to report such issues if you encounter them).
|
51
|
-
|
52
|
-
From a practical point of view there are not likely any major changes ahead. Unless you build your application around edge cases of the exotic language features you should be perfectly safe and future-proof.
|
42
|
+
Available at [eno-lang.org/enolib](https://eno-lang.org/enolib/).
|
@@ -2,6 +2,19 @@
|
|
2
2
|
|
3
3
|
module Enolib
|
4
4
|
class Element < SectionElement
|
5
|
+
def to_document
|
6
|
+
unless @instruction[:type] == :document
|
7
|
+
raise Errors::Validation.unexpected_element_type(@context, nil, @instruction, 'expected_document')
|
8
|
+
end
|
9
|
+
|
10
|
+
unless instance_variable_defined?(:@section)
|
11
|
+
@section = Section.new(@context, @instruction)
|
12
|
+
@yielded = :section
|
13
|
+
end
|
14
|
+
|
15
|
+
@section
|
16
|
+
end
|
17
|
+
|
5
18
|
def to_fieldset_entry
|
6
19
|
unless instance_variable_defined?(:@fieldset_entry)
|
7
20
|
unless @instruction[:type] == :fieldset_entry
|
@@ -27,6 +40,23 @@ module Enolib
|
|
27
40
|
@list_item
|
28
41
|
end
|
29
42
|
|
43
|
+
def to_s
|
44
|
+
"#<Enolib::Element key=#{_key} yields=#{_yields}>"
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_section
|
48
|
+
unless instance_variable_defined?(:@section)
|
49
|
+
unless @instruction[:type] == :section || @instruction[:type] == :document
|
50
|
+
raise Errors::Validation.unexpected_element_type(@context, nil, @instruction, 'expected_section')
|
51
|
+
end
|
52
|
+
|
53
|
+
@section = Section.new(@context, @instruction)
|
54
|
+
@yielded = :section
|
55
|
+
end
|
56
|
+
|
57
|
+
@section
|
58
|
+
end
|
59
|
+
|
30
60
|
def yields_fieldset_entry?
|
31
61
|
@instruction[:type] == :fieldset_entry
|
32
62
|
end
|
@@ -35,8 +65,9 @@ module Enolib
|
|
35
65
|
@instruction[:type] == :list_item
|
36
66
|
end
|
37
67
|
|
38
|
-
def
|
39
|
-
|
68
|
+
def yields_section?
|
69
|
+
@instruction[:type] == :section ||
|
70
|
+
@instruction[:type] == :document
|
40
71
|
end
|
41
72
|
end
|
42
73
|
end
|
@@ -52,6 +52,10 @@ module Enolib
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
+
# TODO: All implementations - this could be called on the document (?),
|
56
|
+
# via both element and section, most likely triggering erratic behavior
|
57
|
+
# because the error->selection chain does not handle the missing key range?
|
58
|
+
# (Also being able to call it and doing so does not make sense in the first place)
|
55
59
|
def key_error(message = nil)
|
56
60
|
if block_given?
|
57
61
|
message = yield(_key)
|
@@ -131,11 +135,10 @@ module Enolib
|
|
131
135
|
end
|
132
136
|
|
133
137
|
def _key
|
134
|
-
if @instruction[:type] == :
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
end
|
138
|
+
return nil if @instruction[:type] == :document
|
139
|
+
return @instruction[:parent][:key] if @instruction[:type] == :list_item
|
140
|
+
|
141
|
+
@instruction[:key]
|
139
142
|
end
|
140
143
|
end
|
141
144
|
end
|
@@ -85,6 +85,10 @@ module Enolib
|
|
85
85
|
@list
|
86
86
|
end
|
87
87
|
|
88
|
+
def to_s
|
89
|
+
"#<Enolib::SectionElement key=#{_key} yields=#{_yields}>"
|
90
|
+
end
|
91
|
+
|
88
92
|
def to_section
|
89
93
|
unless instance_variable_defined?(:@section)
|
90
94
|
unless @instruction[:type] == :section
|
@@ -134,8 +138,14 @@ module Enolib
|
|
134
138
|
@instruction[:type] == :section
|
135
139
|
end
|
136
140
|
|
137
|
-
|
138
|
-
|
141
|
+
private
|
142
|
+
|
143
|
+
def _yields
|
144
|
+
if @instruction[:type] == :empty_element
|
145
|
+
return "#{PRETTY_TYPES[:empty_element]},#{PRETTY_TYPES[:field]},#{PRETTY_TYPES[:fieldset]},#{PRETTY_TYPES[:list]}"
|
146
|
+
end
|
147
|
+
|
148
|
+
PRETTY_TYPES[@instruction[:type]]
|
139
149
|
end
|
140
150
|
end
|
141
151
|
end
|
data/lib/enolib/lookup.rb
CHANGED
@@ -67,7 +67,17 @@ def check_fieldset_by_line(fieldset, line)
|
|
67
67
|
|
68
68
|
fieldset[:entries].each do |entry|
|
69
69
|
return { element: entry, instruction: entry } if line == entry[:line]
|
70
|
-
|
70
|
+
|
71
|
+
if line < entry[:line]
|
72
|
+
if entry.has_key?(:comments) && line >= entry[:comments][0][:line]
|
73
|
+
return {
|
74
|
+
element: entry,
|
75
|
+
instruction: entry[:comments].find { |comment| line == comment[:line] }
|
76
|
+
}
|
77
|
+
end
|
78
|
+
|
79
|
+
return { element: fieldset, instruction: nil }
|
80
|
+
end
|
71
81
|
|
72
82
|
match_in_entry = check_field_by_line(entry, line)
|
73
83
|
|
@@ -82,7 +92,17 @@ def check_fieldset_by_index(fieldset, index)
|
|
82
92
|
index <= fieldset[:entries].last[:ranges][:line][RANGE_END]
|
83
93
|
|
84
94
|
fieldset[:entries].each do |entry|
|
85
|
-
|
95
|
+
if index < entry[:ranges][:line][RANGE_BEGIN]
|
96
|
+
if entry.has_key?(:comments) && index >= entry[:comments][0][:ranges][:line][RANGE_BEGIN]
|
97
|
+
return {
|
98
|
+
element: entry,
|
99
|
+
instruction: entry[:comments].find { |comment| index <= comment[:ranges][:line][RANGE_END] }
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
return { element: fieldset, instruction: nil }
|
104
|
+
end
|
105
|
+
|
86
106
|
return { element: entry, instruction: entry } if index <= entry[:ranges][:line][RANGE_END]
|
87
107
|
|
88
108
|
match_in_entry = check_field_by_index(entry, index)
|
@@ -98,7 +118,17 @@ def check_list_by_line(list, line)
|
|
98
118
|
|
99
119
|
list[:items].each do |item|
|
100
120
|
return { element: item, instruction: item } if line == item[:line]
|
101
|
-
|
121
|
+
|
122
|
+
if line < item[:line]
|
123
|
+
if item.has_key?(:comments) && line >= item[:comments][0][:line]
|
124
|
+
return {
|
125
|
+
element: item,
|
126
|
+
instruction: item[:comments].find { |comment| line == comment[:line] }
|
127
|
+
}
|
128
|
+
end
|
129
|
+
|
130
|
+
return { element: list, instruction: nil }
|
131
|
+
end
|
102
132
|
|
103
133
|
match_in_item = check_field_by_line(item, line)
|
104
134
|
|
@@ -113,7 +143,17 @@ def check_list_by_index(list, index)
|
|
113
143
|
index > list[:items].last[:ranges][:line][RANGE_END]
|
114
144
|
|
115
145
|
list[:items].each do |item|
|
116
|
-
|
146
|
+
if index < item[:ranges][:line][RANGE_BEGIN]
|
147
|
+
if item.has_key?(:comments) && index >= item[:comments][0][:ranges][:line][RANGE_BEGIN]
|
148
|
+
return {
|
149
|
+
element: item,
|
150
|
+
instruction: item[:comments].find { |comment| index <= comment[:ranges][:line][RANGE_END] }
|
151
|
+
}
|
152
|
+
end
|
153
|
+
|
154
|
+
return { element: list, instruction: nil }
|
155
|
+
end
|
156
|
+
|
117
157
|
return { element: item, instruction: item } if index <= item[:ranges][:line][RANGE_END]
|
118
158
|
|
119
159
|
match_in_item = check_field_by_index(item, index)
|
@@ -124,6 +164,17 @@ end
|
|
124
164
|
|
125
165
|
def check_in_section_by_line(section, line)
|
126
166
|
section[:elements].reverse_each do |element|
|
167
|
+
if element.has_key?(:comments)
|
168
|
+
next if line < element[:comments][0][:line]
|
169
|
+
|
170
|
+
if line <= element[:comments][-1][:line]
|
171
|
+
return {
|
172
|
+
element: element,
|
173
|
+
instruction: element[:comments].find { |comment| line == comment[:line] }
|
174
|
+
}
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
127
178
|
next if element[:line] > line
|
128
179
|
|
129
180
|
return { element: element, instruction: element } if element[:line] == line
|
@@ -155,6 +206,17 @@ end
|
|
155
206
|
|
156
207
|
def check_in_section_by_index(section, index)
|
157
208
|
section[:elements].reverse_each do |element|
|
209
|
+
if element.has_key?(:comments)
|
210
|
+
next if index < element[:comments][0][:ranges][:line][RANGE_BEGIN]
|
211
|
+
|
212
|
+
if index <= element[:comments][-1][:ranges][:line][RANGE_END]
|
213
|
+
return {
|
214
|
+
element: element,
|
215
|
+
instruction: element[:comments].find { |comment| index <= comment[:ranges][:line][RANGE_END] }
|
216
|
+
}
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
158
220
|
next if index < element[:ranges][:line][RANGE_BEGIN]
|
159
221
|
|
160
222
|
return { element: element, instruction: element } if index <= element[:ranges][:line][RANGE_END]
|
@@ -211,7 +273,14 @@ module Enolib
|
|
211
273
|
instruction = match[:instruction]
|
212
274
|
|
213
275
|
unless instruction
|
214
|
-
|
276
|
+
if index
|
277
|
+
instruction = context.meta.find do |candidate|
|
278
|
+
index >= candidate[:ranges][:line][RANGE_BEGIN] && index <= candidate[:ranges][:line][RANGE_END]
|
279
|
+
end
|
280
|
+
else
|
281
|
+
instruction = context.meta.find { |candidate| candidate[:line] == line }
|
282
|
+
end
|
283
|
+
|
215
284
|
return result unless instruction
|
216
285
|
end
|
217
286
|
|
data/lib/enolib/messages/de.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# GENERATED ON 2019-
|
3
|
+
# GENERATED ON 2019-05-29T07:40:09 - DO NOT EDIT MANUALLY
|
4
4
|
|
5
5
|
module Enolib
|
6
6
|
module Messages
|
7
7
|
module De
|
8
8
|
CONTENT_HEADER = 'Inhalt'
|
9
|
+
EXPECTED_DOCUMENT = 'Das Dokument wurde erwartet.'
|
9
10
|
EXPECTED_EMPTY = 'Ein leeres Element wurde erwartet.'
|
10
11
|
EXPECTED_FIELD = 'Ein Feld wurde erwartet.'
|
11
12
|
EXPECTED_FIELDS = 'Nur Felder wurden erwartet.'
|
data/lib/enolib/messages/en.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# GENERATED ON 2019-
|
3
|
+
# GENERATED ON 2019-05-29T07:40:09 - DO NOT EDIT MANUALLY
|
4
4
|
|
5
5
|
module Enolib
|
6
6
|
module Messages
|
7
7
|
module En
|
8
8
|
CONTENT_HEADER = 'Content'
|
9
|
+
EXPECTED_DOCUMENT = 'The document was expected.'
|
9
10
|
EXPECTED_EMPTY = 'An empty element was expected.'
|
10
11
|
EXPECTED_FIELD = 'A field was expected.'
|
11
12
|
EXPECTED_FIELDS = 'Only fields were expected.'
|
data/lib/enolib/messages/es.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# GENERATED ON 2019-
|
3
|
+
# GENERATED ON 2019-05-29T07:40:09 - DO NOT EDIT MANUALLY
|
4
4
|
|
5
5
|
module Enolib
|
6
6
|
module Messages
|
7
7
|
module Es
|
8
8
|
CONTENT_HEADER = 'Contenido'
|
9
|
+
EXPECTED_DOCUMENT = 'Se esperaba el documento.'
|
9
10
|
EXPECTED_EMPTY = 'Se esperaba un elemento vacío.'
|
10
11
|
EXPECTED_FIELD = 'Se esperaba una casilla.'
|
11
12
|
EXPECTED_FIELDS = 'Solo se esperaban casillas.'
|
data/lib/enolib/register.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# TODO: Safe-guard against conflicting loader names (e.g. previous definition or native library function conflict)
|
4
|
-
|
5
3
|
module Enolib
|
6
4
|
def self.register(definitions)
|
7
5
|
definitions.each do |name, loader|
|
6
|
+
if name == :string
|
7
|
+
raise ArgumentError, "You cannot register 'string' as a type/loader with enolib as this conflicts with the native string type accessors."
|
8
|
+
end
|
9
|
+
|
8
10
|
ElementBase.send(:define_method, "#{name}_key") { key(loader) }
|
9
11
|
ElementBase.send(:define_method, "optional_#{name}_comment") { optional_comment(loader) }
|
10
12
|
ElementBase.send(:define_method, "required_#{name}_comment") { required_comment(loader) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enolib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Repp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deep-cover
|
@@ -16,70 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.7.
|
19
|
+
version: 0.7.4
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.7.
|
26
|
+
version: 0.7.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 3.8.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 3.8.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec-cheki
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 0.1.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.1.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.68.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 0.68.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rubocop-performance
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.3.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.3.0
|
83
83
|
description: The cross-language eno standard library
|
84
84
|
email: simon@fdpl.io
|
85
85
|
executables: []
|