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 )
255 ln = len( m.group( 0 ) )
256 l =
" " * ln + l[ln:]
259 cur_lines.append( l )
261 if field
or cur_lines:
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 )
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
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] ):
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:
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 )
448 for sec
in chap.order:
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" )
471 chap.sections = others
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
def __init__(self, lines)
def dump(self, prefix="", width=60)
def set_section(self, section_name)
def __init__(self, name="Other")
def sort_order_list(input_list, order_list)
def add_block(self, block)
def process_content(self, content)
def dump(self, prefix="")
def get_markup_items(self, tag_name)
def get_markup_text(self, tag_name)
def __init__(self, source, follow, processor)
def add_chapter(self, block)
def dump(self, prefix="", width=60)
def get_markup(self, tag_name)
def dump_lines(self, margin=0, width=60)
def __init__(self, block)
The DocCode class is used to store source code lines.
def __init__(self, margin, lines)
def __init__(self, name, lines)
def dump_lines(self, margin=0, width=60)
def __init__(self, tag, lines)
def get_markup_name(self, tag_name)
def get_markup_words(self, tag_name)
def dump_lines(self, margin=0, width=60)
def parse_sources(self, source_processor)