KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > parsers > acc > AccParserWrapper


1 /*
2   Copyright (C) 2001-2002 Laurent Martelli <laurent@aopsys.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   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
12   GNU 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 program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.core.parsers.acc;
20
21 import java.io.FileReader JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.io.InputStreamReader JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.Vector JavaDoc;
28 import java_cup.runtime.Symbol;
29 import org.apache.log4j.Logger;
30 import org.objectweb.jac.core.InputStreamParser;
31
32 public class AccParserWrapper implements InputStreamParser
33 {
34     static Logger logger = Logger.getLogger("acc.parser");
35
36     public AccParserWrapper() {
37     }
38
39     public List JavaDoc parse(InputStream JavaDoc inputStream, String JavaDoc streamName,
40                       String JavaDoc targetClass, Set JavaDoc blockKeywords)
41     {
42         AccScanner lexer = new AccScanner(new InputStreamReader JavaDoc(inputStream),
43                                           streamName, blockKeywords);
44         AccParser parser = new AccParser(lexer);
45         // Parse the input expression
46
logger.debug("Parsing "+streamName+" ...");
47         Vector JavaDoc methods = null;
48         try {
49             methods = (Vector JavaDoc)parser.parse().value;
50             // System.out.println(methods);
51
} catch (Exception JavaDoc e) {
52             lexer.printState();
53             logger.error("Parser error in "+streamName,e);
54         }
55         logger.debug(streamName+" parsed");
56         return methods;
57     }
58     /*
59     public void report_error(String message, Object info) {
60         logger.debug(message+" at character "+((Symbol)info).left+
61                      "("+((AccScanner)getScanner()).getLine()+")");
62     }
63     */

64     /**
65      * Parse a file.
66      * @param args arg[0] is the path of the file to parse
67      */

68     public static void main(String JavaDoc[] args)
69     {
70         AccScanner scanner = null;
71         try {
72             scanner = new AccScanner(new FileReader JavaDoc(args[0]),args[0],
73                                      new HashSet JavaDoc());
74             AccParser myParser = new AccParser(scanner);
75             Vector JavaDoc methods = (Vector JavaDoc)myParser.parse().value;
76             System.out.println("Methods = "+methods);
77         } catch (Exception JavaDoc e) {
78             if (scanner!=null)
79                 System.err.println(args[0]+":"+scanner.getLine());
80             e.printStackTrace();
81         }
82     }
83 }
84
Popular Tags