linkparser 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/rake/rdoc.rb CHANGED
@@ -1,22 +1,15 @@
1
1
  #
2
- # RDoc Rake tasks for ThingFish
3
- # $Id: rdoc.rb 78 2008-12-18 22:04:10Z deveiant $
2
+ # RDoc Rake tasks
3
+ # $Id: rdoc.rb 93 2009-03-20 13:02:30Z deveiant $
4
4
  #
5
5
 
6
- gem 'rdoc'
6
+ gem 'rdoc', '>= 2.4.1'
7
7
 
8
+ require 'rubygems'
8
9
  require 'rdoc/rdoc'
9
10
  require 'rake/clean'
10
11
 
11
12
 
12
- if RDoc::RDoc::GENERATORS.key?( 'darkfish' )
13
- $have_darkfish = true
14
- else
15
- trace "No darkfish generator."
16
- $have_darkfish = false
17
- end
18
-
19
-
20
13
  # Append docs/lib to the load path if it exists for a locally-installed Darkfish
21
14
  DOCSLIB = DOCSDIR + 'lib'
22
15
  $LOAD_PATH.unshift( DOCSLIB.to_s ) if DOCSLIB.exist?
@@ -32,7 +25,7 @@ desc "Build API documentation in #{RDOCDIR}"
32
25
  task :rdoc => [ Rake.application.rakefile, *DOCFILES ] do
33
26
  args = RDOC_OPTIONS
34
27
  args += [ '-o', RDOCDIR.to_s ]
35
- args += [ '-f', 'darkfish' ] if $have_darkfish
28
+ args += [ '-f', 'darkfish' ]
36
29
  args += DOCFILES.collect {|pn| pn.to_s }
37
30
 
38
31
  trace "Building docs with arguments: %s" % [ args.join(' ') ]
data/rake/svn.rb CHANGED
@@ -1,18 +1,16 @@
1
1
  #
2
2
  # Subversion Rake Tasks
3
- # $Id: svn.rb 77 2008-12-18 16:35:24Z deveiant $
3
+ # $Id: svn.rb 105 2009-06-01 19:20:12Z deveiant $
4
4
  #
5
5
  # Authors:
6
6
  # * Michael Granger <ged@FaerieMUD.org>
7
7
  #
8
8
 
9
- require 'rubygems'
10
- gem 'rake', '>= 0.8.3'
11
-
12
9
  require 'pp'
13
10
  require 'yaml'
14
11
  require 'date'
15
12
  require 'time'
13
+ require 'abbrev'
16
14
 
17
15
  # Strftime format for tags/releases
18
16
  TAG_TIMESTAMP_FORMAT = '%Y%m%d-%H%M%S'
@@ -25,9 +23,9 @@ DEFAULT_KEYWORDS = %w[Date Rev Author URL Id]
25
23
  KEYWORDED_FILEDIRS = %w[applets spec bin etc ext experiments examples lib misc docs]
26
24
  KEYWORDED_FILEPATTERN = /
27
25
  ^(?:
28
- (?:meta)?rakefile.* # Rakefiles
26
+ (?:meta)?rakefile.* # Rakefiles
29
27
  |
30
- .*\.(?:rb|c|h|js|html|css|template|erb) # Source file extensions
28
+ .*\.(?:rb|c|h|js|html|css|template|erb|page) # Source file extensions
31
29
  |
32
30
  readme|install|todo
33
31
  )$/ix
@@ -58,8 +56,11 @@ end
58
56
  ### a hash.
59
57
  def get_svn_info( dir='.' )
60
58
  return {} unless File.directory?( File.join(dir, '.svn') )
61
- info = IO.read( '|-' ) or exec 'svn', 'info', dir
59
+ info = IO.read( '|-' ) or exec 'svn', 'info', dir.to_s
62
60
  return YAML.load( info ) # 'svn info' outputs valid YAML! Yay!
61
+ rescue NotImplementedError
62
+ trace "No fork(), proceeding without svn info..."
63
+ return {}
63
64
  end
64
65
 
65
66
 
@@ -204,6 +205,15 @@ def get_latest_release_tag
204
205
  end
205
206
 
206
207
 
208
+ ### Return the names of all existing branches.
209
+ def get_branch_names
210
+ rooturl = get_svn_repo_root()
211
+ branchesurl = rooturl + "/#{SVN_BRANCHES_DIR}"
212
+
213
+ return svn_ls( branchesurl )
214
+ end
215
+
216
+
207
217
  ### Extract a diff from the specified subversion working +dir+ and return it.
208
218
  def make_svn_commit_log( dir='.' )
209
219
  diff = IO.read( '|-' ) or exec 'svn', 'diff'
@@ -382,14 +392,15 @@ namespace :svn do
382
392
  desc "Copy the HEAD revision of the current #{SVN_TRUNK_DIR}/ to #{SVN_BRANCHES_DIR} with a " +
383
393
  "user-specified name."
384
394
  task :branch, [:name] do |task, args|
385
- unless args.name
386
- args.name = prompt( "Branch name" ) or abort
395
+ branchname = args.name
396
+ unless branchname
397
+ branchname = prompt( "Branch name" ) or abort
387
398
  end
388
399
 
389
400
  svninfo = get_svn_info()
390
401
  svntrunk = Pathname.new( svninfo['Repository Root'] ) + SVN_TRUNK_DIR
391
402
  svnbranchdir = Pathname.new( svninfo['Repository Root'] ) + SVN_BRANCHES_DIR
392
- svnbranch = svnbranchdir + args.name
403
+ svnbranch = svnbranchdir + branchname
393
404
 
394
405
  desc = "Making a new branch: #{svnbranch}"
395
406
  ask_for_confirmation( desc ) do
@@ -401,6 +412,33 @@ namespace :svn do
401
412
  end
402
413
  end
403
414
 
415
+
416
+ desc "Switch the working copy to the named branch"
417
+ task :switch, [:name] do |task, args|
418
+ branches = get_branch_names().collect {|name| name.chomp('/') }
419
+
420
+ unless args.name
421
+ log "Branches are:\n" + branches.collect {|br| " #{br}" }.join( "\n" )
422
+
423
+ begin
424
+ oldproc = Readline.completion_proc
425
+ abbrev = branches.abbrev
426
+ Readline.completion_proc = lambda{|string| abbrev[string] }
427
+
428
+ name = prompt( "Branch to switch to" ) or abort
429
+ args.with_defaults( :name => name )
430
+ ensure
431
+ Readline.completion_proc = oldproc unless oldproc.nil?
432
+ end
433
+ end
434
+
435
+ svninfo = get_svn_info()
436
+ abort "Branch '#{args.name}' does not exist" unless branches.include?( args.name )
437
+ branchuri = Pathname.new( svninfo['Repository Root'] ) + SVN_BRANCHES_DIR + args.name
438
+ run 'svn', 'sw', branchuri
439
+ end
440
+ task :sw => :switch
441
+
404
442
 
405
443
  desc "Switch to the trunk if the working copy isn't there already."
406
444
  task :trunk do
@@ -529,7 +567,7 @@ namespace :svn do
529
567
  desc "Check in all the changes in your current working copy"
530
568
  task :checkin => ['svn:update', 'svn:newfiles', 'test', 'svn:fix_keywords', COMMIT_MSG_FILE] do
531
569
  targets = get_target_args()
532
- $deferr.puts '---', File.read( COMMIT_MSG_FILE ), '---'
570
+ $stderr.puts '---', File.read( COMMIT_MSG_FILE ), '---'
533
571
  ask_for_confirmation( "Continue with checkin?" ) do
534
572
  run 'svn', 'ci', '-F', COMMIT_MSG_FILE, targets
535
573
  rm_f COMMIT_MSG_FILE
@@ -562,7 +600,7 @@ namespace :svn do
562
600
  end
563
601
 
564
602
  unless files_needing_fixups.empty?
565
- $deferr.puts "Files needing keyword fixes: ",
603
+ $stderr.puts "Files needing keyword fixes: ",
566
604
  files_needing_fixups.collect {|f|
567
605
  " %s: %s" % [f, kwmap[f] ? kwmap[f].join(' ') : "(no keywords)"]
568
606
  }
data/rake/testing.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Rake tasklib for testing tasks
3
- # $Id: testing.rb 80 2008-12-20 19:50:19Z deveiant $
3
+ # $Id: testing.rb 99 2009-04-14 13:03:03Z deveiant $
4
4
  #
