cgialib 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,403 @@
1
+ # File: SQLTokenizer.rb
2
+ # Author: Jack Herrington
3
+ # Purpose: A tokenizer specialized to look for SQL style tokens
4
+ # Date: 12/21/02
5
+
6
+ #require "Tokenizer"
7
+
8
+ module LanguageParser
9
+ # class : SQLT_State
10
+ #
11
+ # The base class state object for the SQL-Tokenizer state machine.
12
+
13
+ class SQLT_State
14
+ # Special characters that are found as delineators in SQL
15
+
16
+ @@specials = { ";" => 1, "," => 1, ":" => 1, "{" => 1, "}" => 1,
17
+ "(" => 1, ")" => 1, "[" => 1, "]" => 1, "%" => 1,
18
+ "+" => 1, "-" => 1, "*" => 1, "." => 1 }
19
+
20
+
21
+ # initialize( newstate, addtoken )
22
+ #
23
+ # newstate - A method to be called to change state
24
+ # addtoken - The method to be called to add a token
25
+ #
26
+ # Intializes the state object
27
+
28
+ def initialize( newstate, addtoken )
29
+
30
+ @newstate = newstate
31
+ @addtoken = addtoken
32
+
33
+ end
34
+
35
+ # next( ch )
36
+ #
37
+ # ch - The character
38
+ #
39
+ # All states should override this method. This handles a
40
+ # character from the stream. Returning true means that the
41
+ # parsing should continue to the next character. Returning false
42
+ # means the parser should stay on the current character.
43
+
44
+ def next( ch )
45
+ true
46
+ end
47
+
48
+ end
49
+
50
+ # class : SQLT_Comment
51
+ #
52
+ # State object for new style SQL comments (e.g. --)
53
+
54
+ class SQLT_Comment < SQLT_State
55
+
56
+ # initialize( newstate, addtoken )
57
+ #
58
+ # newstate - A method to be called to change state
59
+ # addtoken - The method to be called to add a token
60
+ #
61
+
62
+ def initialize( newstate, addtoken )
63
+
64
+ super( newstate, addtoken )
65
+
66
+ # Initialize the text buffer with the beginning //
67
+
68
+ @text = "-"
69
+ @waiting_for_dash = true
70
+
71
+ end
72
+
73
+ # next( ch )
74
+ #
75
+ # ch - The character
76
+ #
77
+ # Handles the character in the parsing stream
78
+
79
+ def next( ch )
80
+
81
+ if ( @waiting_for_dash && ch != "-" )
82
+
83
+ @addtoken.call( CommentToken.new( "-" ) )
84
+ @newstate.call( SQLT_NormalState )
85
+ return false
86
+
87
+ end
88
+
89
+ @waiting_for_dash = false
90
+
91
+ # Add the character to the comment text
92
+
93
+ @text += ch
94
+
95
+ # Go back to the normal state if we find a return
96
+
97
+ if ( ch == "\n" )
98
+
99
+ @addtoken.call( CommentToken.new( @text ) )
100
+ @newstate.call( SQLT_NormalState )
101
+
102
+ end
103
+
104
+ # Proceed to the next character
105
+
106
+ true
107
+
108
+ end
109
+
110
+ end
111
+
112
+ # class : SQLT_DoubleQuote
113
+ #
114
+ # Handles parsing strings
115
+
116
+ class SQLT_DoubleQuote < SQLT_State
117
+
118
+ # initialize( newstate, addtoken )
119
+ #
120
+ # newstate - A method to be called to change state
121
+ # addtoken - The method to be called to add a token
122
+ #
123
+
124
+ def initialize( newstate, addtoken )
125
+
126
+ super( newstate, addtoken )
127
+
128
+ # Start the text buffer with the beginning double quote
129
+
130
+ @text = "\'"
131
+
132
+ @waiting_for_end_apostrophe = false
133
+
134
+ @waiting_for_apostrophe = true
135
+
136
+ end
137
+
138
+ # next( ch )
139
+ #
140
+ # ch - The character
141
+ #
142
+ # Handles the character in the parsing stream
143
+
144
+ def next( ch )
145
+
146
+ if ( @waiting_for_apostrophe )
147
+
148
+ if ( ch == "\'" )
149
+
150
+ @token += ch
151
+ @waiting_for_apostrophe = false
152
+ return true
153
+
154
+ else
155
+
156
+ @addtoken.call( CodeToken.new( "\'" ) )
157
+ @newstate.call( SQLT_NormalState )
158
+ return false
159
+
160
+ end
161
+
162
+ end
163
+
164
+ # Add this character to the text buffer
165
+
166
+ @text += ch
167
+
168
+ if ( @waiting_for_end_apostrophe && ch == "\'" )
169
+
170
+ @addtoken.call( CodeToken.new( @text ) )
171
+ @newstate.call( SQLT_NormalState )
172
+
173
+ end
174
+
175
+ @waiting_for_end_apostrophe = ( ch == "\'" )
176
+
177
+ # Proceed to the next character
178
+
179
+ true
180
+
181
+ end
182
+
183
+ end
184
+
185
+ # SQLT_WhitespaceTokenizer
186
+ #
187
+ # Handles whitespace in the character stream
188
+
189
+ class SQLT_WhitespaceTokenizer < SQLT_State
190
+
191
+ # initialize( newstate, addtoken )
192
+ #
193
+ # newstate - A method to be called to change state
194
+ # addtoken - The method to be called to add a token
195
+ #
196
+
197
+ def initialize( newstate, addtoken )
198
+
199
+ super( newstate, addtoken )
200
+
201
+ # Initialize the text buffer to blank
202
+
203
+ @text = ""
204
+
205
+ end
206
+
207
+ # next( ch )
208
+ #
209
+ # ch - The character
210
+ #
211
+ # Handles the character in the parsing stream
212
+
213
+ def next( ch )
214
+
215
+ if ( ch =~ /\s/ )
216
+
217
+ # If the character is whitespace add it to
218
+ # the buffer
219
+
220
+ @text += ch
221
+ return true
222
+
223
+ else
224
+
225
+ # Otherwise return to the normal state and
226
+ # add the token
227
+
228
+ @addtoken.call( WhitespaceToken.new( @text ) )
229
+ @newstate.call( SQLT_NormalState )
230
+
231
+ # Return false because we want the tokenizer
232
+ # to re-run on the current character
233
+
234
+ return false
235
+
236
+ end
237
+
238
+ end
239
+
240
+ end
241
+
242
+ # class : SQLT_NormalState
243
+ #
244
+ # The default state machine to which all of the other states return.
245
+
246
+ class SQLT_NormalState < SQLT_State
247
+
248
+ # initialize( newstate, addtoken )
249
+ #
250
+ # newstate - A method to be called to change state
251
+ # addtoken - The method to be called to add a token
252
+ #
253
+
254
+ def initialize( newstate, addtoken )
255
+
256
+ super( newstate, addtoken )
257
+
258
+ # This normal state handles adding CodeTokens in the
259
+ # basic stream (e.g. not in a string). So we have a
260
+ # text buffer.
261
+
262
+ @text = ""
263
+
264
+ end
265
+
266
+ # next( ch )
267
+ #
268
+ # ch - The character
269
+ #
270
+ # Handles the character in the parsing stream
271
+
272
+ def next( ch )
273
+
274
+ if ch == "-"
275
+
276
+ # Start the comment switcher state if we
277
+ # see a slash
278
+
279
+ @addtoken.call( CodeToken.new( @text ) )
280
+ @newstate.call( SQLT_Comment )
281
+
282
+ elsif @@specials[ch]
283
+
284
+ # If this is a special character (e.g. ;,*,+, etc.)
285
+ # then dump the current token and add the special
286
+ # characer token
287
+
288
+ @addtoken.call( CodeToken.new( @text ) )
289
+ @text = ""
290
+
291
+ @addtoken.call( CodeToken.new( ch ) )
292
+
293
+ elsif ch == "\'"
294
+
295
+ # Start the double quote state if we see a
296
+ # double quote
297
+
298
+ @addtoken.call( CodeToken.new( @text ) )
299
+ @newstate.call( SQLT_DoubleQuote )
300
+
301
+ elsif ch =~ /\s/
302
+
303
+ # Move into the whitespace state if we
304
+ # see whitespace. Return true to re-run
305
+ # the parser on this character.
306
+
307
+ @addtoken.call( CodeToken.new( @text ) )
308
+ @newstate.call( SQLT_WhitespaceTokenizer )
309
+ return false
310
+
311
+ else
312
+
313
+ # Otherwise add this character to the buffer
314
+
315
+ @text += ch
316
+
317
+ end
318
+
319
+ # Continue onto the next character
320
+
321
+ true
322
+
323
+ end
324
+
325
+ end
326
+
327
+ # class : SQLTokenizer
328
+ #
329
+ # The main entry class that parses SQL text into a set of tokens
330
+
331
+ class SQLTokenizer < Tokenizer
332
+
333
+ # parse( text )
334
+ #
335
+ # text - The SQL text
336
+ #
337
+ # Parses the SQL text string into tokens
338
+
339
+ def parse( text )
340
+
341
+ # Set the current state to the normal state
342
+
343
+ @state = SQLT_NormalState.new(
344
+ method( :newstate ),
345
+ method( :addtoken ) )
346
+
347
+ # Iterate through the text
348
+
349
+ index = 0
350
+
351
+ while index < text.length
352
+
353
+ # Dispatch the character to the current state
354
+
355
+ if ( @state.next( text[ index ].chr() ) )
356
+
357
+ index += 1
358
+
359
+ end
360
+
361
+ end
362
+
363
+ end
364
+
365
+ protected
366
+
367
+ # newstate( classref )
368
+ #
369
+ # classref - The class to use for the new state object
370
+ #
371
+ # This callback informs the state machine that we are going into a new
372
+ # state. The state-machine is given a class reference which it then uses to
373
+ # build a new state object
374
+
375
+ def newstate( classref )
376
+
377
+ # Sets the state to a new state based on the class given
378
+
379
+ @state = classref.new( method( :newstate ), method( :addtoken ) )
380
+
381
+ end
382
+
383
+ # addtoken( token )
384
+ #
385
+ # token - The new token
386
+ #
387
+ # Adds a token to the token stream.
388
+
389
+ def addtoken( token )
390
+
391
+ # Adds a token to the stack. If the token text is empty
392
+ # then ignore it
393
+
394
+ return if ( token.to_s().length < 1 )
395
+
396
+ # Add the token to the array
397
+
398
+ @tokens.push( token )
399
+
400
+ end
401
+
402
+ end
403
+ end
data/lib/cgialib/lp.rb CHANGED
@@ -5,6 +5,11 @@ require 'lp/Tokenizer'
5
5
  require 'lp/CTokenizer'
6
6
  require 'lp/CLanguageScanner'
7
7
  require 'lp/CPPLanguageScanner'
8
+ require 'lp/JavaDoc'
9
+ require 'lp/JavaLanguageScanner'
10
+ require 'lp/SQLTokenizer'
11
+ require 'lp/SQLLanguageScanner'
12
+
8
13
  module LanguageParser
9
14
  VERSION = '0.0.1'
10
15
  end
@@ -6,8 +6,10 @@ C_UT_TEMPLATE = <<'EOF'
6
6
  * you make to it will be lost when it is regenerated.
7
7
  * ==========================================================================
8
8
  */
9
- static int run_tests()
9
+ int run_tests()
10
10
  {
11
+ int failed = 0;
12
+ int success = 0;
11
13
  <%
12
14
  prototypes.each { |proto|
13
15
  name = proto.method_name
@@ -22,13 +24,18 @@ prototypes.each { |proto|
22
24
  %>
23
25
  if ( <%= name %>( <%= args %> ) != <%= result %> )
24
26
  {
25
- printf( stderr, "Unit test <%= test_name %> failed!\n" );
26
- return 0;
27
+ failed++;
28
+ printf( "<%= test_name %>: <%= name %>( <%= args %> ) == <%= result%> failed!\n" );
29
+ } else {
30
+ success++;
31
+ printf( "<%= test_name %>: <%= name %>( <%= args %> ) == <%= result%> passed!\n" );
32
+
27
33
  }
28
34
  <%
29
35
  }
30
36
  }
31
37
  %>
38
+ printf("%d of %d (%d%%) Unit Test are passed\n", success, success+failed,success*100/(success+failed));
32
39
  return 1;
33
40
  }
