KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > n3 > N3Parser


1 /*
2  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package com.hp.hpl.jena.n3;
7
8 import java.io.* ;
9
10 import antlr.TokenStreamException;
11 import com.hp.hpl.jena.util.FileUtils ;
12
13 /** The formal interface to the N3 parser. Wraps up the antlr parser and lexer.
14  * @author Andy Seaborne
15  * @version $Id: N3Parser.java,v 1.7 2005/02/21 12:04:06 andy_seaborne Exp $
16  */

17 public class N3Parser implements N3AntlrParserTokenTypes
18 {
19     N3AntlrLexer lexer = null ;
20     N3AntlrParser parser = null ;
21     
22     public N3Parser(BufferedReader r, N3ParserEventHandler h)
23     {
24         lexer = new N3AntlrLexer(r) ;
25         parser = new N3AntlrParser(lexer) ;
26         parser.setEventHandler(h) ;
27         parser.setLexer(lexer) ;
28     }
29
30     public N3Parser(Reader r, N3ParserEventHandler h)
31     {
32         lexer = new N3AntlrLexer(r) ;
33         parser = new N3AntlrParser(lexer) ;
34         parser.setEventHandler(h) ;
35         parser.setLexer(lexer) ;
36     }
37     
38     public N3Parser(InputStream in, N3ParserEventHandler h)
39     {
40         this(new BufferedReader(FileUtils.asUTF8(in)), h) ;
41     }
42
43     static public String JavaDoc[] getTokenNames() { return N3AntlrParser._tokenNames ; }
44     
45     public int line() { return lexer.getLine() ; }
46     public int col() { return lexer.getColumn() ; }
47     
48     public N3AntlrParser getParser() { return parser ; }
49     public N3AntlrLexer getLexer() { return lexer ; }
50
51     /** Call the top level parser rule */
52     public void parse() throws antlr.RecognitionException, TokenStreamException
53     {
54         parser.document() ;
55     }
56 }
57
58 /*
59  * (c) Copyright 2001, 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
60  * All rights reserved.
61  *
62  * Redistribution and use in source and binary forms, with or without
63  * modification, are permitted provided that the following conditions
64  * are met:
65  * 1. Redistributions of source code must retain the above copyright
66  * notice, this list of conditions and the following disclaimer.
67  * 2. Redistributions in binary form must reproduce the above copyright
68  * notice, this list of conditions and the following disclaimer in the
69  * documentation and/or other materials provided with the distribution.
70  * 3. The name of the author may not be used to endorse or promote products
71  * derived from this software without specific prior written permission.
72  *
73  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
74  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
75  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
76  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
77  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
78  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
79  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
80  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
81  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
82  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
83  */

84
Popular Tags