5
5
  # Authors:
6
6
  # * Michael Granger <ged@FaerieMUD.org>
@@ -45,6 +45,7 @@ begin
45
45
  require 'spec/rake/spectask'
46
46
 
47
47
  ### Task: spec
48
+ desc "Run specs"
48
49
  task :spec => 'spec:doc'
49
50
 
50
51
  namespace :spec do
data/rake/win32.rb ADDED
@@ -0,0 +1,186 @@
1
+ #
2
+ # Win32-specific tasks (cross-compiling, etc.)
3
+ #
4
+ # Thanks to some people that understand this stuff better than me for
5
+ # posting helpful blog posts. This stuff is an amalgam of stuff they did:
6
+ #
7
+ # * Mauricio Fernandez
8
+ # http://eigenclass.org/hiki/cross+compiling+rcovrt
9
+ #
10
+ # * Jeremy Hinegardner
11
+ # http://www.copiousfreetime.org/articles/2008/10/12/building-gems-for-windows.html
12
+ #
13
+ # * Aaron Patterson
14
+ # http://tenderlovemaking.com/2008/11/21/cross-compiling-ruby-gems-for-win32/
15
+
16
+ require 'rake'
17
+ require 'pathname'
18
+ require 'rubygems/platform'
19
+ require 'rbconfig'
20
+ require 'uri'
21
+ require 'net/ftp'
22
+
23
+ HOMEDIR = Pathname( '~' ).expand_path
24
+ RUBYVERSION = '1.8.6-p287'
25
+ RUBYVERSION_MAJORMINOR = RUBYVERSION[/^\d+\.\d+/]
26
+
27
+ RUBY_DL_BASE = "ftp://ftp.ruby-lang.org/pub/ruby/#{RUBYVERSION_MAJORMINOR}/"
28
+ RUBY_DL_URI = URI( RUBY_DL_BASE + "ruby-#{RUBYVERSION}.tar.gz" )
29
+
30
+ XCOMPILER_DIR = HOMEDIR + '.ruby_mingw32'
31
+
32
+ XCOMPILER_DL = XCOMPILER_DIR + "ruby-#{RUBYVERSION}.tar.gz"
33
+ XCOMPILER_SRC = XCOMPILER_DIR + "ruby-#{RUBYVERSION}"
34
+
35
+ XCOMPILER_BIN = XCOMPILER_DIR + 'bin'
36
+ XCOMPILER_LIB = XCOMPILER_DIR + 'lib'
37
+ XCOMPILER_RUBY = XCOMPILER_BIN + 'ruby.exe'
38
+
39
+ XCOMPILER_LOAD_PATH = XCOMPILER_LIB + "ruby/#{RUBYVERSION_MAJORMINOR}/i386-mingw32"
40
+
41
+ TAR_OPTS = { :compression => :gzip }
42
+
43
+ WIN32_GEMSPEC = GEMSPEC.dup
44
+ WIN32_GEMSPEC.files += FileList[ EXTDIR + '**.{dll,so}' ]
45
+ WIN32_GEMSPEC.platform = Gem::Platform.new( 'i386-mingw32' )
46
+ WIN32_GEMSPEC.extensions = []
47
+
48
+
49
+ CONFIGURE_CMD = %W[
50
+ env
51
+ ac_cv_func_getpgrp_void=no
52
+ ac_cv_func_setpgrp_void=yes
53
+ rb_cv_negative_time_t=no
54
+ ac_cv_func_memcmp_working=yes
55
+ rb_cv_binary_elf=no
56
+ ./configure
57
+ --host=i386-mingw32
58
+ --target=i386-mingw32
59
+ --build=#{Config::CONFIG['build']}
60
+ --prefix=#{XCOMPILER_DIR}
61
+ ]
62
+
63
+ ### Archive::Tar::Reader#extract (as of 0.9.0) is broken w.r.t.
64
+ ### permissions, so we have to do this ourselves.
65
+ def untar( tarfile, targetdir )
66
+ targetdir = Pathname( targetdir )
67
+ raise "No such directory: #{targetdir}" unless targetdir.directory?
68
+
69
+ reader = Archive::Tar::Reader.new( tarfile.to_s, TAR_OPTS )
70
+
71
+ mkdir_p( targetdir )
72
+ reader.each( true ) do |header, body|
73
+ path = targetdir + header[:path]
74
+ # trace "Header is: %p" % [ header ]
75
+
76
+ case header[:type]
77
+ when :file
78
+ trace " #{path}"
79
+ path.open( File::WRONLY|File::EXCL|File::CREAT|File::TRUNC, header[:mode] ) do |fio|
80
+ bytesize = header[:size]
81
+ fio.write( body[0,bytesize] )
82
+ end
83
+
84
+ when :directory
85
+ trace " #{path}"
86
+ path.mkpath
87
+
88
+ when :link
89
+ linktarget = targetdir + header[:dest]
90
+ trace " #{path} => #{linktarget}"
91
+ path.make_link( linktarget.to_s )
92
+
93
+ when :symlink
94
+ linktarget = targetdir + header[:dest]
95
+ trace " #{path} -> #{linktarget}"
96
+ path.make_symlink( linktarget )
97
+ end
98
+ end
99
+
100
+ end
101
+
102
+
103
+ begin
104
+ require 'archive/tar'
105
+
106
+ namespace :win32 do
107
+ directory XCOMPILER_DIR.to_s
108
+
109
+ file XCOMPILER_DL => XCOMPILER_DIR do
110
+ # openuri can't handle this -- passive ftp required?
111
+ # run 'wget', '-O', XCOMPILER_DL, RUBY_DL_URI
112
+ log "Downloading ruby distro from %s" % [ RUBY_DL_URI ]
113
+ ftp = Net::FTP.new( RUBY_DL_URI.host )
114
+ ftp.login
115
+ ftp.getbinaryfile( RUBY_DL_URI.path, XCOMPILER_DL, 4096 )
116
+ ftp.close
117
+ end
118
+
119
+ directory XCOMPILER_SRC.to_s
120
+ task XCOMPILER_SRC => [ XCOMPILER_DIR, XCOMPILER_DL ] do
121
+ if XCOMPILER_SRC.exist?
122
+ trace "Rake fails. #{XCOMPILER_SRC} already exists."
123
+ else
124
+ untar( XCOMPILER_DL, XCOMPILER_DIR )
125
+ end
126
+ end
127
+
128
+ file XCOMPILER_RUBY => XCOMPILER_SRC do
129
+ Dir.chdir( XCOMPILER_SRC ) do
130
+ unless File.exist?( 'Makefile.in.orig' )
131
+ File.open( 'Makefile.in.new', IO::CREAT|IO::WRONLY|IO::EXCL ) do |ofh|
132
+ IO.readlines( 'Makefile.in' ).each do |line|
133
+ next if line.include?( 0.chr )
134
+ trace " copying line: %p" % [ line ]
135
+ line.sub!( /ALT_SEPARATOR = ".*?"/, "ALT_SEPARATOR = 92.chr" )
136
+ ofh.write( line )
137
+ end
138
+ end
139
+
140
+ mv 'Makefile.in', 'Makefile.in.orig'
141
+ mv 'Makefile.in.new', 'Makefile.in'
142
+ end
143
+
144
+ run *CONFIGURE_CMD
145
+ run 'make', 'ruby'
146
+ run 'make', 'rubyw.exe'
147
+ run 'make', 'install'
148
+ end
149
+ end
150
+
151
+ file XCOMPILER_LOAD_PATH => XCOMPILER_RUBY
152
+
153
+ desc "Cross-compile the library for Win32 systems, installing a cross-" +
154
+ "compiled Ruby if necessary"
155
+ task :build => [ EXTDIR, XCOMPILER_LOAD_PATH.to_s ] do
156
+ in_subdirectory( EXTDIR ) do
157
+ ruby "-I#{XCOMPILER_LOAD_PATH}", 'extconf.rb'
158
+ sh 'make'
159
+ end
160
+ end
161
+
162
+ desc "Build a binary gem for win32 systems"
163
+ task :gem => ['win32:build', PKGDIR.to_s] + WIN32_GEMSPEC.files do
164
+ when_writing( "Creating win32 GEM" ) do
165
+ pkgname = WIN32_GEMSPEC.file_name
166
+ builder = Gem::Builder.new( WIN32_GEMSPEC )
167
+ builder.build
168
+ mv pkgname, PKGDIR + pkgname, :verbose => $trace
169
+ end
170
+ end
171
+ end
172
+
173
+ rescue LoadError => err
174
+ task :no_win32_build do
175
+ abort "No win32 build: %s: %s" % [ err.class.name, err.message ]
176
+ end
177
+
178
+ namespace :win32 do
179
+ desc "Build a binary Gem for Win32 systems, installing a cross " +
180
+ "compiled Ruby if necessary"
181
+ task :build => :no_win32_build
182
+ end
183
+
184
+ end
185
+
186
+
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/ruby -w
2
2
  #
