tickly 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/tickly/parser.rb CHANGED
@@ -85,20 +85,6 @@ module Tickly
85
85
  return buf
86
86
  end
87
87
 
88
- def expand_one_elements!(expr)
89
- expr.map! do | element |
90
- if expr?(element) && element.length == 1 && element[0].class == element.class
91
- element[0]
92
- else
93
- element
94
- end
95
- end
96
- end
97
-
98
- def remove_empty_elements!(expr)
99
- expr.reject! {|e| expr?(e) && e.empty? }
100
- end
101
-
102
88
  # Tells whether a passed object is a StringExpr or LiteralExpr
103
89
  def expr?(something)
104
90
  [StringExpr, LiteralExpr].include?(something.class)
@@ -107,18 +93,10 @@ module Tickly
107
93
  # Cleans up a subexpression stack. Currently it only removes nil objects
108
94
  # in-between items (which act as line separators)
109
95
  def cleanup(expr)
110
- # Expand one-element expressions of the same class
111
- #expand_one_elements!(expr)
112
-
113
- # Remove empty subexprs
114
- #remove_empty_elements!(expr)
115
-
116
- # Squeeze out the leading and trailing nils
117
- expr.delete_at(0) while (expr.any? && expr[0].nil?)
118
- expr.delete_at(-1) while (expr.any? && expr[-1].nil?)
119
-
96
+ # Ensure multiple consecutive line breaks are ignored
97
+ no_multiple_breaks = Tickly.singularize_nils_in(expr)
120
98
  # Convert line breaks into subexpressions
121
- Tickly.split_array(expr)
99
+ Tickly.split_array(no_multiple_breaks)
122
100
  end
123
101
 
124
102
  end
data/lib/tickly.rb CHANGED
@@ -3,13 +3,13 @@ require File.dirname(__FILE__) + "/tickly/evaluator"
3
3
  require 'forwardable'
4
4
 
5
5
  module Tickly
6
- VERSION = '0.0.2'
6
+ VERSION = '0.0.3'
7
7
 
8
8
  # Represents a TCL expression with it's arguments (in curly or square braces)
9
9
  class Expr
10
10
  extend Forwardable
11
11
 
12
- def_delegators :@e, :push, :<<, :any?, :reject!, :map!, :[], :delete_at, :include?, :each, :empty?, :join, :length
12
+ def_delegators :@e, :push, :<<, :any?, :reject!, :map!, :[], :delete_at, :include?, :each, :each_with_index, :empty?, :join, :length
13
13
 
14
14
  def initialize(elements = [])
15
15
  @e = elements
@@ -73,19 +73,39 @@ module Tickly
73
73
  end
74
74
  end
75
75
 
76
+ # Splits the passed Array-like object into sub-arrays of the same class,
77
+ # delimited by the passed separator. Note that when the separators occur at the beginning or at the end of
78
+ # the passed object they will be discarded
76
79
  def self.split_array(arr, separator = nil)
77
80
  return arr unless arr.include?(separator)
78
81
 
79
82
  subarrays = arr.class.new
80
83
  subarrays.push(arr.class.new)
81
84
 
82
- arr.each do | element |
83
- if element == separator
85
+ arr.each_with_index do | element, i |
86
+ if element == separator && subarrays.length > 0 && subarrays[-1].any? && (i < (arr.length - 1))
84
87
  subarrays.push(arr.class.new)
88
+ elsif element == separator
89
+ # toss it
85
90
  else
86
91
  subarrays[-1].push(element)
87
92
  end
88
93
  end
89
94
  return subarrays
90
95
  end
96
+
97
+ # Removes consecutive nils from the passed Array-like object and returns a new one with all consecutive nils reduced
98
+ # to one nil
99
+ def self.singularize_nils_in(arr)
100
+ new_arr = arr.class.new
101
+ arr.each_with_index do | elem, i |
102
+ if elem.nil? && arr[i-1].nil? && i > 0
103
+ # pass
104
+ else
105
+ new_arr << elem
106
+ end
107
+ end
108
+ new_arr
109
+ end
110
+
91
111
  end
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ SomeNode {
2
+ foo bar
3
+ }
data/test/test_parser.rb CHANGED
@@ -53,7 +53,7 @@ class TestParser < Test::Unit::TestCase
53
53
  end
54
54
 
55
55
  should 'parse a Nuke node' do
56
- f = File.open(File.dirname(__FILE__) + "/nukenode.txt")
56
+ f = File.open(File.dirname(__FILE__) + "/test-data/nukenode.txt")
57
57
  p = P.parse(f)
