rubylexer 0.7.6 → 0.7.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -30,18 +30,19 @@ class Token
30
30
  def strify
31
31
  [self.class.name[/[^:]+$/],": ",instance_variables.sort.collect{|v|
32
32
  [v,"=",instance_variable_get(v).inspect," "]
33
- }].to_s
33
+ }].join
34
34
  end
35
35
  end
36
36
  end
37
37
 
38
- macros=silent=file=nil
39
-
38
+ name=macros=silent=file=nil
39
+ options={}
40
40
  #allow -e
41
41
  opts=GetoptLong.new(
42
42
  ["--eval", "-e", GetoptLong::REQUIRED_ARGUMENT],
43
43
  ["--silent", "-s", GetoptLong::NO_ARGUMENT],
44
- ["--macro", "-m", GetoptLong::NO_ARGUMENT]
44
+ ["--macro", "-m", GetoptLong::NO_ARGUMENT],
45
+ ["--ruby19", "-9", GetoptLong::NO_ARGUMENT]
45
46
  )
46
47
  opts.each{|opt,arg|
47
48
  case opt
@@ -52,6 +53,8 @@ opts.each{|opt,arg|
52
53
  silent=true
53
54
  when '--macro'
54
55
  macros=true
56
+ when '--ruby19'
57
+ options[:rubyversion]=1.9
55
58
  end
56
59
  }
57
60
 
@@ -63,7 +66,9 @@ file||=if name=ARGV.first
63
66
  $stdin.read
64
67
  end
65
68
 
66
- lexer=RubyLexer.new(name, file)
69
+ args=name, file
70
+ args.push 1,0,options unless options.empty?
71
+ lexer=RubyLexer.new(*args)
67
72
  lexer.enable_macros! if macros
68
73
  if silent
69
74
  until RubyLexer::EoiToken===(tok=lexer.get1token)
@@ -3,6 +3,8 @@ require 'open3'
3
3
  require 'rubygems'
4
4
  require 'rubylexer/test/testcases'
5
5
  require 'test/code/rubylexervsruby'
6
+ require 'test/code/test_1.9'
7
+
6
8
  SEP='';
7
9
  'caleb clausen'.each_byte{|ch| SEP<<ch.to_s(2).gsub('0','-').gsub('1','+')}
8
10
  SEP<<'(0)'
@@ -68,17 +70,23 @@ end
68
70
  define_method '#{name}' do
69
71
  difflines=[]
70
72
  begin
71
- res=RubyLexerVsRuby.rubylexervsruby('__#{name}','#{esctc}',difflines)
72
- difflines.empty? or raise DifferencesFromMRILex, difflines
73
+ res=RubyLexerVsRuby.rubylexervsruby('__#{name}','#{esctc}',difflines)
74
+ unless difflines.empty?
75
+ puts '#{esctc}'
76
+ puts difflines.join
77
+ raise DifferencesFromMRILex
78
+ end
73
79
  res or raise LexerTestFailure, ''
74
- rescue Interrupt: exit
75
- rescue Exception=>e:
76
- e.message<<"\n"+'while lexing: #{esctc[0...1000]}'
77
- raise e
80
+ rescue Interrupt; exit
81
+ rescue Exception=>e
82
+ message=e.message.dup<<"\n"+'while lexing: #{esctc}'
83
+ e2=e.class.new(message)
84
+ e2.set_backtrace(e.backtrace)
85
+ raise e2
78
86
  end
79
87
  end
80
88
  ]
81
- }.to_s
89
+ }
82
90
 
83
91
  illegal_test_code= TestCases::ILLEGAL_TESTCASES.map{|tc|
84
92
  i+=1
@@ -89,20 +97,26 @@ end
89
97
  difflines=[]
90
98
  begin
91
99
  res=RubyLexerVsRuby.rubylexervsruby('__#{name}','#{esctc}',difflines)
92
- difflines.empty? or raise DifferencesFromMRILex, difflines
100
+ unless difflines.empty?
101
+ puts '#{esctc}'
102
+ puts difflines.join
103
+ raise DifferencesFromMRILex
104
+ end
93
105
  res or raise LexerTestFailure, ''
94
- rescue LexerTestFailure:
106
+ rescue LexerTestFailure
95
107
  puts 'warning: test failure lexing "#{esctc}"'
96
- rescue Interrupt: exit
97
- rescue Exception=>e:
98
- e.message<<"\n"+'while lexing: #{esctc}'
99
- raise e
108
+ rescue Interrupt; exit
109
+ rescue Exception=>e;
110
+ message=e.message.dup<<"\n"+'while lexing: #{esctc}'
111
+ e2=e.class.new(message)
112
+ e2.set_backtrace(e.backtrace)
113
+ raise e2
100
114
  end
101
115
  end
102
116
  ]
