You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

antlr.html 6.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <html>
  16. <head>
  17. <meta http-equiv="Content-Language" content="en-us">
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>ANTLR Task</title>
  20. </head>
  21. <body>
  22. <h2><a name="antlr">ANTLR</a></h2>
  23. <h3>Description</h3>
  24. <p>
  25. Invokes the <a HREF="http://www.antlr.org/" target="_top">ANTLR</a> Translator generator
  26. on a grammar file.
  27. </p>
  28. <p>
  29. To use the ANTLR task, set the <i>target</i> attribute to the name of the
  30. grammar file to process. Optionally, you can also set the
  31. <i>outputdirectory</i> to write the generated file to a specific directory.
  32. Otherwise ANTLR writes the generated files to the directory containing
  33. the grammar file.
  34. </p>
  35. <p>
  36. This task only invokes ANTLR if the grammar file (or the
  37. supergrammar specified by the glib attribute) is newer than the
  38. generated files.
  39. </p>
  40. <p>Antlr 2.7.1 Note:
  41. <i>
  42. To successfully run ANTLR, your best option is probably to build the whole
  43. jar with the provided script <b>mkalljar</b> and drop the resulting jar (about 300KB)
  44. into ${ant.home}/lib. Dropping the default jar (70KB) is probably not enough
  45. for most needs and your only option will be to add ANTLR home directory
  46. to your classpath as described in ANTLR <tt>install.html</tt> document.
  47. </i>
  48. </p>
  49. <p>Antlr 2.7.2 Note:
  50. <i>
  51. Instead of the above, you will need antlrall.jar that can be created
  52. by the <b>antlr-all.jar</b> target of the Makefile provided with the
  53. download.
  54. </i>
  55. </p>
  56. <h3>Parameters</h3>
  57. <table border="1" cellpadding="2" cellspacing="0">
  58. <tr>
  59. <td valign="top"><b>Attribute</b></td>
  60. <td valign="top"><b>Description</b></td>
  61. <td align="center" valign="top"><b>Required</b></td>
  62. </tr>
  63. <tr>
  64. <td valign="top">target</td>
  65. <td valign="top">The grammar file to process.</td>
  66. <td valign="top" align="center">Yes</td>
  67. </tr>
  68. <tr>
  69. <td valign="top">outputdirectory</td>
  70. <td valign="top">
  71. The directory to write the generated files to. If not set, the files
  72. are written to the directory containing the grammar file.
  73. </td>
  74. <td valign="top" align="center">No</td>
  75. </tr>
  76. <tr>
  77. <td valign="top">glib</td>
  78. <td valign="top">
  79. An optional super grammar file that the target grammar overrides. This
  80. feature is only needed for advanced vocabularies.
  81. </td>
  82. <td valign="top" align="center">No</td>
  83. </tr>
  84. <tr>
  85. <td valign="top">debug</td>
  86. <td valign="top">
  87. When set to "yes", this flag adds code to the generated parser that will
  88. launch the ParseView debugger upon invocation. The default is "no".
  89. <br>
  90. Note: ParseView is a separate component that needs to be installed or your
  91. grammar will have compilation errors.
  92. </td>
  93. <td valign="top" align="center">No</td>
  94. </tr>
  95. <tr>
  96. <td valign="top">html</td>
  97. <td valign="top">
  98. Emit an html version of the grammar with hyperlinked actions.
  99. </td>
  100. <td valign="top" align="center">No</td>
  101. </tr>
  102. <tr>
  103. <td valign="top">diagnostic</td>
  104. <td valign="top">
  105. Generates a text file with debugging information based on the target grammar.
  106. </td>
  107. <td valign="top" align="center">No</td>
  108. </tr>
  109. <tr>
  110. <td valign="top">trace</td>
  111. <td valign="top">
  112. Forces <b>all</b> rules to call traceIn/traceOut if set to "yes".
  113. The default is "no".
  114. </td>
  115. <td valign="top" align="center">No</td>
  116. </tr>
  117. <tr>
  118. <td valign="top">traceParser</td>
  119. <td valign="top">
  120. Only forces parser rules to call traceIn/traceOut if set to "yes".
  121. The default is "no".
  122. </td>
  123. <td valign="top" align="center">No</td>
  124. </tr>
  125. <tr>
  126. <td valign="top">traceLexer</td>
  127. <td valign="top">
  128. Only forces lexer rules to call traceIn/traceOut if set to "yes".
  129. The default is "no".
  130. </td>
  131. <td valign="top" align="center">No</td>
  132. </tr>
  133. <tr>
  134. <td valign="top">traceTreeWalker</td>
  135. <td valign="top">
  136. Only forces tree walker rules to call traceIn/traceOut if set to
  137. "yes". The default is "no".
  138. </td>
  139. <td valign="top" align="center">No</td>
  140. </tr>
  141. <!--tr>
  142. <td valign="top">fork</td>
  143. <td valign="top">Run ANTLR in a separate VM.</td>
  144. <td align="center" valign="top">No, default is &quot;off&quot;</td>
  145. </tr-->
  146. <tr>
  147. <td valign="top">dir</td>
  148. <td valign="top">The directory to invoke the VM in. <!--(ignored if
  149. fork is disabled)--></td>
  150. <td align="center" valign="top">No</td>
  151. </tr>
  152. </table>
  153. <h3><a name="nested">Nested Elements</a></h3>
  154. <p><code>ANTLR</code> supports a nested <code>&lt;classpath&gt;</code>
  155. element, that represents a <a href="../using.html#path">PATH like
  156. structure</a>. It is given as a convenience if you have to specify
  157. the original ANTLR directory. In most cases, dropping the appropriate
  158. ANTLR jar in the normal Ant lib repository will be enough.</p>
  159. <h4>jvmarg</h4>
  160. <p><!--If fork is enabled, -->Additional parameters may be passed to the new
  161. VM via nested <code>&lt;jvmarg&gt;</code> attributes, for example:</p>
  162. <pre>
  163. &lt;antlr target="..."&gt;
  164. &lt;jvmarg value=&quot;-Djava.compiler=NONE&quot;/&gt;
  165. ...
  166. &lt;/antlr&gt;
  167. </pre>
  168. <p>would run ANTLR in a VM without JIT.</p>
  169. <p><code>&lt;jvmarg&gt;</code> allows all attributes described in <a
  170. href="../using.html#arg">Command line arguments</a>.</p>
  171. <h3>Example</h3>
  172. <blockquote><pre>
  173. &lt;antlr
  174. target=&quot;etc/java.g&quot;
  175. outputdirectory=&quot;build/src&quot;
  176. /&gt;
  177. </pre></blockquote>
  178. <p>
  179. This invokes ANTLR on grammar file etc/java.g, writing the generated
  180. files to build/src.
  181. </p>
  182. </body>
  183. </html>