58
58
  script = le(
59
59
  le("set", "cut_paste_input", se("stack", "0")),
@@ -78,7 +78,7 @@ class TestParser < Test::Unit::TestCase
78
78
  end
79
79
 
80
80
  should 'parse a simple Nuke script and internalize the RotoPaint in it' do
81
- f = File.open(File.dirname(__FILE__) + "/three_nodes_and_roto.txt")
81
+ f = File.open(File.dirname(__FILE__) + "/test-data/three_nodes_and_roto.txt")
82
82
  p = P.parse(f)
83
83
  # Should pass through the rotopaint node and get to the blur properly
84
84
  blur = le("Blur",
@@ -99,7 +99,7 @@ class TestParser < Test::Unit::TestCase
99
99
  end
100
100
 
101
101
  should 'parse a Nuke script with indentations' do
102
- f = File.open(File.dirname(__FILE__) + "/nuke_group.txt")
102
+ f = File.open(File.dirname(__FILE__) + "/test-data/nuke_group.txt")
103
103
  p = P.parse(f)
104
104
  grp = le(
105
105
  le("set", "cut_paste_input", se("stack", "0")),
@@ -124,10 +124,25 @@ class TestParser < Test::Unit::TestCase
124
124
  )
125
125
  ),
126
126
  le("Output",
127
- le("name", "Output1")
127
+ le(
128
+ le("name", "Output1")
129
+ )
128
130
  ),
129
131
  le("end_group")
130
132
  )
131
133
  assert_equal grp, p
132
134
  end
135
+
136
+ def test_one_node_parsing
137
+ f = File.open(File.dirname(__FILE__) + "/test-data/one_node_with_one_param.txt")
138
+ p = P.parse(f)
139
+ ref = le("SomeNode",
140
+ le(
141
+ le("foo", "bar")
142
+ )
143
+ )
144
+
145
+ assert_equal ref, p
146
+ end
147
+
133
148
  end
@@ -9,6 +9,10 @@ class TestSplitArray < Test::Unit::TestCase
9
9
  assert_equal [[1, 2], [3, 4]], Tickly.split_array([1, 2, nil, 3, 4])
10
10
  end
11
11
 
12
+ should "only generate sub-elements where they make sense" do
13
+ assert_equal [[1, 2]], Tickly.split_array([nil, 1, 2, nil])
14
+ end
15
+
12
16
  class Jock < Array; end
13
17
 
14
18
  should "properly use subclasses" do
@@ -17,4 +21,8 @@ class TestSplitArray < Test::Unit::TestCase
17
21
  assert_kind_of Jock, s[0]
18
22
  end
19
23
 
24
+ should 'squeeze nils out' do
25
+ s = Tickly.singularize_nils_in([nil, nil, 1,2,3,4, nil, nil, 456, nil, 9,nil,nil])
26
+ assert_equal [nil, 1,2,3,4, nil, 456, nil, 9, nil], s
27
+ end
20
28
  end
data/tickly.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "tickly"
8
- s.version = "0.0.2"
8
+ s.version = "0.0.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Julik Tarkhanov"]
12
- s.date = "2013-03-02"
12
+ s.date = "2013-03-11"
13
13
  s.description = "Parses the subset of the TCL grammar needed for Nuke scripts"
14
14
  s.email = "me@julik.nl"
15
15
  s.extra_rdoc_files = [
@@ -27,23 +27,24 @@ Gem::Specification.new do |s|
27
27
  "lib/tickly/evaluator.rb",
28
28
  "lib/tickly/parser.rb",
29
29
  "test/helper.rb",
30
- "test/nuke7_tracker_2tracks.nk",
31
- "test/nuke_group.txt",
32
- "test/nukenode.txt",
33
- "test/one_tracker_with_break.nk",
34
- "test/one_tracker_with_break_in_grp.nk",
30
+ "test/test-data/nuke7_tracker_2tracks.nk",
31
+ "test/test-data/nuke_group.txt",
32
+ "test/test-data/nukenode.txt",
33
+ "test/test-data/one_node_with_one_param.txt",
34
+ "test/test-data/one_tracker_with_break.nk",
35
+ "test/test-data/one_tracker_with_break_in_grp.nk",
36
+ "test/test-data/three_nodes_and_roto.txt",
37
+ "test/test-data/tracker_with_differing_gaps.nk",
38
+ "test/test-data/tracker_with_repeating_gaps.nk",
35
39
  "test/test_evaluator.rb",
36
40
  "test/test_parser.rb",
37
41
  "test/test_split_array.rb",
38
- "test/three_nodes_and_roto.txt",
39
- "test/tracker_with_differing_gaps.nk",
40
- "test/tracker_with_repeating_gaps.nk",
41
42
  "tickly.gemspec"
42
43
  ]
43
44
  s.homepage = "http://github.com/julik/tickly"
44
45
  s.licenses = ["MIT"]
45
46
  s.require_paths = ["lib"]
46
- s.rubygems_version = "1.8.25"
47
+ s.rubygems_version = "1.8.24"
47
48
  s.summary = "Assists in parsing Nuke scripts in TCL"
48
49
 
49
50
  if s.respond_to? :specification_version then
