blob: 322f19db97d25abf4494a136672f47ad29a8b686 [file] [log] [blame]
<!DOCTYPE html>
<html>
<!-- Created by Texinfo 6.8dev+dev, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- This manual is for GNU Texinfo (version 6.8dev, 23 February 2022),
a documentation system that can produce both online information and a
printed manual from a single source using semantic markup.
Copyright (C) 1988, 1990-1993, 1995-1999, 2001-2022 Free Software Foundation, Inc.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the section entitled
"GNU Free Documentation License". -->
<title>#line Syntax Details (GNU Texinfo 6.8dev)</title>
<meta name="description" content="#line Syntax Details (GNU Texinfo 6.8dev)">
<meta name="keywords" content="#line Syntax Details (GNU Texinfo 6.8dev)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="texi2any">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link href="index.html" rel="start" title="Top">
<link href="Command-and-Variable-Index.html" rel="index" title="Command and Variable Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="External-Macro-Processors.html" rel="up" title="External Macro Processors">
<link href="_0023line-and-TeX.html" rel="prev" title="#line and TeX">
<style type="text/css">
<!--
div.example {margin-left: 3.2em}
-->
</style>
</head>
<body lang="en">
<div class="subsection-level-extent" id="g_t_0023line-Syntax-Details">
<div class="nav-panel">
<p>
Previous: <a href="_0023line-and-TeX.html" accesskey="p" rel="prev">&lsquo;<samp class="samp">#line</samp>&rsquo; and TeX</a>, Up: <a href="External-Macro-Processors.html" accesskey="u" rel="up">External Macro Processors: Line Directives</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Command-and-Variable-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="g_t_0023line-Syntax-Details-1">16.6.3 &lsquo;<samp class="samp">#line</samp>&rsquo; Syntax Details</h4>
<a class="index-entry-id" id="index-_0023line-directive-2"></a>
<a class="index-entry-id" id="index-Syntax-details_002c-_0023line"></a>
<a class="index-entry-id" id="index-Regular-expression_002c-for-_0023line"></a>
<p>Syntax details for the &lsquo;<samp class="samp">#line</samp>&rsquo; directive: the &lsquo;<samp class="samp">#</samp>&rsquo; character
can be preceded or followed by whitespace, the word &lsquo;<samp class="samp">line</samp>&rsquo; is
optional, and the file name can be followed by a whitespace-separated
list of integers (these are so-called &ldquo;flags&rdquo; output by CPP in some
cases). For those who like to know the gory details, the actual
(Perl) regular expression which is matched is this:
</p>
<div class="example">
<pre class="example-preformatted">/^\s*#\s*(line)? (\d+)(( &quot;([^&quot;]+)&quot;)(\s+\d+)*)?\s*$/
</pre></div>
<p>As far as we&rsquo;ve been able to tell, the trailing integer flags only
occur in conjunction with a file name, so that is reflected in the
regular expression.
</p>
<p>As an example, the following is a syntactically valid &lsquo;<samp class="samp">#line</samp>&rsquo;
directive, meaning line 1 of <samp class="file">/usr/include/stdio.h</samp>:
</p>
<div class="example">
<pre class="example-preformatted"># 1 &quot;/usr/include/stdio.h&quot; 2 3 4
</pre></div>
<p>Unfortunately, the quoted file name (&lsquo;<samp class="samp">&quot;...&quot;</samp>&rsquo;) has to be optional,
because M4 (especially) can often generate &lsquo;<samp class="samp">#line</samp>&rsquo; directives
within a single file. Since the &lsquo;<samp class="samp">line</samp>&rsquo; is also optional, the
result is that lines might match which you wouldn&rsquo;t expect, e.g.,
</p>
<div class="example">
<pre class="example-preformatted"># 1
</pre></div>
<p>The possible solutions are described above (see <a class="pxref" href="_0023line-Directive.html">&lsquo;<samp class="samp">#line</samp>&rsquo; Directive</a>).
</p>
</div>
</body>
</html>