3
3
  # Specification for the LinkParser::ParseOptions class
4
- # $Id: parseoptions_spec.rb 48 2008-12-19 18:30:33Z deveiant $
4
+ # $Id: parseoptions_spec.rb 53 2009-06-03 12:52:13Z deveiant $
5
5
  #
6
6
  # See the LICENSE file in the distribution for information about copyright and licensing.
7
7
  #
@@ -73,6 +73,20 @@ describe LinkParser::ParseOptions do
73
73
  @opts.reset_resources
74
74
  }.should_not raise_error()
75
75
  end
76
+
77
+
78
+ describe "in versions of link-grammar >= 4.5.0" do
79
+
80
+ before( :each ) do
81
+ version_vec = LinkParser.link_grammar_version[/(\d+\.\d+\.\d+)/, 1].
82
+ split('.').collect {|v| v.to_i }.pack('n*')
83
+ pending "the underlying library is %s" unless version_vec >= [4,5,0].pack('n*')
84
+ end
85
+
86
+ it "knows whether spell_guessing is enabled or not" do
87
+ @opts.spell_guessing_enabled?.should == true
88
+ end
89
+ end
76
90
 
77
91
  end
78
92
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/ruby -w
2
2
  #
3
3
  # Specification for the LinkParser::Sentence class