34
41
  /*
data/lib/cgialib.rb CHANGED
@@ -5,5 +5,5 @@ require 'cgialib/lp'
5
5
  require 'cgialib/template'
6
6
 
7
7
  module Cgialib
8
- VERSION = '0.0.1'
8
+ VERSION = '0.0.2'
9
9
  end
data/website/index.html CHANGED
@@ -42,30 +42,13 @@
42
42
  <p><pre class='syntax'><span class="ident">sudo</span> <span class="ident">gem</span> <span class="ident">install</span> <span class="ident">cgialib</span></pre></p>
43
43
  <h2>The basics</h2>
44
44
  <h2>Demonstration of usage</h2>
45
- <h2>Forum</h2>
46
- <p><a href="http://groups.google.com/group/cgialib">http://groups.google.com/group/cgialib</a></p>
47
- <p><span class="caps">TODO</span> &#8211; create Google Group &#8211; cgialib</p>
48
45
  <h2>How to submit patches</h2>
49
46
  <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
50
- <p><span class="caps">TODO</span> &#8211; pick <span class="caps">SVN</span> or Git instructions</p>
51
- <p>The trunk repository is <code>svn://rubyforge.org/var/svn/cgialib/trunk</code> for anonymous access.</p>
52
- <p><span class="caps">OOOORRRR</span></p>
53
47
  <p>You can fetch the source from either:</p>
54
48
  <ul>
55
- <li>rubyforge: <span class="caps">MISSING</span> IN <span class="caps">ACTION</span></li>
49
+ <li>rubyforge: <a href="http://rubyforge.org/scm/?group_id=7342">http://rubyforge.org/scm/?group_id=7342</a></li>
56
50
  </ul>
57
- <p><span class="caps">TODO</span> &#8211; You can not created a RubyForge project, OR have not run <code>rubyforge config</code><br />
58
- yet to refresh your local rubyforge data with this projects&#8217; id information.</p>
59
- <p>When you do this, this message will magically disappear!</p>
60
- <p>Or you can hack website/index.txt and make it all go away!!</p>
61
- <ul>
62
- <li>github: <a href="http://github.com/ruanwz/cgialib/tree/master">http://github.com/ruanwz/cgialib/tree/master</a></li>
63
- </ul>
64
- <pre>git clone git://github.com/ruanwz/cgialib.git</pre>
65
- <ul>
66
- <li>gitorious: <a href="git://gitorious.org/cgialib/mainline.git">git://gitorious.org/cgialib/mainline.git</a></li>
67
- </ul>
68
- <pre>git clone git://gitorious.org/cgialib/mainline.git</pre>
51
+ <pre>git clone git://rubyforge.org/cgialib.git</pre>
69
52
  <h3>Build and test instructions</h3>
70
53
  <pre>cd cgialib
71
54
  rake test
@@ -73,9 +56,9 @@ rake install_gem</pre>
73
56
  <h2>License</h2>
74
57
  <p>This code is free to use under the terms of the <span class="caps">MIT</span> license.</p>
75
58
  <h2>Contact</h2>
76
- <p>Comments are welcome. Send an email to <a href="mailto:FIXME"><span class="caps">FIXME</span> full name</a> email via the <a href="http://groups.google.com/group/cgialib">forum</a></p>
59
+ <p>Comments are welcome. Send an email to <a href="mailto:davidruan@gmail.com">David Ruan</a></p>
77
60
  <p class="coda">
78
- <a href="FIXME email">FIXME full name</a>, 19th November 2008<br>
61
+ <a href="ruanwz@gmail.com">David Ruan</a>, 19th November 2008<br>
79
62
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
80
63
  </p>
81
64
  </div>
data/website/index.txt CHANGED
@@ -1,9 +1,7 @@
1
1
  h1. cgialib
2
2
 
3
-
4
3
  h2. What
5
4
 
6
-
7
5
  h2. Installing
8
6
 
9
7
  <pre syntax="ruby">sudo gem install cgialib</pre>
@@ -13,26 +11,13 @@ h2. The basics
13
11
 
14
12
  h2. Demonstration of usage
15
13
 
16
-
17
-
18
- h2. Forum
19
-
20
- "http://groups.google.com/group/cgialib":http://groups.google.com/group/cgialib
21
-
22
- TODO - create Google Group - cgialib
23
-
24
14
  h2. How to submit patches
25
15
 
26
16
  Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
27
17
 
28
- TODO - pick SVN or Git instructions
29
-
30
- The trunk repository is <code>svn://rubyforge.org/var/svn/cgialib/trunk</code> for anonymous access.
31
-
32
- OOOORRRR
33
-
34
18
  You can fetch the source from either:
35
19
 
20
+ <% rubyforge_project_id="7342" %>
36
21
  <% if rubyforge_project_id %>
37
22
 
38
23
  * rubyforge: "http://rubyforge.org/scm/?group_id=<%= rubyforge_project_id %>":http://rubyforge.org/scm/?group_id=<%= rubyforge_project_id %>
@@ -52,16 +37,6 @@ Or you can hack website/index.txt and make it all go away!!
52
37
 
53
38
  <% end %>
54
39
 
55
- * github: "http://github.com/ruanwz/cgialib/tree/master":http://github.com/ruanwz/cgialib/tree/master
56
-
57
- <pre>git clone git://github.com/ruanwz/cgialib.git</pre>
58
-
59
-
60
-
61
- * gitorious: "git://gitorious.org/cgialib/mainline.git":git://gitorious.org/cgialib/mainline.git
62
-
63
- <pre>git clone git://gitorious.org/cgialib/mainline.git</pre>
64
-
65
40
  h3. Build and test instructions
66
41
 
67
42
  <pre>cd cgialib
@@ -75,5 +50,5 @@ This code is free to use under the terms of the MIT license.
75
50
 
76
51
  h2. Contact
77
52
 
78
- Comments are welcome. Send an email to "FIXME full name":mailto:FIXME email via the "forum":http://groups.google.com/group/cgialib
53
+ Comments are welcome. Send an email to "David Ruan":mailto:davidruan@gmail.com
79
54
 
@@ -39,7 +39,7 @@
39
39
  </div>
40
40
  <%= body %>
41
41
  <p class="coda">
42
- <a href="FIXME email">FIXME full name</a>, <%= modified.pretty %><br>
42
+ <a href="ruanwz@gmail.com">David Ruan</a>, <%= modified.pretty %><br>
43
43
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
44
44
  </p>
45
45
  </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cgialib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Ruan
@@ -9,9 +9,29 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-19 00:00:00 -06:00
12
+ date: 2008-11-21 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: cucumber
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.1.9
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.1.11
34
+ version:
15
35
  - !ruby/object:Gem::Dependency
16
36
  name: newgem
17
37
  type: :development
@@ -53,8 +73,9 @@ files:
53
73
  - Rakefile
54
74
  - bin/testgen
55
75
  - config/website.yml.sample
56
- - features/development.feature
57
- - features/steps/common.rb
76
+ - examples/ut/mytest1.c
77
+ - features/language_parser.feature
78
+ - features/steps/language_parser.rb
58
79
  - features/steps/env.rb
59
80
  - lib/cgialib.rb
60
81
  - lib/testgen/cli.rb
@@ -65,6 +86,10 @@ files:
65
86
  - lib/cgialib/lp/CLanguageScanner.rb
66
87
  - lib/cgialib/lp/CPPLanguageScanner.rb
67
88
  - lib/cgialib/lp/CTokenizer.rb
89
+ - lib/cgialib/lp/JavaDoc.rb
90
+ - lib/cgialib/lp/JavaLanguageScanner.rb
91
+ - lib/cgialib/lp/SQLTokenizer.rb
92
+ - lib/cgialib/lp/SQLLanguageScanner.rb
68
93
  - lib/cgialib/template/ut.rb
69
94
  - lib/cgialib/template/ut/c.rb
70
95
  - script/console
@@ -1,13 +0,0 @@
1
- Feature: Development processes of newgem itself (rake tasks)
2
-
3
- As a Newgem maintainer or contributor
4
- I want rake tasks to maintain and release the gem
5
- So that I can spend time on the tests and code, and not excessive time on maintenance processes
6
-
7
- Scenario: Generate RubyGem
8
- Given this project is active project folder
9
- And 'pkg' folder is deleted
10
- When task 'rake gem' is invoked
11
- Then folder 'pkg' is created
12
- And file with name matching 'pkg/*.gem' is created else you should run "rake manifest" to fix this
13
- And gem spec key 'rdoc_options' contains /--mainREADME.rdoc/