1 21 22 package net.percederberg.grammatica.output; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 27 import net.percederberg.grammatica.Grammar; 28 29 35 public abstract class ParserGenerator { 36 37 40 protected static final String FILE_COMMENT = 41 "THIS FILE HAS BEEN GENERATED AUTOMATICALLY. DO NOT EDIT!"; 42 43 46 private Grammar grammar; 47 48 51 private File baseDir = null; 52 53 56 private String fileComment = null; 57 58 63 protected ParserGenerator(Grammar grammar) { 64 this.grammar = grammar; 65 initialize(); 66 } 67 68 71 private void initialize() { 72 StringBuffer buffer; 73 String str; 74 int pos; 75 76 buffer = new StringBuffer (); 78 buffer.append(FILE_COMMENT); 79 str = grammar.getDeclaration(Grammar.LICENSE_DECLARATION); 80 if (str != null) { 81 buffer.append("\n\n"); 82 pos = str.indexOf('\n'); 83 while (pos >= 0) { 84 buffer.append(str.substring(0, pos).trim()); 85 buffer.append('\n'); 86 str = str.substring(pos + 1); 87 pos = str.indexOf('\n'); 88 } 89 buffer.append(str.trim()); 90 } 91 str = grammar.getDeclaration(Grammar.COPYRIGHT_DECLARATION); 92 if (str != null) { 93 buffer.append("\n\n"); 94 buffer.append(str); 95 } 96 fileComment = buffer.toString(); 97 } 98 99 104 public Grammar getGrammar() { 105 return grammar; 106 } 107 108 113 public File getBaseDir() { 114 return baseDir; 115 } 116 117 122 public void setBaseDir(File dir) { 123 this.baseDir = dir; 124 } 125 126 131 public String getFileComment() { 132 return fileComment; 133 } 134 135 140 public abstract void write() throws IOException ; 141 } 142 | Popular Tags |