Top Level Namespace
Defined Under Namespace
Classes: Bare, BareException, BareTypes, CircularSchema, EnumValueError, FixedDataSizeWrong, InvalidBool, MapKeyError, MaximumSizeError, MinimumSizeError, NoTypeProvided, Parser, ReferenceException, SchemaMismatch, SchemaParsingException, SeenList, VoidUsedOutsideTaggedSet
Constant Summary
collapse
- DATA_MAX_SIZE =
30000
- ARRAY_MAX_SIZE =
40
- STRUCT_FIELDS_MAX =
5
Instance Method Summary
collapse
Instance Method Details
#_get_next_7_bits_as_byte(integer, base = 128) ⇒ Object
822
823
824
825
826
827
828
829
830
831
832
833
|
# File 'lib/types.rb', line 822
def _get_next_7_bits_as_byte(integer, base = 128)
groups_of_7 = (integer.size * 8) / 7 + (integer.size % 7 == 0 ? 0 : 1)
0.upto(groups_of_7 - 1) do |group_number|
byte = base
0.upto(7).each do |bit_number|
byte = byte | (integer[group_number * 7 + bit_number] << bit_number)
end
yield(byte)
end
end
|
#create_user_type_name ⇒ Object
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/generative_testing/grammar_util.rb', line 1
def create_user_type_name
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lower = upper.downcase
digit = "0123456789"
name = upper[rand(upper.size)]
loop do
if rand(50) < 5
break
end
num = rand(3)
if num == 0
name << upper[rand(upper.size)]
elsif num == 1
name << lower[rand(lower.size)]
else
name << digit[rand(digit.size)]
end
end
name.to_sym
end
|
#get_type(depth, names = [], can_be_symbol = true) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/generative_testing/gen.rb', line 5
def get_type(depth, names = [], can_be_symbol = true)
if names.size == 0
can_be_symbol = false
end
terminators = [BareTypes::Data, BareTypes::DataFixedLen,
BareTypes::U8, BareTypes::U16, BareTypes::U32, BareTypes::U64,
BareTypes::I8, BareTypes::I16, BareTypes::I32, BareTypes::I64,
BareTypes::F32, BareTypes::F64]
aggregates = [BareTypes::Array, BareTypes::ArrayFixedLen,
BareTypes::Struct]
all = terminators + aggregates
if rand(5) == 0 && names.size != 1 && can_be_symbol
names[rand(names.size)]
elsif depth >= 10 all[rand(terminators.size)].make(depth + 1, names)
else
all[rand(all.size)].make(depth + 1, names)
end
end
|
#lexer(path) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/lexer.rb', line 3
def lexer(path)
tokens = []
line_num = 0
file = File.open(path)
file.each do |line|
while line.size > 0
if /^#/.match(line)
break
elsif /^\n/.match(line)
break
elsif /^ /.match(line)
line = line[1..line.size]
elsif /^</.match(line)
line = line[1..line.size]
tokens << :less_than
elsif /^>/.match(line)
line = line[1..line.size]
tokens << :greater_than
next
elsif /^{/.match(line)
line = line[1..line.size]
tokens << :open_block
elsif /^=/.match(line)
line = line[1..line.size]
tokens << :equal
elsif /^}/.match(line)
line = line[1..line.size]
tokens << :close_block
elsif /^\[/.match(line)
line = line[1..line.size]
tokens << :open_brace
elsif /^\]/.match(line)
line = line[1..line.size]
tokens << :close_brace
elsif /^\(/.match(line)
line = line[1..line.size]
tokens << :open_paren
elsif /^\)/.match(line)
line = line[1..line.size]
tokens << :close_paren
elsif /^\|/.match(line)
line = line[1..line.size]
tokens << :bar
elsif match = /^([0-9]+)/.match(line)
tokens << match[0].to_i
line = line[(match[0].size)..line.size]
next
elsif match = /^[a-z,A-Z,_][_,a-z,A-Z,0-9]*/.match(line)
tokens << match[0]
line = line[(match[0].size)..line.size]
elsif /:/.match(line)
tokens << :colon
line = line[1..line.size]
else
raise SchemaParsingException.new("Unable to lex line #{line_num} near #{line.inspect}")
end
end
line_num += 1
end
return tokens
end
|
#parser(tokens, definitions = {}) ⇒ Object
146
147
148
149
150
|
# File 'lib/parser.rb', line 146
def parser(tokens, definitions = {})
parser = Parser.new
parser.parse(tokens)
return parser.definitions
end
|