maxy-gen 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/maxy/gen/generator.rb +9 -10
- data/lib/maxy/gen/parser.rb +43 -32
- data/lib/maxy/gen/tokenizer.rb +3 -1
- data/lib/maxy/gen/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5207d413af11f892c06645d4a52eb920dc9fdb131bea13311d13285754609b33
|
4
|
+
data.tar.gz: 2fb7405ad16c771c903a0eb6af81947bb577aa528ccf70d62c24a98c6e7a29a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ccd516764930052b407fcf3c2bc4cea320292e9f980eda73cc9e7cf5a1d43ba72a682826e8600a7dad82cef54c7d603127ced8e27b4ae5739cd7f35ad3f6787
|
7
|
+
data.tar.gz: 3fa95ba2e3289e5ef500d3d86c4b030e241886880124053822b08f1a43dacf9e166bf655609b01598dbb2c7c1a78d1917b31c87cf4a47aa2c187433dd472eedf
|
data/lib/maxy/gen/generator.rb
CHANGED
@@ -17,15 +17,17 @@ module Maxy
|
|
17
17
|
raise RuntimeError.new('No object definitions were found. please run `maxy-gen install` first') unless File.exist?("#{ENV['HOME']}/.maxy-gen/library.yml")
|
18
18
|
|
19
19
|
@object_count = 1
|
20
|
-
@patch = Psych.load_file(File.join(__dir__, '../../../assets/blank.yml')).
|
21
|
-
@library = Psych.load_file("#{ENV['HOME']}/.maxy-gen/library.yml").
|
20
|
+
@patch = Psych.load_file(File.join(__dir__, '../../../assets/blank.yml')).dup
|
21
|
+
@library = Psych.load_file("#{ENV['HOME']}/.maxy-gen/library.yml").dup
|
22
22
|
end
|
23
23
|
|
24
|
-
def generate(
|
25
|
-
return JSON.generate(@patch) if
|
24
|
+
def generate(root_node)
|
25
|
+
return JSON.generate(@patch) if root_node.nil?
|
26
26
|
|
27
|
-
node = align_tree(
|
27
|
+
node = align_tree(root_node.child_nodes[0])
|
28
28
|
generate_node(node, "obj_#{@object_count}")
|
29
|
+
@patch['patcher']['boxes'].compact!
|
30
|
+
@patch['patcher']['lines'].compact!
|
29
31
|
JSON.generate(@patch)
|
30
32
|
end
|
31
33
|
|
@@ -38,13 +40,12 @@ module Maxy
|
|
38
40
|
generate_node(child_node, child_id)
|
39
41
|
@patch['patcher']['lines'] << make_line(id, child_id)
|
40
42
|
end
|
41
|
-
|
42
43
|
end
|
43
44
|
|
44
45
|
def make_box(node, id)
|
45
|
-
box = @library[:objects][node.name]
|
46
|
+
box = @library[:objects][node.name].dup
|
46
47
|
box['id'] = id
|
47
|
-
box['patching_rect'] = [OFFSET_X + node.x_rank * STEP_X, OFFSET_Y + node.y_rank * STEP_Y, box['width'] || WIDTH, box['height'] || HEIGHT]
|
48
|
+
box['patching_rect'] = [OFFSET_X + (node.x_rank - 1) * STEP_X, OFFSET_Y + (node.y_rank - 1) * STEP_Y, box['width'] || WIDTH, box['height'] || HEIGHT]
|
48
49
|
unless box['text'].nil?
|
49
50
|
box['text'] += " #{node.args}"
|
50
51
|
end
|
@@ -70,8 +71,6 @@ module Maxy
|
|
70
71
|
node
|
71
72
|
end
|
72
73
|
end
|
73
|
-
#
|
74
|
-
# Box = Struct.new( :id, :node, :x_rank, :y_rank)
|
75
74
|
|
76
75
|
end
|
77
76
|
end
|
data/lib/maxy/gen/parser.rb
CHANGED
@@ -6,25 +6,54 @@ module Maxy
|
|
6
6
|
|
7
7
|
@library = Psych.load_file("#{ENV['HOME']}/.maxy-gen/library.yml").freeze
|
8
8
|
@tokens = tokens
|
9
|
+
@tree = RootNode.new([])
|
10
|
+
@groups = []
|
9
11
|
end
|
10
12
|
|
11
|
-
def parse
|
12
|
-
|
13
|
+
def parse(parent_node=@tree, closing_group=false)
|
14
|
+
if closing_group
|
15
|
+
if peek(:dash) || peek(:identifier) || peek(:escaped_identifier)
|
16
|
+
raise RuntimeError.new("Parsing Error: only + is allowed after a ) closing a group.")
|
17
|
+
end
|
18
|
+
else
|
19
|
+
parse_begin_group parent_node
|
20
|
+
child_node = parse_identifier parent_node
|
21
|
+
parse_dash child_node
|
22
|
+
end
|
23
|
+
|
24
|
+
parse_plus parent_node
|
25
|
+
|
26
|
+
parse_end_group
|
13
27
|
end
|
14
28
|
|
15
|
-
def
|
16
|
-
|
29
|
+
def parse_begin_group(parent)
|
30
|
+
if peek(:oparen)
|
31
|
+
consume(:oparen)
|
32
|
+
@groups << parent
|
33
|
+
end
|
34
|
+
end
|
17
35
|
|
18
|
-
|
36
|
+
def parse_end_group
|
37
|
+
return @tree if @tokens.empty?
|
38
|
+
if peek(:cparen)
|
39
|
+
consume(:cparen)
|
40
|
+
parse(@groups.pop, true)
|
41
|
+
end
|
42
|
+
end
|
19
43
|
|
20
|
-
|
44
|
+
def parse_identifier(parent)
|
45
|
+
if peek(:identifier)
|
46
|
+
obj_name = consume(:identifier).value
|
47
|
+
elsif peek(:escaped_identifier)
|
48
|
+
obj_name = consume(:escaped_identifier).value
|
49
|
+
end
|
21
50
|
|
22
|
-
|
23
|
-
obj_node.child_nodes << new_obj_node unless obj_node.nil?
|
51
|
+
arguments = parse_arguments || ''
|
24
52
|
|
25
|
-
|
53
|
+
raise RuntimeError.new("Could not find #{obj_name} in object definitions.") if @library[:objects][obj_name].nil?
|
26
54
|
|
27
|
-
|
55
|
+
new_obj_node = ObjectNode.new(obj_name, arguments, [])
|
56
|
+
parent.child_nodes << new_obj_node
|
28
57
|
|
29
58
|
new_obj_node
|
30
59
|
end
|
@@ -50,41 +79,23 @@ module Maxy
|
|
50
79
|
@tokens.length > 0 && @tokens.fetch(0).type == expected_type
|
51
80
|
end
|
52
81
|
|
53
|
-
def parse_identifier
|
54
|
-
if peek(:identifier)
|
55
|
-
obj_name = consume(:identifier).value
|
56
|
-
else
|
57
|
-
if peek(:escaped_identifier)
|
58
|
-
obj_name = consume(:escaped_identifier).value
|
59
|
-
end
|
60
|
-
end
|
61
|
-
raise RuntimeError.new("Could not find #{obj_name} in object definitions.") if @library[:objects][obj_name].nil?
|
62
|
-
|
63
|
-
obj_name
|
64
|
-
end
|
65
|
-
|
66
82
|
def parse_plus(obj_node)
|
67
83
|
if peek(:plus)
|
68
84
|
consume(:plus)
|
69
|
-
|
70
|
-
sibling_args = parse_arguments || ''
|
71
|
-
sibling_obj_node = ObjectNode.new(sibling_obj_name, sibling_args, [])
|
72
|
-
obj_node.child_nodes << sibling_obj_node
|
73
|
-
|
74
|
-
parse_plus(obj_node)
|
75
|
-
|
76
|
-
parse_dash(sibling_obj_node)
|
85
|
+
parse(obj_node)
|
77
86
|
end
|
78
87
|
end
|
79
88
|
|
80
89
|
def parse_dash(obj_node)
|
81
90
|
if peek(:dash)
|
82
91
|
consume(:dash)
|
83
|
-
|
92
|
+
parse(obj_node)
|
84
93
|
end
|
85
94
|
end
|
86
95
|
end
|
87
96
|
|
88
97
|
ObjectNode = Struct.new(:name, :args, :child_nodes, :x_rank, :y_rank)
|
98
|
+
RootNode = Struct.new(:child_nodes)
|
99
|
+
|
89
100
|
end
|
90
101
|
end
|
data/lib/maxy/gen/tokenizer.rb
CHANGED
@@ -3,8 +3,10 @@ module Maxy
|
|
3
3
|
class Tokenizer
|
4
4
|
TOKEN_TYPES = [
|
5
5
|
[:arguments, /({[^{}]*})/],
|
6
|
-
[:escaped_identifier, /(\\[\S][^-+{}()\\]
|
6
|
+
[:escaped_identifier, /(\\[\S][^-+{}()\\]*)(?=[-+*{}])?/],
|
7
7
|
[:identifier, /([^-+{}()\\]+)(?=[-+*{}])?/],
|
8
|
+
[:oparen, /(\()/],
|
9
|
+
[:cparen, /(\))/],
|
8
10
|
[:plus, /(\+)/],
|
9
11
|
[:dash, /(-)/]
|
10
12
|
]
|
data/lib/maxy/gen/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maxy-gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Julian Rubisch
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|