A comment is text the type checker and the interpreter skip. // starts a line comment, which runs to the end of its line, and /* */ encloses a block comment. A run of line comments right above a top-level declaration is its doc comment, and //! lines document the whole module; ant doc and editors show them.
Block comments do not nest: a block comment ends at the first */.
// and /* inside a string literal are part of the string, not a comment.
A doc comment is a run of // lines, each alone on its line, directly above a top-level var, let, func, or type, or the export before one. A blank line, a block comment, a //! line, or a comment after code ends the run.
//! lines come before the first import or declaration, on consecutive lines. Other comments, such as a license, may come before or after them, but not between.
A file's first line may start with #!, so a script runs as a command. #! anywhere else is a syntax error.
A comment at the end of a line does not change where the expression ends. A line that ends with an operator continues onto the next line, comment or not:
//! lines document the module. Here a license comment comes first and a blank line separates it, so it documents nothing. // Distances is followed by a blank line, so it labels a section of the file instead of documenting distance. In a doc comment, an empty // line separates paragraphs, lines indented past the comment's own space are code, and a name in brackets, such as [Point], names a declaration that an editor may turn into a link:
ant
// Copyright 2026 The Ant Authors. MIT license.//! Geometry computes distances on the plane.//!//! Build a [Point] and pass two of them to [distance].// Point is a position on the plane.export type Point = { x: float64, y: float64 }// Distances// distance returns the straight-line distance from a to b.//// distance(Point{ x: 0.0, y: 0.0 }, Point{ x: 3.0, y: 4.0 }) // 5.0export func distance(a: Point, b: Point): float64 { Math.sqrt(square(a.x - b.x) + square(a.y - b.y))}func square(n: float64): float64 { n * n}
For a module, ant doc prints the module doc and the signature of each exported declaration:
text
Geometry computes distances on the plane. Build a [Point] and pass two of them to [distance].type Point = { x: float64, y: float64 }func distance(a: Point, b: Point): float64
A blank line between a comment and a declaration ends the run, so the comment documents nothing and ant doc prints only the signature:
ant
// area returns the area of a w by h rectangle.export func area(w: float64, h: float64): float64 { w * h}
text
func area(w: float64, h: float64): float64
A //! line after the first declaration, or after code on its line, is a syntax error. Put the module doc at the top of the file:
ant
let limit = 3 //! Limits caps retries.// error: a //! module doc line must come before the first import or declarationprintln(limit)
An HTML comment, <!-- -->, is a syntax error in markup. Write {/* ... */} instead:
ant
let page = <p><!-- note -->Hi</p> // error: an HTML comment is written {/* ... */} in markup
// always starts a comment, so an empty regular expression cannot be a literal, and neither can a pattern that starts with *. Write the empty pattern with Regex.compile(""):
ant
Regex.compile("") // Ok{ value: /(?:)/ }
#! works only from the first byte of the file. On any later line it is an error:
ant
println("start")#!/usr/bin/env ant // error: unexpected character '#'
Comments and doc comments
A comment is text the type checker and the interpreter skip.
//starts a line comment, which runs to the end of its line, and/* */encloses a block comment. A run of line comments right above a top-level declaration is its doc comment, and//!lines document the whole module;ant docand editors show them.Details
*/.//and/*inside a string literal are part of the string, not a comment.//lines, each alone on its line, directly above a top-levelvar,let,func, ortype, or theexportbefore one. A blank line, a block comment, a//!line, or a comment after code ends the run.//!lines come before the firstimportor declaration, on consecutive lines. Other comments, such as a license, may come before or after them, but not between.#!, so a script runs as a command.#!anywhere else is a syntax error.Basic examples
A line comment runs to the end of its line. It can stand alone or follow code:
A block comment can sit inside an expression or span several lines:
A doc comment is the run of line comments right above a top-level declaration.
ant docprints it under the declaration's signature:Scope
Comments between values
A block comment can sit between the parts of an expression, such as to label one argument of a call:
Comments at line ends
A comment at the end of a line does not change where the expression ends. A line that ends with an operator continues onto the next line, comment or not:
Comments in markup
Inside markup, a comment is a block comment in braces,
{/* ... */}. It renders nothing:Strings
//and/*in a string literal are characters of the string:Commenting out code
A block comment turns off several lines at once, as long as they hold no
*/:Module docs and section labels
//!lines document the module. Here a license comment comes first and a blank line separates it, so it documents nothing.// Distancesis followed by a blank line, so it labels a section of the file instead of documentingdistance. In a doc comment, an empty//line separates paragraphs, lines indented past the comment's own space are code, and a name in brackets, such as[Point], names a declaration that an editor may turn into a link:For a module,
ant docprints the module doc and the signature of each exported declaration:Scripts
A script starts with
#!on its first line so that it runs as a command. Its//!lines say what the program does and how to run it:Possible issues
Block comments do not nest. The first
*/closes the comment, and the rest of the line is read as code:So a block comment cannot turn off code that already holds one. Use line comments for that:
A block comment needs its
*/. Without one, it runs to the end of the file:A blank line between a comment and a declaration ends the run, so the comment documents nothing and
ant docprints only the signature:A
//!line after the first declaration, or after code on its line, is a syntax error. Put the module doc at the top of the file:An HTML comment,
<!-- -->, is a syntax error in markup. Write{/* ... */}instead://always starts a comment, so an empty regular expression cannot be a literal, and neither can a pattern that starts with*. Write the empty pattern withRegex.compile(""):#!works only from the first byte of the file. On any later line it is an error:See also
ant doc, Writing docs, Identifiers, Line endings, Keywords and reserved words,export,ant run