📄 tinydoc.g
字号:
header {
package isis.anp.nesc;
}
{
import isis.anp.nesc.tinydoc.Author;
import isis.anp.nesc.tinydoc.Description;
import isis.anp.nesc.tinydoc.Paragraph;
import isis.anp.nesc.tinydoc.Param;
import isis.anp.nesc.tinydoc.Returns;
import isis.anp.nesc.tinydoc.Section;
import isis.anp.nesc.tinydoc.See;
import isis.anp.nesc.tinydoc.TinyDoc;
import antlr.ASTFactory;
import antlr.ASTPair;
import antlr.CommonHiddenStreamToken;
import antlr.NoViableAltException;
import antlr.ParserSharedInputState;
import antlr.RecognitionException;
import antlr.Token;
import antlr.TokenBuffer;
import antlr.TokenStream;
import antlr.TokenStreamException;
import antlr.collections.AST;
import antlr.collections.impl.ASTArray;
import antlr.collections.impl.BitSet;
}
class TinyDocParser extends Parser;
options {
k=1;
buildAST = true;
}
translationUnit returns [TinyDoc tdObj = new TinyDoc()]
{ Section sectionObj = null; }
:
START
(
options { greedy = true; }:
sectionObj = firstParagraph { tdObj.add(sectionObj); }
)?
(sectionObj = labeledParagraph { tdObj.add(sectionObj); }
)*
END
;
firstParagraph returns [Description dObj = new Description()]
{ Paragraph pObj = null; }
:
pObj = firstSentence { dObj.setFirstSentence(pObj); }
(pObj = paragraph { dObj.setParagraph(pObj); }
)? { ## = #( #[FIRSTPARAGRAPH], ## ); }
;
firstSentence returns [Paragraph pObj = new Paragraph()]
:
(options { greedy = true; }: id: ID { pObj.addHiddenAfter((CommonHiddenStreamToken)id); }
)*
(options { greedy = true; }: d: DOT { pObj.addHiddenAfter((CommonHiddenStreamToken)d); }
)?
{ ## = #( #[FIRSTSENTENCE], ## ); }
;
paragraph returns [Paragraph pObj = new Paragraph()]
:
( d: DOT { pObj.addHiddenAfter((CommonHiddenStreamToken)d); }
| id: ID { pObj.addHiddenAfter((CommonHiddenStreamToken)id); }
)+
;
labeledParagraph returns [Section sObj = null]
{ Paragraph pObj = null;}
:
( PARAM^ (WS)* id: ID { sObj = new Param();
((Param)sObj).setName(id.getText());
}
| RETURN^ { sObj = new Returns(); }
| SEE^ { sObj = new See(); }
| AUTHOR^ { sObj = new Author(); }
)
pObj = paragraph { sObj.setParagraph(pObj); }
;
dummy
:
FIRSTSENTENCE
| FIRSTPARAGRAPH
;
{
import java.io.InputStream;
import java.io.Reader;
import java.util.Hashtable;
import antlr.ANTLRHashString;
import antlr.ByteBuffer;
import antlr.CharBuffer;
import antlr.CharStreamException;
import antlr.CharStreamIOException;
import antlr.InputBuffer;
import antlr.LexerSharedInputState;
import antlr.NoViableAltForCharException;
import antlr.RecognitionException;
import antlr.SemanticException;
import antlr.Token;
import antlr.TokenStream;
import antlr.TokenStreamException;
import antlr.TokenStreamIOException;
import antlr.TokenStreamRecognitionException;
import antlr.collections.impl.BitSet;
}
class TinyDocLexer extends Lexer;
options {
k=3;
// exportVocab = TinyDoc;
charVocabulary = '\3'..'\377'; // extended ASCII (3-255 in octal notation)
}
tokens {
PARAM = "@param";
RETURN = "@return";
SEE = "@see";
AUTHOR = "@author";
}
START
: "/**"
;
END
: "*/"
;
NL
: ( "\r\n" // Evil DOS
| '\r' // Macintosh
| '\n' // Unix (the right way)
) { newline(); }
(WS)* ( {LA(2) != '/'}? '*')*
{ $setText("\n");
}
;
DOT
: '.'
;
WS
: ( ' '
| '\t'
| '\014'
)
;
ID
: ( ~('\n' | '\r' | '\t' | ' ' | '\014' | '*' | '.' | '/')
| ( {LA(2) != '/'}? '*')
| ( {LA(2) != '*' && LA(3) != '*'}? '/')
)+
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -