chirp 0.2.0 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. data/History.txt +0 -0
  2. data/Manifest.txt +44 -2
  3. data/README.txt +10 -2
  4. data/Rakefile +1 -1
  5. data/bin/chirp +6 -4
  6. data/lib/chirp.rb +7 -3
  7. data/lib/chirp/application.rb +248 -159
  8. data/lib/chirp/context.rb +101 -0
  9. data/lib/chirp/fs_expression.rb +180 -0
  10. data/lib/chirp/path_filter.rb +58 -0
  11. data/lib/chirp/pathmap.rb +200 -0
  12. data/lib/chirp/span.rb +38 -0
  13. data/test/account.dir/input +0 -0
  14. data/test/account.dir/output +0 -0
  15. data/test/account.dir/program.chirp +7 -4
  16. data/test/action.dir/input +0 -0
  17. data/test/action.dir/output +0 -0
  18. data/test/action.dir/program.chirp +2 -2
  19. data/test/beforeafter.dir/input +0 -0
  20. data/test/beforeafter.dir/output +0 -0
  21. data/test/beforeafter.dir/program.chirp +3 -3
  22. data/test/copy1.dir/input +0 -0
  23. data/test/copy1.dir/output +5 -0
  24. data/test/copy1.dir/program.chirp +9 -0
  25. data/test/copy1.dir/source +2 -0
  26. data/test/copy2.dir/input +0 -0
  27. data/test/copy2.dir/output +5 -0
  28. data/test/copy2.dir/program.chirp +9 -0
  29. data/test/copy2.dir/source +2 -0
  30. data/test/copy3.dir/input +0 -0
  31. data/test/copy3.dir/output +5 -0
  32. data/test/copy3.dir/program.chirp +7 -0
  33. data/test/copy3.dir/source +2 -0
  34. data/test/copy_file.dir/a.txt +1 -0
  35. data/test/copy_file.dir/b.txt +1 -0
  36. data/test/copy_file.dir/c.txt +1 -0
  37. data/test/copy_file.dir/input +0 -0
  38. data/test/copy_file.dir/output +2 -0
  39. data/test/copy_file.dir/program.chirp +5 -0
  40. data/test/fields.dir/input +0 -0
  41. data/test/fields.dir/output +0 -0
  42. data/test/fields.dir/program.chirp +2 -2
  43. data/test/fields_sep.dir/input +0 -0
  44. data/test/fields_sep.dir/output +0 -0
  45. data/test/fields_sep.dir/program.chirp +1 -2
  46. data/test/files.dir/a.ignore +0 -0
  47. data/test/files.dir/a.txt +0 -0
  48. data/test/files.dir/b.txt +0 -0
  49. data/test/files.dir/c.stuff +0 -0
  50. data/test/files.dir/input +0 -0
  51. data/test/files.dir/output +3 -0
  52. data/test/files.dir/program.chirp +7 -3
  53. data/test/fs_expr.dir/aa.txt +1 -0
  54. data/test/fs_expr.dir/bb.txt +9 -0
  55. data/test/fs_expr.dir/cc.txt +0 -0
  56. data/test/fs_expr.dir/dir1/dir2/dir3/a.txt +1 -0
  57. data/test/fs_expr.dir/input +0 -0
  58. data/test/fs_expr.dir/output +7 -0
  59. data/test/fs_expr.dir/program.chirp +17 -0
  60. data/test/inplace.dir/a.txt +0 -0
  61. data/test/inplace.dir/b.txt +0 -0
  62. data/test/inplace.dir/input +0 -0
  63. data/test/inplace.dir/output +0 -0
  64. data/test/inplace.dir/program.chirp +4 -6
  65. data/test/line_no.dir/input +0 -0
  66. data/test/line_no.dir/output +1 -0
  67. data/test/line_no.dir/program.chirp +5 -1
  68. data/test/match.dir/input +0 -0
  69. data/test/match.dir/output +0 -0
  70. data/test/match.dir/program.chirp +1 -1
  71. data/test/path.dir/dir1/dir2/dir3/a.txt +1 -0
  72. data/test/path.dir/input +0 -0
  73. data/test/path.dir/new +5 -0
  74. data/test/path.dir/output +20 -0
  75. data/test/path.dir/program.chirp +44 -0
  76. data/test/proc.dir/input +0 -0
  77. data/test/proc.dir/output +0 -0
  78. data/test/proc.dir/program.chirp +2 -2
  79. data/test/rename_file.dir/a.txt +4 -0
  80. data/test/rename_file.dir/b.txt +4 -0
  81. data/test/rename_file.dir/c.txt +4 -0
  82. data/test/rename_file.dir/input +0 -0
  83. data/test/rename_file.dir/output +2 -0
  84. data/test/rename_file.dir/program.chirp +7 -0
  85. data/test/requires.rb +6 -0
  86. data/test/span.dir/input +0 -0
  87. data/test/span.dir/output +0 -0
  88. data/test/span.dir/program.chirp +1 -1
  89. data/test/span2.dir/input +0 -0
  90. data/test/span2.dir/output +0 -0
  91. data/test/span2.dir/program.chirp +3 -1
  92. data/test/string.dir/input +0 -0
  93. data/test/string.dir/output +0 -0
  94. data/test/string.dir/program.chirp +1 -1
  95. data/test/test_application.rb +14 -9
  96. data/test/test_fs_expression.rb +99 -0
  97. data/test/test_span.rb +36 -0
  98. metadata +64 -7
  99. data/lib/chirp/statement.rb +0 -91
  100. data/test/test_statement.rb +0 -118
