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.VisualBasicParserGenerator; 31 32 40 public class VisualBasicElement 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 VisualBasicElement() { 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 <visualbasic> element"); 117 } 118 } 119 120 128 public void process(Grammar grammar) throws BuildException { 129 VisualBasicParserGenerator gen; 130 131 gen = new VisualBasicParserGenerator(grammar); 132 gen.setBaseDir(dir); 133 if (namespace != null) { 134 gen.setNamespace(namespace); 135 } 136 if (prefix != null) { 137 gen.setBaseName(prefix); 138 } 139 gen.setPublicAccess(publicAccess); 140 try { 141 System.out.println("Writing Visual Basic parser source code..."); 142 gen.write(); 143 System.out.println("Done."); 144 } catch (IOException e) { 145 throw new BuildException(e); 146 } 147 } 148 } 149 | Popular Tags |