Changeset 221

Show
Ignore:
Timestamp:
04/07/07 00:11:48 (2 years ago)
Author:
ingy
Message:
 r3781@dhcp199:  ingy | 2007-04-07 13:35:17 +0900
 Release of Document-Tools
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/core/Spork/lib/Spork/Parser.pm

    r215 r221  
    44use base 'Document::Parser'; 
    55 
    6 sub set_ast { 
     6sub create_ast { 
    77    require Document::AST::Tree; 
    8     my $self = shift; 
    9     $self->{ast} = Document::AST::Tree->new; 
     8    return Document::AST::Tree->new; 
    109} 
    1110 
    12 sub set_grammar { 
    13     my $self = shift; 
     11sub create_grammar { 
    1412    my $all_phrases = [qw(b i tt hilite)]; 
    1513    my $all_blocks = [qw(indent center h2 ul pre p)]; 
    16     $self->{grammar} =  
    17     { 
     14    return { 
    1815        top => { 
    1916            blocks => $all_blocks, 
  • trunk/src/plugins/ingy/Document-Formatter/lib/Document/Parser.pm

    r218 r221  
    1717    my $self = shift; 
    1818    $self->{input} ||= shift; 
    19     $self->{grammar} or $self->set_grammar
    20     $self->{ast} or $self->set_ast
     19    $self->{ast} ||= $self->set_ast
     20    $self->{grammar} ||= $self->set_grammar
    2121    $self->parse_blocks('top'); 
    22     return $self->{ast}->content; 
     22    my $ast = $self->{ast}->content; 
     23    delete $self->{ast}; 
     24    return $ast; 
     25
     26 
     27sub set_ast { 
     28    my $self = shift; 
     29    $self->{ast} = shift || $self->create_ast; 
     30
     31 
     32sub set_grammar { 
     33    my $self = shift; 
     34    $self->{grammar} = shift || $self->create_grammar; 
    2335} 
    2436 
     
    1701821; 
    171183 
    172 =head1 
    173  
    174 =cut 
     184=head1 NAME 
     185 
     186Document::Parser - Base Class for Creating Text Format Parsers 
     187 
     188=head1 SYNOPSIS 
     189 
     190    package MyParser; 
     191    use base 'Document::Parser'; 
     192 
     193    sub create_grammar {  
     194        return { 
     195            # ... define a grammar hash here ... 
     196        }; 
     197    } 
     198=head1 DESCRIPTION 
     199 
     200Document::Parser is a base class that you can use to easily generate a parse 
     201for text document markups (like Wiki or POD markups). 
     202 
     203See this parser as an example: 
     204 
     205    http://svn.kwiki.org/kwiki/trunk/src/core/Spork/lib/Spork/Parser.pm 
     206 
     207And this module for usage of the parser: 
     208 
     209    http://svn.kwiki.org/kwiki/trunk/src/core/Spork/lib/Spork/Formatter2.pm 
     210 
     211=head1 AUTHOR 
     212 
     213Ingy döt Net <ingy@cpan.org> 
     214 
     215=head1 COPYRIGHT 
     216 
     217Copyright (c) 2007. Ingy döt Net. All rights reserved. 
     218 
     219This program is free software; you can redistribute it and/or modify it 
     220under the same terms as Perl itself. 
     221 
     222See http://www.perl.com/perl/misc/Artistic.html 
  • trunk/src/plugins/modules.mk

    r220 r221  
    114114        Document/AST.pm \ 
    115115        Document/Parser.pm \ 
     116        Document/Tools.pm \ 
    116117        Kwiki/AdSense.pm \ 
    117118        Kwiki/BreadCrumbs.pm \