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