@@ -0,0 +1,38 @@
1
+ module Chirp
2
+ class Span
3
+ BEFORE_SPAN = 0
4
+ IN_SPAN = 1
5
+ AFTER_SPAN = 2
6
+
7
+ def initialize(v1, v2)
8
+ v2 = 999999999999 unless v2
9
+ @p1 = predicate(v1)
10
+ @p2 = predicate(v2)
11
+ reset
12
+ end
13
+
14
+ def reset
15
+ @state = BEFORE_SPAN
16
+ end
17
+
18
+ def evaluate(context)
19
+ if @state == BEFORE_SPAN
20
+ @state = IN_SPAN if @p1.call(context)
21
+ end
22
+ ret = @state == IN_SPAN
23
+ if @state == IN_SPAN
24
+ @state = AFTER_SPAN if @p2.call(context)
25
+ end
26
+ ret
27
+ end
28
+
29
+ def predicate(value)
30
+ if value.kind_of?(Regexp)
31
+ return lambda {|context| value =~ context.line}
32
+ else
33
+ return lambda {|context| value == context.line_no}
34
+ end
35
+ end
36
+
37
+ end
38
+ end
File without changes
File without changes
@@ -1,16 +1,19 @@
1
1
  #!/usr/bin/env chirp
2
+ require 'pp'
2
3
 
3
4
  #
4
5
  # Simple bank acccount program, shows the use of fields
5
6
  #
6
- file do
7
- before {@sum=0}
7
+ each :path=>'input' do
8
+ before do
9
+ @sum=0
10
+ end
8
11
 
9
- line(lambda{fields[0] =~ /credit/}) do
12
+ line :expr=>lambda{fields[0] =~ /credit/} do
10
13
  @sum += fields[1].to_i
11
14
  end
12
15
 
13
- line(lambda{fields[0] =~ /debit/}) do
16
+ line :expr=>lambda{fields[0] =~ /debit/} do
14
17
  @sum -= fields[1].to_i
15
18
  end
16
19
 
File without changes
File without changes
@@ -1,3 +1,3 @@
1
- file do
2
- line(3) { puts "matched line #{line_no} text is #{line}" }
1
+ each :path=>'input' do
2
+ line(:number=>3) { puts "matched line #{line_no} text is #{line}" }
3
3
  end
File without changes
File without changes
@@ -1,7 +1,7 @@
1
- run { puts "before any processing" }
2
- file do
1
+ now { puts "before any processing" }
2
+ each :path=>'input' do
3
3
  before { puts "before file" }
4
4
  line
5
5
  after { puts "after file" }
6
6
  end