103
- }.to_s
104
-
117
+ }
105
118
 
106
- # puts test_code+illegal_test_code
107
- eval test_code+illegal_test_code
119
+ src=(test_code+illegal_test_code).join
120
+ # puts src
121
+ eval src
108
122
  end
@@ -194,7 +194,7 @@ end
194
194
  return false
195
195
  =end
196
196
 
197
- rescue Interrupt: raise
197
+ rescue Interrupt; raise
198
198
  rescue Exception
199
199
  File.exist? nopfile and
200
200
  system "ruby -c #{nopfile} >/dev/null 2>&1" or expected="(expected) " unless stringdata
@@ -0,0 +1,31 @@
1
+ require 'test/unit'
2
+ require "rubylexer"
3
+ require "rubylexer/test/oneliners_1.9"
4
+
5
+ class Ruby1_9Tests < Test::Unit::TestCase
6
+ include Ruby1_9OneLiners
7
+ def test_1_9_roughly
8
+ EXPECT_NO_METHODS.each{|snippet|
9
+ begin
10
+ tokens=RubyLexer.new('string',snippet,1,0,:rubyversion=>1.9).to_a
11
+ assert_equal [],tokens.grep(RubyLexer::MethNameToken)
12
+ assert_equal [],tokens.grep(RubyLexer::ErrorToken)
13
+ rescue Exception=>e
14
+ e2=e.class.new(e.message+" while testing '#{snippet}'")
15
+ e2.set_backtrace(e.backtrace)
16
+ raise e2
17
+ end
18
+ }
19
+ EXPECT_1_METHOD.each{|snippet|
20
+ begin
21
+ tokens=RubyLexer.new('string',snippet,1,0,:rubyversion=>1.9).to_a
22
+ assert_equal 1,tokens.grep(RubyLexer::MethNameToken).size
23
+ assert_equal [],tokens.grep(RubyLexer::ErrorToken)
24
+ rescue Exception=>e
25
+ e2=e.class.new(e.message+" while testing '#{snippet}'")
26
+ e2.set_backtrace(e.backtrace)
27
+ raise e2
28
+ end
29
+ }
30
+ end
31
+ end
@@ -66,15 +66,15 @@ class SymbolToken
66
66
  def verify_offset(fd)
67
67
  la=fd.read(2)
68
68
  case la
69
- when '%s':
69
+ when '%s'
70
70
  quote=fd.read(1)
71
71
  ender=RubyLexer::PAIRS[quote] || quote
72
72
  body=@ident[2...-1]
