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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddf1d556c1b563928dac5451b7e431034ab0265f1599a6f075c2fbe9cea47777
4
- data.tar.gz: 29b360138505a3700dc6a38abc8ac989673a0bb0a42c18484733eccfe994b1eb
3
+ metadata.gz: 5207d413af11f892c06645d4a52eb920dc9fdb131bea13311d13285754609b33
4
+ data.tar.gz: 2fb7405ad16c771c903a0eb6af81947bb577aa528ccf70d62c24a98c6e7a29a1
5
5
  SHA512:
6
- metadata.gz: 5930cfb96c88d5deb47e186f685dbb3cb113609cca68d4fae099e2a6ac854a21c12e41467eae434cb1523f0378554a6d5bef1a625c282b39ed341c0cf7833bb5
7
- data.tar.gz: 3e55e67c6e5b0c246c4edb0be123f57cbf6b5c6fd0ace130cf4b67f0b68328576e9e6e4b88079e9fa306b3d62da7e1d8605a6a9fad23fd13880b92aca9b6b799
6
+ metadata.gz: 4ccd516764930052b407fcf3c2bc4cea320292e9f980eda73cc9e7cf5a1d43ba72a682826e8600a7dad82cef54c7d603127ced8e27b4ae5739cd7f35ad3f6787
7
+ data.tar.gz: 3fa95ba2e3289e5ef500d3d86c4b030e241886880124053822b08f1a43dacf9e166bf655609b01598dbb2c7c1a78d1917b31c87cf4a47aa2c187433dd472eedf
@@ -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')).freeze
21
- @library = Psych.load_file("#{ENV['HOME']}/.maxy-gen/library.yml").freeze
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(node)
25
- return JSON.generate(@patch) if node.nil?
24
+ def generate(root_node)
25
+ return JSON.generate(@patch) if root_node.nil?
26
26
 
27
- node = align_tree(node)
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
@@ -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
- parse_obj
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 parse_obj(obj_node=nil)
16
- return if @tokens.length == 0
29
+ def parse_begin_group(parent)
30
+ if peek(:oparen)
31
+ consume(:oparen)
32
+ @groups << parent
33
+ end
34
+ end
17
35
 
18
- obj_name = parse_identifier
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
- arguments = parse_arguments || ''
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
- new_obj_node = ObjectNode.new(obj_name, arguments, [])
23
- obj_node.child_nodes << new_obj_node unless obj_node.nil?
51
+ arguments = parse_arguments || ''
24
52
 
25
- parse_plus(obj_node)
53
+ raise RuntimeError.new("Could not find #{obj_name} in object definitions.") if @library[:objects][obj_name].nil?
26
54
 
27
- parse_dash(new_obj_node)
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
- sibling_obj_name = parse_identifier
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
- parse_obj(obj_node)
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
@@ -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
  ]
@@ -1,5 +1,5 @@
1
1
  module Maxy
2
2
  module Gen
3
- VERSION = "0.2.2"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
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.2.2
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-06 00:00:00.000000000 Z
11
+ date: 2018-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler