01: /*=============================================================================
02: * Copyright Texas Instruments 2000. All Rights Reserved.
03: *
04: * This program is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2 of the License, or (at your option) any later version.
08: *
09: * This program is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: * $ProjectHeader: OSCRIPT 0.155 Fri, 20 Dec 2002 18:34:22 -0800 rclark $
19: */
20:
21: package oscript;
22:
23: import java.io.*;
24:
25: import oscript.syntaxtree.Node;
26: import oscript.parser.*;
27:
28: /* XXX TODO: move this, and oscript.OscriptParser, etc. to oscript.parser
29: * package.
30: */
31:
32: /**
33: *
34: * @author Rob Clark (rob@ti.com)
35: * <!--$Format: " * @version $Revision$"$-->
36: * @version 1.3.1.4
37: */
38: public class DefaultParser implements Parser {
39: static OscriptParser parser = new OscriptParser(
40: new StringReader(""), "bogus");
41:
42: /**
43: * Get the file extension for file type to handle, eg. <code>os</code>. This
44: * is used to determine which parser to use for which file to parse.
45: *
46: * @return the file extension
47: */
48: public String getExtension() {
49: return "os";
50: }
51:
52: /**
53: * Convert a file to Node.
54: *
55: * @param file the file to parse
56: * @return the parsed syntaxtree
57: */
58: public Node parse(oscript.fs.AbstractFile file)
59: throws ParseException, IOException {
60: // we want to annotate the error msg with the name of the file being
61: // parsed:
62: Reader r = new InputStreamReader(file.getInputStream());
63: try {
64: return parse(r, file.getPath());
65: } catch (TokenMgrError e) {
66: throw new ParseException("Error parsing '" + file.getPath()
67: + "', " + e.getMessage());
68: } catch (ParseException e) {
69: throw new ParseException("Error parsing '" + file.getPath()
70: + "', " + e.getMessage());
71: } finally {
72: r.close();
73: }
74: }
75:
76: // we don't want multiple isntances of the parser, so we share it by
77: // providing this method as a way to access the parser.
78: public synchronized static Node parse(Reader in, String desc)
79: throws ParseException, IOException {
80: synchronized (parser) {
81: parser.ReInit(new BufferedReader(in), desc);
82: return parser.ProgramFile();
83: }
84: }
85: }
86:
87: /*
88: * Local Variables:
89: * tab-width: 2
90: * indent-tabs-mode: nil
91: * mode: java
92: * c-indentation-style: java
93: * c-basic-offset: 2
94: * eval: (c-set-offset 'substatement-open '0)
95: * eval: (c-set-offset 'case-label '+)
96: * eval: (c-set-offset 'inclass '+)
97: * eval: (c-set-offset 'inline-open '0)
98: * End:
99: */
|