antlr解析googlecodewiki.1 -- 段落和标题

 

input:

 

= ab zx =
abc inline
XXX

== cd ==
zef
 

antlr syntax:

 

grammar bestpaper;  
options {  
    output=AST;  
    ASTLabelType=CommonTree;  
}  
chapter   
    :   (paragraph NEWLINE+)+;     
paragraph  
    :   heading NEWLINE+ content | heading;    
heading  
    :  SPACE? (heading1 | heading2 | heading3 | heading4 | heading5 | heading6) SPACE?;      
heading1  
    :   H1 SPACE title SPACE H1;  
heading2  
    :   H2 SPACE title SPACE H2;  
heading3  
    :   H3 SPACE title SPACE H3;  
heading4  
    :   H4 SPACE title SPACE H4;  
heading5  
    :   H5 SPACE title SPACE H5;  
heading6  
    :   H6 SPACE title SPACE H6;      
title     
    :   (WORD SPACE)* WORD;  
content   
    :   (line NEWLINE)* line;  
line  
    :	SPACE? (WORD SPACE)* WORD SPACE? | SPACE;

      
H1  
    :   '=';  
H2  
    :   '==';  
H3  
    :   '===';  
H4  
    :   '====';  
H5  
    :   '=====';  
H6  
    :   '======';     
INT   
    :   ('1'..'9')('0'..'9')* | '0';          
NEWLINE   
    :   '\r'? '\n' ;  
SPACE     
    :   (' ' | '\t')+;  
WORD  
    :   (~('\r' | '\n' | ' ' | '\t'))+; 

 

parse tree:



antlr解析googlecodewiki.1 -- 段落和标题_第1张图片

你可能感兴趣的:(Google)