tomparse 0.1.0 → 0.2.0
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.
- data/.ruby +1 -1
- data/HISTORY.md +12 -0
- data/README.md +0 -6
- data/lib/tomparse.rb +103 -34
- data/lib/tomparse.yml +1 -1
- metadata +6 -6
data/.ruby
CHANGED
data/HISTORY.md
CHANGED
@@ -1,5 +1,17 @@
|
|
1
1
|
# Release History
|
2
2
|
|
3
|
+
|
4
|
+
## 0.2.0 / 2012-03-5
|
5
|
+
|
6
|
+
This release improves support of TomDoc, in particular, named parameters. It also
|
7
|
+
fixes a bug with appending to argument and option descriptions.
|
8
|
+
|
9
|
+
Changes:
|
10
|
+
|
11
|
+
* Ass support for named parameters.
|
12
|
+
* Fix appending to argument description issue.
|
13
|
+
|
14
|
+
|
3
15
|
## 0.1.0 / 2012-03-04
|
4
16
|
|
5
17
|
TomParse is stand-alone TomDoc parser, spun-off and rewritten from the original
|
data/README.md
CHANGED
@@ -18,12 +18,6 @@ See [TomDoc](https://github.com/mojombo/tomdoc) for more information about
|
|
18
18
|
the TomDoc format.
|
19
19
|
|
20
20
|
|
21
|
-
## Limitations
|
22
|
-
|
23
|
-
Current implmentation doesn't yet support named parameters. Hopefully
|
24
|
-
that will be fixed soon in an upcoming release --any volunteers?
|
25
|
-
|
26
|
-
|
27
21
|
## Installation
|
28
22
|
|
29
23
|
$ gem install tomparse
|
data/lib/tomparse.rb
CHANGED
@@ -8,33 +8,6 @@ module TomParse
|
|
8
8
|
TomDoc.new(comment, parse_options)
|
9
9
|
end
|
10
10
|
|
11
|
-
# Raised when comment can't be parsed, which means it's most
|
12
|
-
# likely not valid TomDoc.
|
13
|
-
#
|
14
|
-
class ParseError < RuntimeError
|
15
|
-
# Create new ParseError object.
|
16
|
-
#
|
17
|
-
# doc - document string
|
18
|
-
#
|
19
|
-
def initialize(doc)
|
20
|
-
@doc = doc
|
21
|
-
end
|
22
|
-
|
23
|
-
# Provide access to document string.
|
24
|
-
#
|
25
|
-
# Returns String.
|
26
|
-
def message
|
27
|
-
@doc
|
28
|
-
end
|
29
|
-
|
30
|
-
# Provide access to document string.
|
31
|
-
#
|
32
|
-
# Returns String.
|
33
|
-
def to_s
|
34
|
-
@doc
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
11
|
# Encapsulate parsed tomdoc documentation.
|
39
12
|
#
|
40
13
|
# TODO: Currently uses lazy evaluation, eventually this should
|
@@ -132,7 +105,7 @@ module TomParse
|
|
132
105
|
end
|
133
106
|
|
134
107
|
# put first line back
|
135
|
-
lines.unshift(first.sub(/^\s*/,''))
|
108
|
+
lines.unshift(first.sub(/^\s*/,'')) if first
|
136
109
|
|
137
110
|
lines.compact.join("\n")
|
138
111
|
end
|
@@ -306,7 +279,7 @@ module TomParse
|
|
306
279
|
# Parse arguments section. Arguments occur subsequent to
|
307
280
|
# the description.
|
308
281
|
#
|
309
|
-
# section - String containing
|
282
|
+
# section - String containing argument definitions.
|
310
283
|
#
|
311
284
|
# Returns nothing.
|
312
285
|
def parse_arguments(section)
|
@@ -318,7 +291,7 @@ module TomParse
|
|
318
291
|
indent = line.scan(/^\s*/)[0].to_s.size
|
319
292
|
|
320
293
|
if last_indent && indent > last_indent
|
321
|
-
args.last.description
|
294
|
+
args.last.description << line.squeeze(" ")
|
322
295
|
else
|
323
296
|
param, desc = line.split(" - ")
|
324
297
|
args << Argument.new(param.strip, desc.strip) if param && desc
|
@@ -382,7 +355,8 @@ module TomParse
|
|
382
355
|
end
|
383
356
|
end
|
384
357
|
|
385
|
-
@returns
|
358
|
+
@returns.concat(returns)
|
359
|
+
@raises.concat(raises)
|
386
360
|
end
|
387
361
|
|
388
362
|
# Parse signature section.
|
@@ -427,7 +401,7 @@ module TomParse
|
|
427
401
|
indent = line.scan(/^\s*/)[0].to_s.size
|
428
402
|
|
429
403
|
if last_indent && indent > last_indent
|
430
|
-
args.last.description
|
404
|
+
args.last.description << line.squeeze(" ")
|
431
405
|
else
|
432
406
|
param, desc = line.split(" - ")
|
433
407
|
args << Argument.new(param.strip, desc.strip) if param && desc
|
@@ -445,7 +419,11 @@ module TomParse
|
|
445
419
|
#
|
446
420
|
class Argument
|
447
421
|
|
448
|
-
attr_accessor :name
|
422
|
+
attr_accessor :name
|
423
|
+
|
424
|
+
attr_accessor :description
|
425
|
+
|
426
|
+
attr_accessor :options
|
449
427
|
|
450
428
|
# Create new Argument object.
|
451
429
|
#
|
@@ -454,7 +432,7 @@ module TomParse
|
|
454
432
|
#
|
455
433
|
def initialize(name, description = '')
|
456
434
|
@name = name.to_s.intern
|
457
|
-
|
435
|
+
parse(description)
|
458
436
|
end
|
459
437
|
|
460
438
|
# Is this an optional argument?
|
@@ -464,6 +442,97 @@ module TomParse
|
|
464
442
|
@description.downcase.include? 'optional'
|
465
443
|
end
|
466
444
|
|
445
|
+
# Parse arguments section. Arguments occur subsequent to
|
446
|
+
# the description.
|
447
|
+
#
|
448
|
+
# section - String containing argument definitions.
|
449
|
+
#
|
450
|
+
# Returns nothing.
|
451
|
+
def parse(description)
|
452
|
+
desc = []
|
453
|
+
opts = []
|
454
|
+
|
455
|
+
lines = description.lines.to_a
|
456
|
+
|
457
|
+
until lines.empty? or /^\s+\:(\w+)\s+-\s+(.*?)$/ =~ lines.first
|
458
|
+
desc << lines.shift
|
459
|
+
end
|
460
|
+
|
461
|
+
opts = []
|
462
|
+
last_indent = nil
|
463
|
+
|
464
|
+
lines.each do |line|
|
465
|
+
next if line.strip.empty?
|
466
|
+
indent = line.scan(/^\s*/)[0].to_s.size
|
467
|
+
|
468
|
+
if last_indent && indent > last_indent
|
469
|
+
args.last.description << line.squeeze(" ")
|
470
|
+
else
|
471
|
+
param, desc = line.split(" - ")
|
472
|
+
opts << Option.new(param.strip, desc.strip) if param && desc
|
473
|
+
end
|
474
|
+
|
475
|
+
last_indent = indent
|
476
|
+
end
|
477
|
+
|
478
|
+
@description = desc.join
|
479
|
+
@options = opts
|
480
|
+
end
|
481
|
+
|
482
|
+
end
|
483
|
+
|
484
|
+
# Encapsulate a named parameter.
|
485
|
+
#
|
486
|
+
class Option
|
487
|
+
|
488
|
+
attr_accessor :name
|
489
|
+
|
490
|
+
attr_accessor :description
|
491
|
+
|
492
|
+
# Create new Argument object.
|
493
|
+
#
|
494
|
+
# name - name of option
|
495
|
+
# description - option description
|
496
|
+
#
|
497
|
+
def initialize(name, description = '')
|
498
|
+
@name = name.to_s.intern
|
499
|
+
@description = description
|
500
|
+
end
|
501
|
+
|
502
|
+
# Is this a required option?
|
503
|
+
#
|
504
|
+
# Returns Boolean.
|
505
|
+
def required?
|
506
|
+
@description.downcase.include? 'required'
|
507
|
+
end
|
508
|
+
|
509
|
+
end
|
510
|
+
|
511
|
+
# Raised when comment can't be parsed, which means it's most
|
512
|
+
# likely not valid TomDoc.
|
513
|
+
#
|
514
|
+
class ParseError < RuntimeError
|
515
|
+
# Create new ParseError object.
|
516
|
+
#
|
517
|
+
# doc - document string
|
518
|
+
#
|
519
|
+
def initialize(doc)
|
520
|
+
@doc = doc
|
521
|
+
end
|
522
|
+
|
523
|
+
# Provide access to document string.
|
524
|
+
#
|
525
|
+
# Returns String.
|
526
|
+
def message
|
527
|
+
@doc
|
528
|
+
end
|
529
|
+
|
530
|
+
# Provide access to document string.
|
531
|
+
#
|
532
|
+
# Returns String.
|
533
|
+
def to_s
|
534
|
+
@doc
|
535
|
+
end
|
467
536
|
end
|
468
537
|
|
469
538
|
end
|
data/lib/tomparse.yml
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tomparse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: microtest
|
16
|
-
requirement: &
|
16
|
+
requirement: &28469660 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *28469660
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: detroit
|
27
|
-
requirement: &
|
27
|
+
requirement: &28468540 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *28468540
|
36
36
|
description: ! 'TomParse is a Ruby TomDoc parser. It contains no other functionality
|
37
37
|
|
38
38
|
than the ability to take a comment and parse it in accordance to the
|