28 re_code_start = re.compile(
r"(\s*){\s*$" )
29 re_code_end = re.compile(
r"(\s*)}\s*$" )
35 re_identifier = re.compile(
r'(\w*)' )
42 re_header_macro = re.compile(
r'^#define\s{1,}(\w{1,}_H)\s{1,}<(.*)>' )
63 if string.strip( l[:margin] ) ==
"":
65 self.lines.append( l )
67 def dump( self, prefix = "", width = 60 ):
75 result.append(
" " * margin + l )
93 self.words.extend( string.split( l ) )
95 def dump( self, prefix = "", width = 60 ):
105 for word
in self.
words:
111 result.append(
" " * margin + cur )
121 result.append(
" " * margin + cur )
154 if mode == mode_code:
155 m = re_code_end.match( l )
156 if m
and len( m.group( 1 ) ) <= margin:
159 self.items.append( code )
165 cur_lines.append( l[margin:] )
168 m = re_code_start.match( l )
173 self.items.append( para )
177 margin = len( m.group( 1 ) )
180 if not string.split( l )
and cur_lines:
184 self.items.append( para )
189 cur_lines.append( l )
191 if mode == mode_code:
193 code =
DocCode( margin, cur_lines )
194 self.items.append( code )
197 self.items.append( para )
201 print prefix + self.field +
" ::"
202 prefix = prefix +
"----"
219 result.extend( p.dump_lines( margin, width ) )
228 re_field = re.compile(
r"\s*(\w*|\w(\w|\.)*\w)\s*::" )
235 self.
tag = string.lower( tag )
243 m = re_field.match( l )
250 self.fields.append( f )
255 ln = len( m.group( 0 ) )
256 l =
" " * ln + l[ln:]
259 cur_lines.append( l )
261 if field
or cur_lines:
263 self.fields.append( f )
267 return self.
fields[0].items[0].words[0]
274 for word
in self.
fields[0].items[0].words:
275 result = result +
" " + word
281 print " " * margin +
"<" + self.
tag +
">"
284 print " " * margin +
"</" + self.
tag +
">"
295 self.
title = block.get_markup_words(
"title" )
296 self.
order = block.get_markup_words(
"sections" )
299 self.
title = string.split(
"Miscellaneous" )
318 self.defs.append( block )
321 self.block_names.append( block.name )
322 self.
blocks[block.name] = block
326 for block
in self.
defs:
327 title = block.get_markup_text(
"title" )
330 self.
abstract = block.get_markup_words(
"abstract" )
331 self.
description = block.get_markup_items(
"description" )
332 self.
order = block.get_markup_words(
"order" )
343 """initialize a block content processor"""
354 """set current section during parsing"""
355 if not self.sections.has_key( section_name ):
357 self.
sections[section_name] = section
364 self.chapters.append( chapter )
368 """reset the content processor for a new block"""
374 """add a new markup section"""
379 if len( marks ) > 0
and not string.strip( marks[-1] ):
384 self.markups.append( m )
390 """process a block content and return a list of DocMarkup objects
391 corresponding to it"""
398 for t
in re_markup_tags:
401 found = string.lower( m.group( 1 ) )
402 prefix = len( m.group( 0 ) )
403 line =
" " * prefix + line[prefix:]
411 if len( string.strip( line ) ) > 0:
412 self.markup_lines.append( line )
414 self.markup_lines.append( line )
421 blocks = source_processor.blocks
422 count = len( blocks )
424 for n
in range( count ):
432 while m < count
and not blocks[m].content:
433 follow.append( blocks[m] )
436 doc_block =
DocBlock( source, follow, self )
442 for sec
in self.sections.values():
448 for sec
in chap.order:
449 if self.sections.has_key( sec ):
451 section.chapter = chap
453 chap.sections.append( section )
455 sys.stderr.write(
"WARNING: chapter '" + \
456 chap.name +
"' in " + chap.block.location() + \
457 " lists unknown section '" + sec +
"'\n" )
462 for sec
in self.sections.values():
471 chap.sections = others
472 self.chapters.append( chap )
486 self.
markups = processor.process_content( source.content )
497 para = markup.fields[0].items[0]
499 m = re_identifier.match( name )
506 if self.
type ==
"section":
508 processor.set_section( self.
name )
509 processor.section.add_def( self )
510 elif self.
type ==
"chapter":
512 processor.add_chapter( self )
514 processor.section.add_block( self )
524 m = re_header_macro.match( l )
526 processor.headers[m.group( 2 )] = m.group( 1 );
529 if re_source_sep.match( l ):
535 end = len( source ) - 1
537 while start < end
and not string.strip( source[start] ):
540 while start < end
and not string.strip( source[end] ):
543 if start == end
and not string.strip( source[start] ):
546 self.
code = source[start:end + 1]
549 return self.source.location()
552 """return the DocMarkup corresponding to a given tag in a block"""
554 if m.tag == string.lower( tag_name ):
559 """return the name of a given primary markup in a block"""
569 return m.fields[0].items[0].words
575 return string.join( result )
580 return m.fields[0].items
The DocCode class is used to store source code lines.