metadata CHANGED
@@ -1,91 +1,88 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: tickly
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 2
10
- version: 0.0.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Julik Tarkhanov
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-03-02 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-03-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: shoulda
22
- version_requirements: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
23
17
  none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
31
- prerelease: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
32
22
  type: :development
33
- requirement: *id001
34
- - !ruby/object:Gem::Dependency
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
35
31
  name: rdoc
36
- version_requirements: &id002 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
37
33
  none: false
38
- requirements:
34
+ requirements:
39
35
  - - ~>
40
- - !ruby/object:Gem::Version
41
- hash: 31
42
- segments:
43
- - 3
44
- - 12
45
- version: "3.12"
46
- prerelease: false
36
+ - !ruby/object:Gem::Version
37
+ version: '3.12'
47
38
  type: :development
48
- requirement: *id002
49
- - !ruby/object:Gem::Dependency
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.12'
46
+ - !ruby/object:Gem::Dependency
50
47
  name: bundler
51
- version_requirements: &id003 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
52
49
  none: false
53
- requirements:
54
- - - ">="
55
- - !ruby/object:Gem::Version
56
- hash: 3
57
- segments:
58
- - 0
59
- version: "0"
60
- prerelease: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
61
54
  type: :development
62
- requirement: *id003
63
- - !ruby/object:Gem::Dependency
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
64
63
  name: jeweler
65
- version_requirements: &id004 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
66
65
  none: false
67
- requirements:
66
+ requirements:
68
67
  - - ~>
69
- - !ruby/object:Gem::Version
70
- hash: 49
71
- segments:
72
- - 1
73
- - 8
74
- - 3
68
+ - !ruby/object:Gem::Version
75
69
  version: 1.8.3
76
- prerelease: false
77
70
  type: :development
78
- requirement: *id004
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 1.8.3
79
78
  description: Parses the subset of the TCL grammar needed for Nuke scripts
80
79
  email: me@julik.nl
81
80
  executables: []
82
-
83
81
  extensions: []
84
-
85
- extra_rdoc_files:
82
+ extra_rdoc_files:
86
83
  - LICENSE.txt
87
84
  - README.rdoc
88
- files:
85
+ files:
89
86
  - .document
90
87
  - .travis.yml
91
88
  - Gemfile
@@ -96,50 +93,45 @@ files:
96
93
  - lib/tickly/evaluator.rb
97
94
  - lib/tickly/parser.rb
98
95
  - test/helper.rb
99
- - test/nuke7_tracker_2tracks.nk
100
- - test/nuke_group.txt
101
- - test/nukenode.txt
102
- - test/one_tracker_with_break.nk
103
- - test/one_tracker_with_break_in_grp.nk
96
+ - test/test-data/nuke7_tracker_2tracks.nk
97
+ - test/test-data/nuke_group.txt
98
+ - test/test-data/nukenode.txt
99
+ - test/test-data/one_node_with_one_param.txt
100
+ - test/test-data/one_tracker_with_break.nk
101
+ - test/test-data/one_tracker_with_break_in_grp.nk
102
+ - test/test-data/three_nodes_and_roto.txt
103
+ - test/test-data/tracker_with_differing_gaps.nk
104
+ - test/test-data/tracker_with_repeating_gaps.nk
104
105
  - test/test_evaluator.rb
105
106
  - test/test_parser.rb
106
107
  - test/test_split_array.rb
107
- - test/three_nodes_and_roto.txt
108
- - test/tracker_with_differing_gaps.nk
109
- - test/tracker_with_repeating_gaps.nk
110
108
  - tickly.gemspec
111
109
  homepage: http://github.com/julik/tickly
112
- licenses:
110
+ licenses:
113
111
  - MIT
114
112
  post_install_message:
115
113
  rdoc_options: []
116
-
117
- require_paths:
114
+ require_paths:
118
115
  - lib
119
- required_ruby_version: !ruby/object:Gem::Requirement
116
+ required_ruby_version: !ruby/object:Gem::Requirement
120
117
  none: false
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- hash: 3
125
- segments:
118
+ requirements:
119
+ - - ! '>='
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ segments:
126
123
  - 0
127
- version: "0"
128
- required_rubygems_version: !ruby/object:Gem::Requirement
124
+ hash: 592217362083330592
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
126
  none: false
130
- requirements:
131
- - - ">="
132
- - !ruby/object:Gem::Version
133
- hash: 3
134
- segments:
135
- - 0
136
- version: "0"
127
+ requirements:
128
+ - - ! '>='
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
137
131
  requirements: []
138
-
139
132
  rubyforge_project:
140
- rubygems_version: 1.8.25
133
+ rubygems_version: 1.8.24
141
134
  signing_key:
142
135
  specification_version: 3
143
136
  summary: Assists in parsing Nuke scripts in TCL
144
137
  test_files: []
145
-