001    /*
002      Copyright (C) 2001-2002 Laurent Martelli <laurent@aopsys.com>
003    
004      This program is free software; you can redistribute it and/or modify
005      it under the terms of the GNU Lesser General Public License as
006      published by the Free Software Foundation; either version 2 of the
007      License, or (at your option) any later version.
008    
009      This program is distributed in the hope that it will be useful,
010      but WITHOUT ANY WARRANTY; without even the implied warranty of
011      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012      GNU Lesser General Public License for more details.
013    
014      You should have received a copy of the GNU Lesser General Public
015      License along with this program; if not, write to the Free Software
016      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
017      USA */
018    
019    package org.objectweb.jac.core.parsers.acc;
020    
021    import java.io.FileReader;
022    import java.io.InputStream;
023    import java.io.InputStreamReader;
024    import java.util.HashSet;
025    import java.util.List;
026    import java.util.Set;
027    import java.util.Vector;
028    import java_cup.runtime.Symbol;
029    import org.apache.log4j.Logger;
030    import org.objectweb.jac.core.InputStreamParser;
031    
032    public class AccParserWrapper implements InputStreamParser 
033    {
034        static Logger logger = Logger.getLogger("acc.parser");
035    
036        public AccParserWrapper() {
037        }
038    
039        public List parse(InputStream inputStream, String streamName, 
040                          String targetClass, Set blockKeywords) 
041        {
042            AccScanner lexer = new AccScanner(new InputStreamReader(inputStream), 
043                                              streamName, blockKeywords);
044            AccParser parser = new AccParser(lexer);
045            // Parse the input expression
046            logger.debug("Parsing "+streamName+" ...");
047            Vector methods = null;
048            try {
049                methods = (Vector)parser.parse().value;
050                //          System.out.println(methods);
051            } catch (Exception e) {
052                lexer.printState();
053                logger.error("Parser error in "+streamName,e);
054            }
055            logger.debug(streamName+" parsed");
056            return methods;
057        }
058        /*
059        public void report_error(String message, Object info) {
060            logger.debug(message+" at character "+((Symbol)info).left+
061                         "("+((AccScanner)getScanner()).getLine()+")");
062        }   
063        */
064        /**
065         * Parse a file. 
066         * @param args arg[0] is the path of the file to parse
067         */
068        public static void main(String[] args) 
069        {
070            AccScanner scanner = null;
071            try {
072                scanner = new AccScanner(new FileReader(args[0]),args[0],
073                                         new HashSet());
074                AccParser myParser = new AccParser(scanner);
075                Vector methods = (Vector)myParser.parse().value;
076                System.out.println("Methods = "+methods);
077            } catch (Exception e) {
078                if (scanner!=null)
079                    System.err.println(args[0]+":"+scanner.getLine());
080                e.printStackTrace();
081            }
082        }
083    }