7
- run { puts "after any processing" }
7
+ now { puts "after any processing" }
File without changes
@@ -0,0 +1,5 @@
1
+ ["source"]
2
+ ["source", "target"]
3
+ ==============
4
+ These are the contents of infile
5
+ These are the contents of infile
@@ -0,0 +1,9 @@
1
+ now { pp Dir['source', 'target'].sort }
2
+
3
+ each :path=>'source', :output=>"target" do
4
+ line {puts line}
5
+ end
6
+
7
+ now { pp Dir['source', 'target'].sort }
8
+ now { puts "==============" }
9
+ now { puts File.read('target') }
@@ -0,0 +1,2 @@
1
+ These are the contents of infile
2
+ These are the contents of infile
File without changes
@@ -0,0 +1,5 @@
1
+ ["source"]
2
+ ["source", "target"]
3
+ ==============
4
+ These are the contents of infile
5
+ These are the contents of infile
@@ -0,0 +1,9 @@
1
+ now { pp Dir['source', 'target'].sort }
2
+
3
+ each_line :path=>"source", :output=>"target" do
4
+ puts line
5
+ end
6
+
7
+ now { pp Dir['source', 'target'].sort }
8
+ now { puts "==============" }
9
+ now { puts File.read('target') }
@@ -0,0 +1,2 @@
1
+ These are the contents of infile
2
+ These are the contents of infile
File without changes
@@ -0,0 +1,5 @@
1
+ ["source"]
2
+ ["source", "target"]
3
+ ==============
4
+ These are the contents of infile
5
+ These are the contents of infile
@@ -0,0 +1,7 @@
1
+ now { pp Dir['source', 'target'].sort }
2
+
3
+ copy :path=>"source", :output=>"target"
4
+
5
+ now { pp Dir['source', 'target'].sort }
6
+ now { puts "==============" }
7
+ now { puts File.read('target') }
@@ -0,0 +1,2 @@
1
+ These are the contents of infile
2
+ These are the contents of infile
@@ -0,0 +1 @@
1
+ Each path: a.txt output path: a.txt.new
@@ -0,0 +1 @@
1
+ Each path: b.txt output path: b.txt.new
@@ -0,0 +1 @@
1
+ Each path: c.txt output path: c.txt.new
File without changes
@@ -0,0 +1,2 @@
1
+ ["a.txt", "b.txt", "c.txt"]
2
+ ["a.txt", "a.txt.new", "b.txt", "b.txt.new", "c.txt", "c.txt.new"]
@@ -0,0 +1,5 @@
1
+ now { pp Dir['*.txt*'].sort }
2
+
3
+ copy :name=>'*.txt', :type=>:file, :output=>'%p.new'
4
+
5
+ now { pp Dir['*.txt*'].sort }
File without changes
File without changes
@@ -1,5 +1,5 @@
1
1
  require 'pp'
2
2
 
3
- file do
4
- line { pp fields }
3
+ each_line :path=>'input' do
4
+ pp fields
5
5
  end
File without changes
File without changes
@@ -1,6 +1,5 @@
1
1
  require 'pp'
2
2
 
3
- file do
4
- field_separator ':'
3
+ each :path=>'input', :field_separator=>':' do
5
4
  line { pp fields }
6
5
  end
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,2 +1,5 @@
1
1
  paths: a.txtb.txt
2
2
  paths: a.txtb.txt
3
+ ===================
4
+ path: a.txt
5
+ path: b.txt
@@ -1,6 +1,10 @@
1
1
 
2
- files "*.txt"
2
+ each_line :path=>'*.txt' do
3
+ puts "paths: #{paths}"
4
+ end
5
+
6
+ now {puts "==================="}
3
7
 
4
- file do
5
- line {puts "paths: #{paths}"}
8
+ each_file :path=>'*.txt' do
9
+ puts "path: #{path}"
6
10
  end
@@ -0,0 +1 @@
1
+ 123456789
@@ -0,0 +1,9 @@
1
+ total 24
2
+ -rw-r--r-- 1 rolsen rolsen 10 2007-12-13 14:35 aa.txt
3
+ -rw-r--r-- 1 rolsen rolsen 0 2007-12-13 14:54 bb.txt
4
+ drwxr-xr-x 3 rolsen rolsen 4096 2007-12-13 14:33 dir1
5
+ -rw-r--r-- 1 rolsen rolsen 0 2007-12-13 14:33 input
6
+ -rw-r--r-- 1 rolsen rolsen 183 2007-12-13 14:33 output
7
+ -rw-r--r-- 1 rolsen rolsen 69 2007-12-13 14:53 program.chirp
8
+ -rw-r--r-- 1 rolsen rolsen 183 2007-12-13 14:33 qq
9
+ -rw-r--r-- 1 rolsen rolsen 389 2007-12-13 14:33 zzz
File without changes
@@ -0,0 +1 @@
1
+ example file
File without changes
@@ -0,0 +1,7 @@
1
+ aa.txt
2
+ =========
3
+ aa.txt
4
+ bb.txt
5
+ =========
6
+ dir1
7
+ =========
@@ -0,0 +1,17 @@
1
+
2
+ each_path :path=>"*.txt", :fsexp=>length(10) do
3
+ puts path
4
+ end
5
+
6
+ now {puts "========="}
7
+
8
+ each_path :path=>"*.txt", :fsexp=>bigger(1) do
9
+ puts path
10
+ end
11
+
12
+ now {puts "========="}
13
+ each_path :path=>"dir*", :fsexp=>dir? do
14
+ puts path
15
+ end
16
+
17
+ now {puts "========="}
File without changes
File without changes
File without changes
File without changes
@@ -1,9 +1,7 @@
1
- files "*.txt"
1
+ now { puts "before any processing" }
2
2
 
