📄 n3antlrparser.java
字号:
// $ANTLR 2.7.2: "src/com/hp/hpl/jena/n3/n3.g" -> "N3AntlrParser.java"$
package com.hp.hpl.jena.n3 ;
import antlr.TokenStreamRecognitionException ;
import antlr.TokenBuffer;
import antlr.TokenStreamException;
import antlr.Token;
import antlr.TokenStream;
import antlr.RecognitionException;
import antlr.NoViableAltException;
import antlr.SemanticException;
import antlr.ParserSharedInputState;
import antlr.collections.impl.BitSet;
import antlr.collections.AST;
import antlr.ASTFactory;
import antlr.ASTPair;
import antlr.collections.impl.ASTArray;
public class N3AntlrParser extends antlr.LLkParser implements N3AntlrParserTokenTypes
{
// Extra code for the parser.
boolean emitListTypeQuad = false ;
N3AntlrLexer lexer = null ;
void setLexer(N3AntlrLexer _lexer) { lexer = _lexer ; }
// Internallly generated anon id. Avoid clash with _:xxx
private int anonId = 0 ;
private String genAnonId() { return "=:"+(anonId++) ; }
// Forumla zero is the outer context. Avoid clash with other labels.
private int formulaId = 1 ;
private String genFormulaId() { return "{}:"+(formulaId++) ; }
private N3ParserEventHandler handler = null ;
public void setEventHandler(N3ParserEventHandler h) { this.handler = h ; }
private void startDocument()
{
if ( handler == null )
throw new RuntimeException("N3AntlrParser: No sink specified") ;
handler.startDocument() ;
}
private void endDocument() { handler.endDocument() ; }
private void startFormula(String context)
{
handler.startFormula(lexer.getLine(), context) ;
}
private void endFormula(String context)
{
handler.endFormula(lexer.getLine(), context) ;
}
private String currentFormula = null ;
private void emitQuad(AST subj, AST prop, AST obj)
{
handler.quad(lexer.getLine(), subj, prop, obj, currentFormula ) ;
}
private void directive(AST directive, AST arg)
{
handler.directive(lexer.getLine(),
directive, new AST[]{arg},
currentFormula) ;
}
private void directive(AST directive, AST arg1, AST arg2)
{
handler.directive(lexer.getLine(),
directive, new AST[]{arg1, arg2},
currentFormula) ;
}
public void reportError(RecognitionException ex)
{
handler.error(ex, "N3 error: ["+ex.line+":"+ex.column+"] "+ex.getMessage());
}
/** Parser error-reporting function can be overridden in subclass */
public void reportError(String s)
{
//System.err.println("N3AntlrParser(s): "+s);
handler.error(null, "N3AntlrParser(s): ["+lexer.getLine()+":"+lexer.getColumn()+"] "+s) ;
}
protected N3AntlrParser(TokenBuffer tokenBuf, int k) {
super(tokenBuf,k);
tokenNames = _tokenNames;
buildTokenTypeASTClassMap();
astFactory = new ASTFactory(getTokenTypeToASTClassMap());
}
public N3AntlrParser(TokenBuffer tokenBuf) {
this(tokenBuf,1);
}
protected N3AntlrParser(TokenStream lexer, int k) {
super(lexer,k);
tokenNames = _tokenNames;
buildTokenTypeASTClassMap();
astFactory = new ASTFactory(getTokenTypeToASTClassMap());
}
public N3AntlrParser(TokenStream lexer) {
this(lexer,1);
}
public N3AntlrParser(ParserSharedInputState state) {
super(state,1);
tokenNames = _tokenNames;
buildTokenTypeASTClassMap();
astFactory = new ASTFactory(getTokenTypeToASTClassMap());
}
public final void document() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST document_AST = null;
try { // for error handling
if ( inputState.guessing==0 ) {
startDocument() ;
}
{
_loop3:
do {
switch ( LA(1)) {
case AT_PREFIX:
{
n3Directive();
break;
}
case QNAME:
case KW_THIS:
case STRING:
case LBRACK:
case LCURLY:
case LPAREN:
case NUMBER:
case URIREF:
case UVAR:
{
statement();
break;
}
default:
{
break _loop3;
}
}
} while (true);
}
if ( inputState.guessing==0 ) {
endDocument() ;
}
AST tmp1_AST = null;
tmp1_AST = astFactory.create(LT(1));
match(Token.EOF_TYPE);
}
catch (RecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex) ; throw ex ;
} else {
throw ex;
}
}
catch (TokenStreamRecognitionException ex) {
if (inputState.guessing==0) {
reportError(ex.recog) ; throw ex.recog ;
} else {
throw ex;
}
}
returnAST = document_AST;
}
public final void n3Directive() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST n3Directive_AST = null;
n3Directive0();
match(SEP);
returnAST = n3Directive_AST;
}
public final void statement() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST statement_AST = null;
statement0();
match(SEP);
returnAST = statement_AST;
}
public final void n3Directive0() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST n3Directive0_AST = null;
Token d = null;
AST d_AST = null;
AST ns_AST = null;
AST u_AST = null;
d = LT(1);
d_AST = astFactory.create(d);
match(AT_PREFIX);
nsprefix();
ns_AST = (AST)returnAST;
uriref();
u_AST = (AST)returnAST;
if ( inputState.guessing==0 ) {
directive(d_AST, ns_AST, u_AST);
}
returnAST = n3Directive0_AST;
}
public final void nsprefix() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST nsprefix_AST = null;
Token ns = null;
AST ns_AST = null;
try { // for error handling
ns = LT(1);
ns_AST = astFactory.create(ns);
astFactory.addASTChild(currentAST, ns_AST);
match(QNAME);
if (!( ns.getText().endsWith(":") ))
throw new SemanticException(" ns.getText().endsWith(\":\") ");
nsprefix_AST = (AST)currentAST.root;
}
catch (SemanticException ex) {
if (inputState.guessing==0) {
RecognitionException rEx =
new RecognitionException("Illegal prefix: '"+ns.getText()+"'") ;
rEx.line = lexer.getLine() ; rEx.column = lexer.getColumn() ;
throw rEx ;
} else {
throw ex;
}
}
returnAST = nsprefix_AST;
}
public final void uriref() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST uriref_AST = null;
AST tmp4_AST = null;
tmp4_AST = astFactory.create(LT(1));
astFactory.addASTChild(currentAST, tmp4_AST);
match(URIREF);
uriref_AST = (AST)currentAST.root;
returnAST = uriref_AST;
}
public final void statement0() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST statement0_AST = null;
AST subj_AST = null;
subject();
subj_AST = (AST)returnAST;
propertyList(subj_AST);
returnAST = statement0_AST;
}
public final void subject() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST subject_AST = null;
item();
astFactory.addASTChild(currentAST, returnAST);
subject_AST = (AST)currentAST.root;
returnAST = subject_AST;
}
public final void propertyList(
AST subj
) throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST propertyList_AST = null;
switch ( LA(1)) {
case NAME_OP:
{
match(NAME_OP);
anonnode(subj);
propertyList(subj);
break;
}
case QNAME:
case KW_THIS:
case KW_HAS:
case KW_A:
case KW_IS:
case STRING:
case EQUAL:
case ARROW_R:
case ARROW_L:
case ARROW_PATH_L:
case LBRACK:
case LCURLY:
case LPAREN:
case NUMBER:
case URIREF:
case UVAR:
{
propValue(subj);
{
switch ( LA(1)) {
case SEMI:
{
AST tmp6_AST = null;
tmp6_AST = astFactory.create(LT(1));
match(SEMI);
propertyList(subj);
break;
}
case SEP:
case RBRACK:
case RCURLY:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
break;
}
case SEP:
case RBRACK:
case RCURLY:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
returnAST = propertyList_AST;
}
public final void formulaList() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST formulaList_AST = null;
switch ( LA(1)) {
case QNAME:
case KW_THIS:
case AT_PREFIX:
case STRING:
case LBRACK:
case LCURLY:
case LPAREN:
case NUMBER:
case URIREF:
case UVAR:
{
{
switch ( LA(1)) {
case QNAME:
case KW_THIS:
case STRING:
case LBRACK:
case LCURLY:
case LPAREN:
case NUMBER:
case URIREF:
case UVAR:
{
statement0();
break;
}
case AT_PREFIX:
{
n3Directive0();
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
{
switch ( LA(1)) {
case SEP:
{
AST tmp7_AST = null;
tmp7_AST = astFactory.create(LT(1));
match(SEP);
formulaList();
break;
}
case RCURLY:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
}
break;
}
case RCURLY:
{
break;
}
default:
{
throw new NoViableAltException(LT(1), getFilename());
}
}
returnAST = formulaList_AST;
}
public final void item() throws RecognitionException, TokenStreamException {
returnAST = null;
ASTPair currentAST = new ASTPair();
AST item_AST = null;
AST n_AST = null;
AST n1_AST = null;
AST n2_AST = null;
node();
n_AST = (AST)returnAST;
astFactory.addASTChild(currentAST, returnAST);
{
_loop21:
do {
switch ( LA(1)) {
case PATH:
{
match(PATH);
node();
n1_AST = (AST)returnAST;
astFactory.addASTChild(currentAST, returnAST);
if ( inputState.guessing==0 ) {
AST a1 = (AST)astFactory.make( (new ASTArray(1)).add(astFactory.create(ANON,genAnonId()))) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -