slow_blink 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/slow_blink/ext_schema_parser/common.h +27 -0
- data/ext/slow_blink/ext_schema_parser/extconf.rb +3 -0
- data/ext/slow_blink/ext_schema_parser/lexer.c +2701 -0
- data/ext/slow_blink/ext_schema_parser/lexer.h +486 -0
- data/ext/slow_blink/ext_schema_parser/parser.c +3848 -0
- data/ext/slow_blink/ext_schema_parser/parser.h +110 -0
- data/ext/slow_blink/ext_schema_parser/parser.l +139 -0
- data/ext/slow_blink/ext_schema_parser/parser.y +932 -0
- data/lib/slow_blink/annotatable.rb +46 -0
- data/lib/slow_blink/annotation.rb +38 -0
- data/lib/slow_blink/compact_encoder.rb +97 -0
- data/lib/slow_blink/component_reference.rb +50 -0
- data/lib/slow_blink/definition.rb +57 -0
- data/lib/slow_blink/enumeration.rb +105 -0
- data/lib/slow_blink/error.rb +4 -0
- data/lib/slow_blink/field.rb +82 -0
- data/lib/slow_blink/group.rb +129 -0
- data/lib/slow_blink/incremental_annotation.rb +91 -0
- data/lib/slow_blink/message.rb +43 -0
- data/lib/slow_blink/name_with_id.rb +49 -0
- data/lib/slow_blink/schema.rb +135 -0
- data/lib/slow_blink/sym.rb +54 -0
- data/lib/slow_blink/type.rb +448 -0
- data/lib/slow_blink/version.rb +22 -0
- data/lib/slow_blink.rb +20 -0
- data/rakefile +29 -0
- data/test/integration/capture_stderr.rb +20 -0
- data/test/integration/tc_inputs.rb +57 -0
- metadata +36 -5
@@ -0,0 +1,91 @@
|
|
1
|
+
# Copyright (c) 2016 Cameron Harper
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
module SlowBlink
|
21
|
+
|
22
|
+
# Blink Specification 7.3
|
23
|
+
class IncrementalAnnotation
|
24
|
+
|
25
|
+
attr_reader :ref
|
26
|
+
attr_reader :annotes
|
27
|
+
attr_reader :location
|
28
|
+
|
29
|
+
# @private
|
30
|
+
#
|
31
|
+
# @param ref [SchemaRef, DefinitionRef, DefinitionTypeRef, FieldRef, FieldTypeRef] annotation target
|
32
|
+
# @param annotations [Array<Integer,Annotation>]
|
33
|
+
# @param location [String]
|
34
|
+
def initialize(ref, annotes, location)
|
35
|
+
@ref = ref
|
36
|
+
@annotes = annotes
|
37
|
+
@location = location
|
38
|
+
@schema = nil
|
39
|
+
end
|
40
|
+
|
41
|
+
# @private
|
42
|
+
#
|
43
|
+
# Apply annotes to targets
|
44
|
+
#
|
45
|
+
# @macro common_link
|
46
|
+
def link(schema, stack=[])
|
47
|
+
if @schema != schema
|
48
|
+
@schema = nil
|
49
|
+
case @ref.class
|
50
|
+
when SchemaRef
|
51
|
+
schema.annote(@annotes)
|
52
|
+
@schema = schema
|
53
|
+
when DefinitionRef
|
54
|
+
object = schema.symbol(ref.qName)
|
55
|
+
if object
|
56
|
+
object.nameWithID.annote(@annotes)
|
57
|
+
@schema = schema
|
58
|
+
end
|
59
|
+
when DefinitionTypeRef
|
60
|
+
object = schema.symbol(ref.qName)
|
61
|
+
if object
|
62
|
+
object.enumOrType.annote(@annotes)
|
63
|
+
@schema = schema
|
64
|
+
end
|
65
|
+
when FieldRef
|
66
|
+
object = schema.symbol(ref.qName)
|
67
|
+
if object
|
68
|
+
field = object.field(ref.name)
|
69
|
+
if field
|
70
|
+
field.nameWithID.annote(@annotes)
|
71
|
+
@schema = schema
|
72
|
+
end
|
73
|
+
end
|
74
|
+
when FieldTypeRef
|
75
|
+
object = schema.symbol(ref.qName)
|
76
|
+
if object
|
77
|
+
field = object.field(ref.name)
|
78
|
+
if field
|
79
|
+
field.type.annote(@annotes)
|
80
|
+
@schema = schema
|
81
|
+
end
|
82
|
+
end
|
83
|
+
else
|
84
|
+
raise "unknown component reference".freeze
|
85
|
+
end
|
86
|
+
end
|
87
|
+
@schema
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module SlowBlink
|
2
|
+
|
3
|
+
class Message
|
4
|
+
|
5
|
+
# Create Message
|
6
|
+
#
|
7
|
+
# @param schema [Schema]
|
8
|
+
# @param input [Hash] Blink JSON Format
|
9
|
+
# @param **opts [Hash] options
|
10
|
+
def initialize(schema, input, **opts)
|
11
|
+
@schema = schema
|
12
|
+
@input = input
|
13
|
+
@input.each do |i|
|
14
|
+
@schema.group(type).validate(i)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Convert compact form encoding to a message according to schema
|
19
|
+
#
|
20
|
+
# @param schema [Schema]
|
21
|
+
# @param input [String] compact form encoding
|
22
|
+
# @return [Message]
|
23
|
+
def self.from_compact(schema, input)
|
24
|
+
raise
|
25
|
+
end
|
26
|
+
|
27
|
+
# Convert message to compact form encoding
|
28
|
+
#
|
29
|
+
# @return [String] compact form encoding
|
30
|
+
def to_compact
|
31
|
+
@schema.group(@input["$group"]).encode_compact(@input)
|
32
|
+
end
|
33
|
+
|
34
|
+
# Convert message to Blink JSON format
|
35
|
+
#
|
36
|
+
# @return [String] Blink JSON format
|
37
|
+
def to_json
|
38
|
+
@input
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# Copyright (c) 2016 Cameron Harper
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
module SlowBlink
|
21
|
+
class NameWithID
|
22
|
+
|
23
|
+
include Annotatable
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
attr_reader :name
|
27
|
+
|
28
|
+
# @return [Integer]
|
29
|
+
# @return [nil]
|
30
|
+
attr_reader :id
|
31
|
+
|
32
|
+
# @private
|
33
|
+
#
|
34
|
+
# @param name [String]
|
35
|
+
# @param id [nil,Integer]
|
36
|
+
def initialize(name, id)
|
37
|
+
@name = name
|
38
|
+
@id = id
|
39
|
+
end
|
40
|
+
|
41
|
+
# @private
|
42
|
+
#
|
43
|
+
# @param value [Integer]
|
44
|
+
def id=(value)
|
45
|
+
@id = id
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
# Copyright (c) 2016 Cameron Harper
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
require 'slow_blink/annotatable'
|
21
|
+
|
22
|
+
# @!macro [new] common_link
|
23
|
+
#
|
24
|
+
# Resolve symbols to definitions in schema
|
25
|
+
#
|
26
|
+
# @param schema [Schema] schema to link
|
27
|
+
# @param stack [Array]
|
28
|
+
#
|
29
|
+
# @return [Schema] linked
|
30
|
+
# @return [nil] not linked
|
31
|
+
#
|
32
|
+
|
33
|
+
module SlowBlink
|
34
|
+
|
35
|
+
class Schema
|
36
|
+
|
37
|
+
include Annotatable
|
38
|
+
|
39
|
+
# @!method self.parse(input, **opts)
|
40
|
+
#
|
41
|
+
# Initialise a Schema object from Blink Schema input string
|
42
|
+
#
|
43
|
+
# @param input [String] Blink Schema
|
44
|
+
# @param opts [Hash] options
|
45
|
+
# @option opts [String] :fileName file input originated from (for error messages)
|
46
|
+
# @return [Schema]
|
47
|
+
|
48
|
+
# @param namespace [nil,String]
|
49
|
+
# @param defs [Array<Definition>]
|
50
|
+
def initialize(namespace, defs)
|
51
|
+
@nameWithID = NameWithID.new(nil,nil)
|
52
|
+
@annotes = []
|
53
|
+
@groups = {}
|
54
|
+
errors = 0
|
55
|
+
|
56
|
+
if namespace
|
57
|
+
@namespace = namespace
|
58
|
+
else
|
59
|
+
@namespace = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
@defs = {}
|
63
|
+
|
64
|
+
# populate table of definitions
|
65
|
+
defs.each do |d|
|
66
|
+
if !d.is_a? IncrementalAnnotation
|
67
|
+
if @defs[d.nameWithID.name]
|
68
|
+
puts "#{d.location}: error: duplicate definition name"
|
69
|
+
errors += 1
|
70
|
+
else
|
71
|
+
@defs[d.nameWithID.name] = d
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# now apply incremental annotation
|
77
|
+
defs.each do |d|
|
78
|
+
if d === IncrementalAnnotation
|
79
|
+
d.link(schema)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# now link the definitions
|
84
|
+
@defs.each do |name, d|
|
85
|
+
if !d.link(self)
|
86
|
+
errors += 1
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
if errors > 0
|
91
|
+
raise Error.new "#{errors} errors"
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
# @param name [String] definition or group name
|
97
|
+
# @return [Definition]
|
98
|
+
# @return [Group]
|
99
|
+
def symbol(name)
|
100
|
+
@defs[name]
|
101
|
+
end
|
102
|
+
|
103
|
+
# @param nameOrID [String,Integer] group name or id
|
104
|
+
# @return [Group] group exists
|
105
|
+
# @return [nil] group does not exist
|
106
|
+
def group(nameOrID)
|
107
|
+
if nameOrID.kind_of? String
|
108
|
+
@groups[nameOrID]
|
109
|
+
else
|
110
|
+
@groups.values.detect{|g|g.nameWithID.id == nameOrID}
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
end
|
117
|
+
|
118
|
+
require 'slow_blink/compact_encoder'
|
119
|
+
require 'slow_blink/error'
|
120
|
+
require 'slow_blink/version'
|
121
|
+
require 'slow_blink/annotation'
|
122
|
+
require 'slow_blink/incremental_annotation'
|
123
|
+
require 'slow_blink/group'
|
124
|
+
require 'slow_blink/field'
|
125
|
+
require 'slow_blink/component_reference'
|
126
|
+
require 'slow_blink/definition'
|
127
|
+
require 'slow_blink/type'
|
128
|
+
require 'slow_blink/enumeration'
|
129
|
+
require 'slow_blink/sym'
|
130
|
+
require 'slow_blink/name_with_id'
|
131
|
+
require 'slow_blink/ext_schema_parser'
|
132
|
+
require 'slow_blink/message'
|
133
|
+
|
134
|
+
|
135
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (c) 2016 Cameron Harper
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
# this software and associated documentation files (the "Software"), to deal in
|
5
|
+
# the Software without restriction, including without limitation the rights to
|
6
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
# subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
11
|
+
# copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
19
|
+
|
20
|
+
module SlowBlink
|
21
|
+
class Sym
|
22
|
+
|
23
|
+
include Annotatable
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
attr_reader :location
|
27
|
+
|
28
|
+
# @return [String]
|
29
|
+
attr_reader :name
|
30
|
+
|
31
|
+
# @return [Integer]
|
32
|
+
attr_reader :val
|
33
|
+
|
34
|
+
# @private
|
35
|
+
#
|
36
|
+
# @param name [String]
|
37
|
+
# @param val [nil,Integer] explicit value
|
38
|
+
# @param location [String]
|
39
|
+
def initialize(name, val, location)
|
40
|
+
@name = name
|
41
|
+
@val = val
|
42
|
+
@annotes = {}
|
43
|
+
@location = location
|
44
|
+
end
|
45
|
+
|
46
|
+
# @private
|
47
|
+
#
|
48
|
+
# @macro common_link
|
49
|
+
def link(schema, stack=[])
|
50
|
+
@schema = schema
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|