1 18 19 package org.objectweb.jac.core.parsers.acc; 20 21 import java.io.Reader ; 22 import java.util.Collection ; 23 import java.util.HashSet ; 24 import java.util.Set ; 25 import java.util.Vector ; 26 import java_cup.runtime.Symbol; 27 import org.apache.log4j.Logger; 28 import org.objectweb.jac.core.parsers.acc.ToolParser; 29 30 public class ToolParserWrapper extends ToolParser 31 { 32 static Logger logger = Logger.getLogger("acc.parser"); 33 34 public ToolParserWrapper() { 35 this.blockKeywords = new HashSet (); 36 } 37 38 public ToolParserWrapper(Set blockKeywords) { 39 this.blockKeywords = blockKeywords; 40 } 41 42 Set blockKeywords; 43 public void addBlockKeywords(Collection keywords) { 44 blockKeywords.addAll(blockKeywords); 45 } 46 public void setBlockKeywords(Set keywords) { 47 blockKeywords.addAll(keywords); 48 } 49 50 56 public NonTerminal parse(Reader input, String streamName) 57 { 58 AccScanner lexer = new AccScanner(input,streamName, blockKeywords); 59 setScanner(lexer); 60 logger.debug("Parsing "+streamName+" keywords="+blockKeywords+"..."); 62 Vector methods = null; 63 try { 64 syntaxElements = (NonTerminal)parse().value; 65 logger.debug(streamName+" parsed"); 67 } catch (Exception e) { 68 logger.warn("Parser error in "+streamName+" : "+e); 70 } 72 return syntaxElements; 73 } 74 75 NonTerminal syntaxElements; 76 public NonTerminal getSyntaxElements() { 77 return syntaxElements; 78 } 79 80 public void report_error(String message, Object info) { 81 logger.debug(message+" at character "+((Symbol)info).left+ 82 "("+((AccScanner)getScanner()).getLine()+")"); 83 } 84 85 89 public Terminal getTerminalAt(int position) { 90 if (syntaxElements!=null) 91 return syntaxElements.getTerminalAt(position); 92 else 93 return null; 94 } 95 96 100 public SyntaxElement getSyntaxElementAt(int position) { 101 if (syntaxElements!=null) 102 return syntaxElements.getSyntaxElementAt(position); 103 else 104 return null; 105 } 106 107 113 public SyntaxElement getSyntaxElementAt(int position, String name) { 114 if (syntaxElements!=null) { 115 SyntaxElement element = syntaxElements.getSyntaxElementAt(position); 116 if (element!=null) 117 return element.findParent(name); 118 else 119 return null; 120 } else 121 return null; 122 } 123 } 124 | Popular Tags |