4
- # $Id: sentence_spec.rb 48 2008-12-19 18:30:33Z deveiant $
4
+ # $Id: sentence_spec.rb 53 2009-06-03 12:52:13Z deveiant $
5
5
  #
6
6
  # See the LICENSE file in the distribution for information about copyright and licensing.
7
7
  #
@@ -33,8 +33,18 @@ describe LinkParser::Sentence do
33
33
  @sentence = LinkParser::Sentence.new( "The cat runs.", @dict )
34
34
  end
35
35
 
36
-
37
- it "returns an informational string when inspected" do
36
+ it "returns an informational string when inspected before it's been parsed" do
37
+ @sentence.inspect.should =~ %r{
38
+ <
39
+ LinkParser::Sentence:0x[[:xdigit:]]+
40
+ \s
41
+ \(unparsed\)
42
+ >
43
+ }x
44
+ end
45
+
46
+ it "returns an informational string when inspected after it's been parsed" do
47
+ @sentence.parse
38
48
  @sentence.inspect.should =~ %r{
39
49
  <
40
50
  LinkParser::Sentence:0x[[:xdigit:]]+
@@ -69,12 +79,12 @@ describe LinkParser::Sentence do
69
79
  it "delegates linkage methods to its first linkage" do
70
80
  @sentence.num_links.should == 5
71
81
  end
72
-
82
+
73
83
 
74
84
  it "knows whether or not it's been parsed" do
75
- @sentence.parsed?.should be_false()
85
+ @sentence.should_not be_parsed()
76
86
  @sentence.parse
77
- @sentence.parsed?.should be_true()
87
+ @sentence.should be_parsed()
78
88
  end
79
89
 
80
90
 
@@ -113,5 +123,20 @@ describe LinkParser::Sentence do
113
123
  end
114
124
  end
115
125
 
126
+
127
+ describe "parsed from a sentence that yields no linkages" do
128
+
129
+ before( :each ) do
130
+ @sentence = @dict.parse( "The event that he smiled at me gives me hope" )
131
+ end
132
+
133
+ it "raises a descriptive exception if a delegated method is called" do
134
+ expect {
135
+ @sentence.constituent_tree_string
136
+ }.to raise_error( LinkParser::Error, /sentence has no linkages/i )
137
+ end
138
+
139
+ end
140
+
116
141
  end
117
142