3
- run { puts "before any processing" }
4
- file do
5
- edit_in_place
3
+ each :path=>'*.txt', :output=>'%p' do
6
4
  line { puts line.upcase }
7
5
  end
8
- run { puts File.read('a.txt') }
9
- run { puts File.read('b.txt') }
6
+ now { puts File.read('a.txt') }
7
+ now { puts File.read('b.txt') }
File without changes
@@ -1 +1,2 @@
1
1
  33
2
+ 11
@@ -1 +1,5 @@
1
- file {line(3)}
1
+ each_line :path=>'input', :number=>3
2
+
3
+ each :path=>'in*' do
4
+ line :number=>1
5
+ end
File without changes
File without changes
@@ -1 +1 @@
1
- file { line(/abc/) }
1
+ each_line :path=>'input', :pattern=>/abc/
@@ -0,0 +1 @@
1
+ example file
File without changes
@@ -0,0 +1,5 @@
1
+ starting_with 'dir1'
2
+
3
+ each :path=>'dir1/**/*.txt' do
4
+ before { puts "path: #{path}" }
5
+ end
@@ -0,0 +1,20 @@
1
+ path: dir1/dir2/dir3/a.txt
2
+ dirname: dir1/dir2/dir3
3
+ basename: a.txt
4
+ extname: .txt
5
+ name: a
6
+ full_path: ./dir1/dir2/dir3/a.txt
7
+ path_name: dir1/dir2/dir3/a.txt
8
+ path_name.class: Pathname
9
+ full_path_name: ./dir1/dir2/dir3/a.txt
10
+ full_path_name.class: Pathname
11
+ path: dir1/dir2/dir3/a.txt
12
+ ====================
13
+ dir1/dir2/dir3/a.txt
14
+ ====================
15
+ dir2/dir3
16
+ ====================
17
+ dir1/dir2/dir3/a.txt
18
+ ====================
19
+ foo.txt
20
+ this is the foo file
@@ -0,0 +1,44 @@
1
+ each :path=>'dir1/**/*.txt' do
2
+ before { puts "path: #{path}" }
3
+ before { puts "dirname: #{dirname}" }
4
+ before { puts "basename: #{basename}" }
5
+ before { puts "extname: #{extname}" }
6
+ before { puts "name: #{name}" }
7
+ before { puts "full_path: #{full_path}" }
8
+ before { puts "path_name: #{path_name}" }
9
+ before { puts "path_name.class: #{path_name.class}" }
10
+ before { puts "full_path_name: #{full_path_name}" }
11
+ before { puts "full_path_name.class: #{full_path_name.class}" }
12
+ path { puts "path: #{path}" }
13
+ end
14
+
15
+ now {puts "===================="}
16
+
17
+ each :path=>/dir1.*txt$/ do
18
+ path {puts path}
19
+ end
20
+
21
+ now {puts "===================="}
22
+
23
+ now do
24
+ rm_rf 'dir2'
25
+ mkdir_p 'dir2/dir3/dir4'
26
+ end
27
+
28
+ each :dir=>'dir2' do
29
+ path {puts path}
30
+ end
31
+
32
+ now {puts "===================="}
33
+
34
+ each :path=>/dir1.*txt$/ do
35
+ file {puts path}
36
+ end
37
+
38
+ now {puts "===================="}
39
+
40
+ each :path=>'*.txt', :contains=>/foo/ do
41
+ path {puts path}
42
+ path {puts contents}
43
+ end
44
+
File without changes
File without changes
@@ -1,3 +1,3 @@
1
- file do
2
- line(lambda{/russ/=~fields[0]})
1
+ each :path=>'input' do
2
+ line(:expr=>lambda{/russ/=~fields[0]})
3
3
  end
@@ -0,0 +1,4 @@
1
+ a.txt
2
+ input
3
+ output
4
+ program.chirp
@@ -0,0 +1,4 @@
1
+ a.txt
2
+ input
3
+ output
4
+ program.chirp
@@ -0,0 +1,4 @@
1
+ a.txt
2
+ input
3
+ output
4
+ program.chirp