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 5.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <!DOCTYPE html>
  2. <!--
  3. Licensed to the Apache Software Foundation (ASF) under one or more
  4. contributor license agreements. See the NOTICE file distributed with
  5. this work for additional information regarding copyright ownership.
  6. The ASF licenses this file to You under the Apache License, Version 2.0
  7. (the "License"); you may not use this file except in compliance with
  8. the License. You may obtain a copy of the License at
  9. https://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to in writing, software
  11. distributed under the License is distributed on an "AS IS" BASIS,
  12. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. limitations under the License.
  15. -->
  16. <html lang="en">
  17. <head>
  18. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  19. <title>ANTLR Task</title>
  20. </head>
  21. <body>
  22. <h2 id="antlr">ANTLR</h2>
  23. <h3>Description</h3>
  24. <p>Invokes the <a href="https://www.antlr.org/" target="_top">ANTLR</a> Translator generator on a
  25. grammar file.</p>
  26. <p>To use the ANTLR task, set the <var>target</var> attribute to the name of the grammar file to
  27. process. Optionally, you can also set the <var>outputdirectory</var> to write the generated file to
  28. a specific directory. Otherwise ANTLR writes the generated files to the directory containing the
  29. grammar file.</p>
  30. <p>This task only invokes ANTLR if the grammar file (or the supergrammar specified by
  31. the <var>glib</var> attribute) is newer than the generated files.</p>
  32. <p><strong>Note</strong>: This task depends on external libraries not included in the Apache Ant
  33. distribution. See <a href="../install.html#librarydependencies">Library Dependencies</a> for more
  34. information.</p>
  35. <p>Antlr 2.7.2 Note: <em>You will need <samp>antlrall.jar</samp> that can be created by
  36. the <q>antlr-all.jar</q> target of the Makefile provided with the download.</em></p>
  37. <h3>Parameters</h3>
  38. <table class="attr">
  39. <tr>
  40. <th scope="col">Attribute</th>
  41. <th scope="col">Description</th>
  42. <th scope="col">Required</th>
  43. </tr>
  44. <tr>
  45. <td>target</td>
  46. <td>The grammar file to process.</td>
  47. <td>Yes</td>
  48. </tr>
  49. <tr>
  50. <td>outputdirectory</td>
  51. <td>The directory to write the generated files to.</td>
  52. <td>No; defaults to the directory containing the grammar file</td>
  53. </tr>
  54. <tr>
  55. <td>glib</td>
  56. <td>An optional super grammar file that the target grammar overrides. This feature is only
  57. needed for advanced vocabularies.</td>
  58. <td>No</td>
  59. </tr>
  60. <tr>
  61. <td>debug</td>
  62. <td>When set to <q>yes</q>, this flag adds code to the generated parser that will launch the
  63. ParseView debugger upon invocation.<br/> Note: ParseView is a separate component that needs
  64. to be installed or your grammar will have compilation errors.</td>
  65. <td>No; default is <q>no</q></td>
  66. </tr>
  67. <tr>
  68. <td>html</td>
  69. <td>Emit an HTML version of the grammar with hyperlinked actions if set to <q>yes</q>.</td>
  70. <td>No; default is <q>no</q></td>
  71. </tr>
  72. <tr>
  73. <td>diagnostic</td>
  74. <td>Generate a text file with debugging information based on the target grammar if set
  75. to <q>yes</q>.</td>
  76. <td>No; default is <q>no</q></td>
  77. </tr>
  78. <tr>
  79. <td>trace</td>
  80. <td>Force <strong>all</strong> rules to call traceIn/traceOut if set to <q>yes</q>.</td>
  81. <td>No; default is <q>no</q></td>
  82. </tr>
  83. <tr>
  84. <td>traceParser</td>
  85. <td>Only force parser rules to call traceIn/traceOut if set to <q>yes</q>.</td>
  86. <td>No; default is <q>no</q></td>
  87. </tr>
  88. <tr>
  89. <td>traceLexer</td>
  90. <td>Only force lexer rules to call traceIn/traceOut if set to <q>yes</q>.</td>
  91. <td>No; default is <q>no</q></td>
  92. </tr>
  93. <tr>
  94. <td>traceTreeWalker</td>
  95. <td>Only force tree walker rules to call traceIn/traceOut if set to <q>yes</q>.</td>
  96. <td>No; default is <q>no</q></td>
  97. </tr>
  98. <!--tr>
  99. <td>fork</td>
  100. <td>Run ANTLR in a separate JVM.</td>
  101. <td>No; default is <q>off</q></td>
  102. </tr-->
  103. <tr>
  104. <td>dir</td>
  105. <td>The directory to invoke JVM in.<!--(ignored if fork is disabled)--></td>
  106. <td>No</td>
  107. </tr>
  108. </table>
  109. <h3 id="nested">Parameters specified as nested elements</h3>
  110. <p>The task supports a nested <code>&lt;classpath&gt;</code> element, that represents
  111. a <a href="../using.html#path">path-like structure</a>. It is given as a convenience if you have to
  112. specify the original ANTLR directory. In most cases, dropping the appropriate ANTLR jar in the
  113. normal Ant lib repository will be enough.</p>
  114. <h4>jvmarg</h4>
  115. <p><!--If fork is enabled, -->Additional parameters may be passed to the new JVM via
  116. nested <code>&lt;jvmarg&gt;</code> attributes, for example:</p>
  117. <pre>
  118. &lt;antlr target="..."&gt;
  119. &lt;jvmarg value=&quot;-Djava.compiler=NONE&quot;/&gt;
  120. ...
  121. &lt;/antlr&gt;</pre>
  122. <p>would run ANTLR in a JVM without JIT.</p>
  123. <p><code>&lt;jvmarg&gt;</code> allows all attributes described
  124. in <a href="../using.html#arg">Command line arguments</a>.</p>
  125. <h3>Example</h3>
  126. <p>Invoke ANTLR on grammar file <samp>etc/java.g</samp>, writing the generated files
  127. to <samp>build/src</samp>:</p>
  128. <pre>
  129. &lt;antlr
  130. target=&quot;etc/java.g&quot;
  131. outputdirectory=&quot;build/src&quot;/&gt;</pre>
  132. </body>
  133. </html>