1 21 22 package net.percederberg.grammatica.ant; 23 24 import java.io.File ; 25 import java.io.IOException ; 26 27 import org.apache.tools.ant.BuildException; 28 29 import net.percederberg.grammatica.Grammar; 30 import net.percederberg.grammatica.output.CSharpParserGenerator; 31 32 40 public class CSharpElement implements ProcessingElement { 41 42 45 private File dir = null; 46 47 50 private String namespace = null; 51 52 55 private String prefix = null; 56 57 60 private boolean publicAccess = false; 61 62 65 public CSharpElement() { 66 } 67 68 73 public void setDir(File dir) { 74 this.dir = dir; 75 } 76 77 83 public void setNamespace(String namespace) { 84 this.namespace = namespace; 85 } 86 87 93 public void setPrefix(String prefix) { 94 this.prefix = prefix; 95 } 96 97 103 public void setPublic(boolean publicAccess) { 104 this.publicAccess = publicAccess; 105 } 106 107 113 public void validate() throws BuildException { 114 if (dir == null) { 115 throw new BuildException( 116 "missing 'dir' attribute in <csharp> element"); 117 } 118 } 119 120 128 public void process(Grammar grammar) throws BuildException { 129 CSharpParserGenerator gen = new CSharpParserGenerator(grammar); 130 131 gen.setBaseDir(dir); 132 if (namespace != null) { 133 gen.setNamespace(namespace); 134 } 135 if (prefix != null) { 136 gen.setBaseName(prefix); 137 } 138 gen.setPublicAccess(publicAccess); 139 try { 140 System.out.println("Writing C# parser source code..."); 141 gen.write(); 142 System.out.println("Done."); 143 } catch (IOException e) { 144 throw new BuildException(e); 145 } 146 } 147 } 148 | Popular Tags |