001 /* Copyright 2000, 2001, Compaq Computer Corporation */ 002 003 package escjava.parser; 004 005 import javafe.parser.PragmaParser; 006 import javafe.parser.Token; 007 008 import javafe.util.Location; 009 import javafe.util.CorrelatedReader; 010 import javafe.util.ErrorSet; 011 012 import java.io.IOException; 013 014 /** 015 * This class produces a {@link PragmaParser} that reports an 016 * client-chosen error message each time an annotation comment is 017 * encountered. (Javadoc comments are also considered annotations.) 018 */ 019 020 public class ErrorPragmaParser implements PragmaParser 021 { 022 /** The error message to report. */ 023 public String msg; 024 025 /** Create a new ErrorPragmaParser that report error message msg. */ 026 public ErrorPragmaParser(String msg) { 027 this.msg = msg; 028 } 029 030 /** We consider both ESC and Javadoc comments to be annotations. */ 031 public boolean checkTag(int tag) { 032 return tag == '@' || tag == '*'; 033 } 034 035 /** Report an error for each annotation comment **/ 036 public void restart(CorrelatedReader in, boolean eolComment) { 037 try { 038 in.read(); 039 } catch (IOException e) { 040 ErrorSet.fatal(in.getLocation(), e.toString()); 041 } 042 043 ErrorSet.error(in.getLocation(), msg); 044 } 045 046 /** Produce no actual pragmas. */ 047 public boolean getNextPragma(Token dst) { return false; } 048 049 /** No work to close us. */ 050 public void close() {} 051 052 public javafe.ast.FieldDecl isPragmaDecl(javafe.parser.Token l) { return null; } 053 054 } // end of class ErrorPragmaParser 055 056 /* 057 * Local Variables: 058 * Mode: Java 059 * fill-column: 85 060 * End: 061 */