Class: LanguageParser::JavaDoc

Inherits:
Object
  • Object
show all
Defined in:
lib/cgialib/lp/JavaDoc.rb

Overview

class : JavaDoc

Simple JavaDoc interpreter. This class holds JavaDoc tokens for a series of related JavaDoc comments. You should use one JavaDoc object per method or class. The JavaDoc object parses the comments, and stores the JavaDoc data in structured holders for easy access.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeJavaDoc

initialize()

Builds the JavaDoc class



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cgialib/lp/JavaDoc.rb', line 19

def initialize()
  
  # Hash to hold the @name tags. The default text goes into a tag named
  # '@desc'.
  
  @tags = { '@desc' => "" }
  
  # Special holder for the @param values
  
  @params = {}
  
end

Instance Attribute Details

#paramsObject (readonly)

The @param contents



34
35
36
# File 'lib/cgialib/lp/JavaDoc.rb', line 34

def params
  @params
end

#tagsObject (readonly)

The tag contents



32
33
34
# File 'lib/cgialib/lp/JavaDoc.rb', line 32

def tags
  @tags
end

Instance Method Details

#parse(text) ⇒ Object

parse( text )

text - The JavaDoc comment

Parses the JavaDoc comment and stores the contents



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/cgialib/lp/JavaDoc.rb', line 58

def parse( text )
  
  # Strip leading and trailing space
  
  text.strip!
  
  # Return unless we see the distinctive '/**' JavaDoc beginning
  # marker
  
  return unless ( text =~ /^\/\*\*/ || text =~ /^\*/ )
  
  # This section removes all of the leading stars, the comment lines
  # and anything around the text
  
  cleaned = ""
  text.each_line { |line|
  
    line.strip!
  
    line.sub!( /^\/\*\*/, "" )
    line.sub!( /^\*\//, "" )
    line.sub!( /^\*\s*/, "" )
  
    line.strip!
  
    next if line.length < 1
  
    cleaned += "#{line}\n"
  
  }
  
  # This section is a mini-tokenizer that splits the content of the string
  # into an array.  The delimiter is whitespace.  The whitespace is stored
  # in the array as well as it may be important to some tags.
  
  in_whitespace = false
  text = ""
  tokens = []
  
  cleaned.each_byte { |ch|
  
    ch = ch.chr()
  
    if ( ch =~ /\s/ )
  
      if ( in_whitespace )
  
        text += ch
  
      else
  
        tokens.push( text ) if ( text.length > 0 )
        text = ch
        in_whitespace = true
  
      end
  
    else
  
      if ( in_whitespace )
  
        tokens.push( text ) if ( text.length > 0 )
        text = ch
        in_whitespace = false
  
      else
  
        text += ch
  
      end
  
    end
  
  }
  
  tokens.push( text ) if ( text.length > 0 )
  
  # Now we use our 'tokenized' array and search for the '@tag' items. As
  # we go through the tokens we are building a buffer.  When we reach a 
  # new tag we send the buffer on to add_to_tag.
  
  cur_name = "@desc"
  buffer = ""
  
  tokens.each { |tok|
  
    if ( tok =~ /^@/ )
  
      add_to_tag( cur_name, buffer ) if ( buffer.length > 0 )
      buffer = ""
  
      cur_name = tok
  
    else
  
      buffer += tok
  
    end
  
  }
  
  # Make sure we get the contents of the buffer at the end
  
  add_to_tag( cur_name, buffer ) if ( buffer.length > 0 )
  
  # Invoke the tag cleaner
  
  clean_tags()
  
end

#to_sObject

to_s()

Pretty prints the current contents of this JavaDoc object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/cgialib/lp/JavaDoc.rb', line 40

def to_s()
  
  text = ""
  
  @tags.each_key { |k| text += "#{k} : #{@tags[k]}\n" }
  
  @params.each_key { |k| text += "param(#{k}) : #{@params[k]}\n" }
  
  text
  
end