73
- when /^:(['"])/:
73
+ when /^:(['"])/
74
74
  #stay right here
75
75
  quote=ender=$1
76
76
  body=@ident[2...-1]
77
- when /^:/:
77
+ when /^:/
78
78
  fd.pos-=1
79
79
  body=@ident[1..-1]
80
80
  else raise 'unrecognized symbol type'
@@ -85,7 +85,7 @@ class SymbolToken
85
85
  #punt if its too hard
86
86
  if quote
87
87
  bs="\\"
88
- hardstuff= /[#{bs}#{quote}#{bs}#{ender}\#\\]/
88
+ hardstuff= Regexp.new %/[#{bs}#{quote}#{bs}#{ender}\#\\\\]/
89
89
  return true if (body+bodyread).match(hardstuff)
90
90
  end
91
91
 
@@ -154,7 +154,7 @@ class StringToken
154
154
  #verify offsets of subtokens
155
155
  @elems.each{|elem|
156
156
  case elem
157
- when String:
157
+ when String
158
158
  #get string data to compare against,
159
159
  #translating dos newlines to unix.
160
160
  #(buffer mgt is a PITA)
@@ -245,7 +245,7 @@ def check_offset(tok,file=nil,endpos=nil)
245
245
  when RubyLexer::StringToken,RubyLexer::NumberToken,
246
246
  RubyLexer::HereBodyToken,RubyLexer::SymbolToken,
247
247
  RubyLexer::HerePlaceholderToken,
248
- RubyLexer::FileAndLineToken: #do nothing
248
+ RubyLexer::FileAndLineToken #do nothing
249
249
  else
250
250
  file.pos==endpos or allow_ooo or
251
251
  $stderr.puts "positions don't line up, expected #{endpos}, got #{file.pos}, token: #{tok.to_s.gsub("\n","\n ") }"
@@ -0,0 +1,2 @@
1
+ require 'test/code/regression'
2
+ require 'test/code/test_1.9'
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubylexer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.6
4
+ version: 0.7.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Caleb Clausen
8
8
  autorequire:
9
- bindir: ""
9
+ bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-07-06 00:00:00 -07:00
12
+ date: 2010-01-03 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,153 +20,149 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.2.0
23
+ version: 0.2.3
24
24
  version:
25
- - !ruby/object:Gem::Dependency
26
- name: hoe
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 1.12.2
34
- version:
35
- description: RubyLexer is a lexer library for Ruby, written in Ruby. Rubylexer is meant as a lexer for Ruby that's complete and correct; all legal Ruby code should be lexed correctly by RubyLexer as well. Just enough parsing capability is included to give RubyLexer enough context to tokenize correctly in all cases. (This turned out to be more parsing than I had thought or wanted to take on at first.) RubyLexer handles the hard things like complicated strings, the ambiguous nature of some punctuation characters and keywords in ruby, and distinguishing methods and local variables.
36
- email: rubylexer-owner @at@ inforadical .dot. net
25
+ description: RubyLexer is a lexer library for Ruby, written in Ruby. Rubylexer is meant as a lexer for Ruby that's complete and correct; all legal Ruby code should be lexed correctly by RubyLexer as well. Just enough parsing capability is included to give RubyLexer enough context to tokenize correctly in all cases. (This turned out to be more parsing than I had thought or wanted to take on at first.) RubyLexer handles the hard things like complicated strings, the ambiguous nature of some punctuation characters and keywords in ruby, and distinguishing methods and local variables. RubyLexer is not particularly clean code. As I progressed in writing this, I've learned a little about how these things are supposed to be done; the lexer is not supposed to have any state of it's own, instead it gets whatever it needs to know from the parser. As a stand-alone lexer, Rubylexer maintains quite a lot of state. Every instance variable in the RubyLexer class is some sort of lexer state. Most of the complication and ugly code in RubyLexer is in maintaining or using this state.
26
+ email: caleb (at) inforadical (dot) net
37
27
  executables: []
38
28
 
39
29
  extensions: []
40
30
 
41
31
  extra_rdoc_files:
42
32
  - README.txt
43
- - Manifest.txt
44
- - howtouse.txt
45
- - History.txt
46
- - testing.txt
33
+ - COPYING
47
34
  files:
35
+ - .document
48
36
  - COPYING
49
- - README.txt
37
+ - History.txt
38
+ - Makefile
50
39
  - Manifest.txt
51
- - Rakefile
40
+ - README.txt
52
41
  - howtouse.txt
53
- - History.txt
54
- - testing.txt
55
- - lib/rubylexer/rubycode.rb
56
- - lib/rubylexer/context.rb
57
- - lib/rubylexer/token.rb
58
- - lib/rubylexer/0.6.rb
42
+ - lib/.document
43
+ - lib/assert.rb
44
+ - lib/rubylexer.rb
45
+ - lib/rubylexer/.document
59
46
  - lib/rubylexer/0.6.2.rb
47
+ - lib/rubylexer/0.6.rb
60
48
  - lib/rubylexer/0.7.0.rb
61
- - lib/rubylexer/version.rb
62
- - lib/rubylexer/rulexer.rb
63
- - lib/rubylexer/tokenprinter.rb
49
+ - lib/rubylexer/0.7.1.rb
50
+ - lib/rubylexer/charhandler.rb
64
51
  - lib/rubylexer/charset.rb
52
+ - lib/rubylexer/context.rb
65
53
  - lib/rubylexer/lextable.rb
54
+ - lib/rubylexer/rubycode.rb
55
+ - lib/rubylexer/rulexer.rb
66
56
  - lib/rubylexer/symboltable.rb
67
- - lib/rubylexer/charhandler.rb
68
- - lib/assert.rb
69
- - lib/rubylexer.rb
70
- - test/data/blockassigntest.rb
71
- - test/data/for.rb
72
- - test/data/chunky_bacon.rb
73
- - test/data/and.rb
74
- - test/data/pre.unix.rb
75
- - test/data/untermed_string.rb.broken
76
- - test/data/__end__2.rb
77
- - test/data/w.rb
78
- - test/data/if.rb
79
- - test/data/pre.rb
80
- - test/data/jarh.rb
81
- - test/data/regtest.rb
82
- - test/data/chunky_bacon4.rb
83
- - test/data/__end__.rb
84
- - test/data/strinc.rb
85
- - test/data/lbrace.rb
86
- - test/data/p.rb
87
- - test/data/chunky.plain.rb
88
- - test/data/noeolatend.rb
89
- - test/data/g.rb
90
- - test/data/23.rb
91
- - test/data/lbrack.rb
92
- - test/data/untitled1.rb
93
- - test/data/rescue.rb
94
- - test/data/pleac.rb
95
- - test/data/pleac.rb.broken
96
- - test/data/heart.rb
97
- - test/data/s.rb
98
- - test/data/wsdlDriver.rb
99
- - test/data/p-op.rb
100
- - test/data/1.rb
101
- - test/data/1.rb.broken
102
- - test/data/untermed_here.rb.broken
103
- - test/data/newsyntax.rb
104
- - test/data/chunky_bacon3.rb
105
- - test/data/chunky_bacon2.rb
106
- - test/data/format.rb
107
- - test/code/locatetest.rb
108
- - test/code/rubylexervsruby.rb
109
- - test/code/tokentest.rb
110
- - test/code/dumptokens.rb
111
- - test/code/torment
112
- - test/code/locatetest
113
- - test/code/deletewarns.rb
114
- - lib/rubylexer/0.7.1.rb
57
+ - lib/rubylexer/test/illegal_oneliners.rb
58
+ - lib/rubylexer/test/illegal_stanzas.rb
59
+ - lib/rubylexer/test/oneliners.rb
60
+ - lib/rubylexer/test/oneliners_1.9.rb
61
+ - lib/rubylexer/test/stanzas.rb
62
+ - lib/rubylexer/test/testcases.rb
63
+ - lib/rubylexer/token.rb
64
+ - lib/rubylexer/tokenprinter.rb
65
+ - lib/rubylexer/version.rb
66
+ - rubylexer.gemspec
115
67
  - test/code/all_the_gems.rb
116
68
  - test/code/all_the_raas.rb
117
69
  - test/code/all_the_rubies.rb
70
+ - test/code/coloruby.rb
71
+ - test/code/deletewarns.rb
72
+ - test/code/dumptokens.rb
118
73
  - test/code/errscan
119
74
  - test/code/isolate_error.rb
120
75
  - test/code/lexloop
76
+ - test/code/locatetest
77
+ - test/code/locatetest.rb
121
78
  - test/code/regression.rb
79
+ - test/code/rubylexervsruby.rb
122
80
  - test/code/strgen.rb
123
81
  - test/code/tarball.rb
124
- - lib/rubylexer/test/testcases.rb
125
- - test/data/cvtesc.rb
82
+ - test/code/test_1.9.rb
83
+ - test/code/tokentest.rb
84
+ - test/code/torment
85
+ - test/data/1.rb
86
+ - test/data/1.rb.broken
87
+ - test/data/23.rb
88
+ - test/data/__end__.rb
89
+ - test/data/__end__2.rb
126
90
  - test/data/__eof2.rb
127
91
  - test/data/__eof5.rb
128
92
  - test/data/__eof6.rb
93
+ - test/data/and.rb
94
+ - test/data/blockassigntest.rb
95
+ - test/data/chunky.plain.rb
96
+ - test/data/chunky_bacon.rb
97
+ - test/data/chunky_bacon2.rb
98
+ - test/data/chunky_bacon3.rb
99
+ - test/data/chunky_bacon4.rb
100
+ - test/data/cvtesc.rb
101
+ - test/data/for.rb
102
+ - test/data/format.rb
103
+ - test/data/g.rb
129
104
  - test/data/hd0.rb
130
105
  - test/data/hdateof.rb
131
106
  - test/data/hdempty.rb
132
- - test/data/hdr_dos2.rb
133
- - test/data/hdr_dos.rb
134
107
  - test/data/hdr.rb
135
- - test/data/here_escnl_dos.rb
108
+ - test/data/hdr_dos.rb
109
+ - test/data/hdr_dos2.rb.broken
110
+ - test/data/heart.rb
136
111
  - test/data/here_escnl.rb
137
- - test/data/heremonsters_dos.rb
138
- - test/data/heremonsters_dos.rb.broken
139
- - test/data/heremonsters.rb
140
- - test/data/heremonsters.rb.broken
112
+ - test/data/here_escnl_dos.rb
141
113
  - test/data/here_squote.rb
142
- - lib/rubylexer/test/illegal_oneliners.rb
143
- - lib/rubylexer/test/illegal_stanzas.rb
114
+ - test/data/heremonsters.rb
115
+ - test/data/heremonsters_broken.rb
116
+ - test/data/heremonsters_dos.rb
117
+ - test/data/heremonsters_dos_broken.rb
118
+ - test/data/if.rb
119
+ - test/data/jarh.rb
120
+ - test/data/lbrace.rb
121
+ - test/data/lbrack.rb
144
122
  - test/data/make_ws_strdelim.rb
145
123
  - test/data/maven2_builer_test.rb
146
124
  - test/data/migration.rb
125
+ - test/data/modl.rb
147
126
  - test/data/modl_dos.rb
148
127
  - test/data/modl_fails.rb
149
- - test/data/modl.rb
150
128
  - test/data/multilinestring.rb
151
- - lib/rubylexer/test/oneliners.rb
152
- - test/data/simple_dos.rb
129
+ - test/data/newsyntax.rb
130
+ - test/data/noeolatend.rb
131
+ - test/data/p-op.rb
132
+ - test/data/p.rb
133
+ - test/data/pleac.rb
134
+ - test/data/pleac.rb.broken
135
+ - test/data/pre.rb
136
+ - test/data/pre.unix.rb
137
+ - test/data/regtest.rb
138
+ - test/data/rescue.rb
139
+ - test/data/s.rb
153
140
  - test/data/simple.rb
154
- - lib/rubylexer/test/stanzas.rb
141
+ - test/data/simple_dos.rb
155
142
  - test/data/strdelim_crlf.rb
143
+ - test/data/strinc.rb
144
+ - test/data/stuff.rb
156
145
  - test/data/stuff2.rb
157
146
  - test/data/stuff3.rb
158
147
  - test/data/stuff4.rb
159
- - test/data/stuff.rb
160
148
  - test/data/tkweird.rb
161
149
  - test/data/unending_stuff.rb
150
+ - test/data/untermed_here.rb.broken
151
+ - test/data/untermed_string.rb.broken
152
+ - test/data/untitled1.rb
153
+ - test/data/w.rb
162
154
  - test/data/whatnot.rb
163
155
  - test/data/ws_strdelim.rb
156
+ - test/data/wsdlDriver.rb
164
157
  - test/test.sh
158
+ - test/test_all.rb
159
+ - testing.txt
165
160
  has_rdoc: true
166
- homepage: http://github.com/coatl/rubylexer/
161
+ homepage: http://github.com/coatl/rubylexer
167
162
  post_install_message:
168
163
  rdoc_options:
169
- - -x lib/rubylexer/test/oneliners.rb
164
+ - --main
165
+ - README.txt
170
166
  require_paths:
171
167
  - lib
172
168
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -189,4 +185,4 @@ signing_key:
189
185
  specification_version: 2
190
186
  summary: RubyLexer is a lexer library for Ruby, written in Ruby.
191
187
  test_files:
192
- - test/code/regression.rb
188
+ - test/test_all.rb