inweb-bootstrap/docs/inweb/M-tid.html
2020-03-23 15:04:43 +00:00

144 lines
5.9 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>M/htwaw</title>
<meta name="viewport" content="width=device-width initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Language" content="en-gb">
<link href="../inweb.css" rel="stylesheet" rev="stylesheet" type="text/css">
</head>
<body>
<nav role="navigation">
<h1><a href="../webs.html">Sources</a></h1>
<ul>
<li><a href="../inweb/index.html">inweb</a></li>
</ul>
<h2>Foundation</h2>
<ul>
<li><a href="../foundation-module/index.html">foundation-module</a></li>
<li><a href="../foundation-test/index.html">foundation-test</a></li>
</ul>
</nav>
<main role="main">
<!--Weave of 'M/tid' generated by 7-->
<ul class="crumbs"><li><a href="../webs.html">Source</a></li><li><a href="index.html">inweb</a></li><li><a href="index.html#M">Manual</a></li><li><b>The InC Dialect</b></li></ul><p class="purpose">A modest extension of C used by the Inform project.</p>
<ul class="toc"><li><a href="#SP1">&#167;1. The InC language</a></li></ul><hr class="tocbar">
<p class="inwebparagraph"><a id="SP1"></a><b>&#167;1. The InC language. </b>InC is only a little extended from regular C. All of the Inform tools are
written in InC, as is the <code class="display"><span class="extract">foundation</span></code> module of utility routines built in
to Inweb. It's probably not sensible to use InC in a web which does not
import <code class="display"><span class="extract">foundation</span></code>, and it's certainly not possible to import <code class="display"><span class="extract">foundation</span></code>
on a web not written in InC. So the two go together.
</p>
<p class="inwebparagraph"><a id="SP2"></a><b>&#167;2. </b>Though this is really a feature of Inweb rather than InC, and is also
true of regular C webs, functions, definitions and typedef structs need not
be declared before use. In this way, the need for header files can be
avoided altogether.
</p>
<p class="inwebparagraph"><a id="SP3"></a><b>&#167;3. </b>Each section of an InC web can, optionally, begin:
</p>
<p class="inwebparagraph"></p>
<pre class="display">
<span class="plain">[Namespace::] The Title of This Section.</span>
</pre>
<p class="inwebparagraph">rather than, as normal,
</p>
<p class="inwebparagraph"></p>
<pre class="display">
<span class="plain">The Title of This Section.</span>
</pre>
<p class="inwebparagraph">That declares that all functions in this section must be have a name which
begins with <code class="display"><span class="extract">Namespace::</span></code>. For example,
</p>
<p class="inwebparagraph"></p>
<pre class="display">
<span class="plain">int Namespace::initialise(void) {</span>
<span class="plain"> ....</span>
<span class="plain">}</span>
</pre>
<p class="inwebparagraph">Inweb will not allow a function with the wrong namespace (or with none) to
be declared in the section. This rudimentary feature enables the different
sections of the web to behave like packages or modules in languages which
support rather more compartmentalisation than standard C.
</p>
<p class="inwebparagraph">The tangler converts these identifiers to regular C identifiers by converting
the <code class="display"><span class="extract">::</span></code> to <code class="display"><span class="extract">__</span></code>, so in a debugger, the above function would look like
<code class="display"><span class="extract">Namespace__initialise</span></code>.
</p>
<p class="inwebparagraph">Namespaces can be "nested", in the sense that, for example, we could have:
</p>
<p class="inwebparagraph"></p>
<pre class="display">
<span class="plain">[Errors::Fatal::] Handling fatal errors.</span>
</pre>
<p class="inwebparagraph"></p>
<p class="inwebparagraph"><a id="SP4"></a><b>&#167;4. </b>The <code class="display"><span class="extract">foundation</span></code> module contains a suite of utility functions for handling
strings and streams of text. These are unified in a structure called
<code class="display"><span class="extract">text_stream</span></code>, so that strings in InC webs are almost all values of type
<code class="display"><span class="extract">text_stream *</span></code>. InC provides one convenient feature for this: the notation
</p>
<p class="inwebparagraph"></p>
<pre class="display">
<span class="plain">text_stream *excuse = I"The compiler is not feeling well today.";</span>
</pre>
<p class="inwebparagraph">creates a string literal of this type. (This is analogous to ANSI C's little
used syntax for "long strings", which is <code class="display"><span class="extract">L"like so"</span></code>.)
</p>
<p class="inwebparagraph"><a id="SP5"></a><b>&#167;5. </b>The <code class="display"><span class="extract">words</span></code> module, a component of the Inform compiler which is not
included in Inweb, defines natural-language grammars in a notation called
Preform. Inweb contains support for writing these directly into code; any
paragraph whose code section makes use of this feature is automatically
tagged <code class="display"><span class="extract">^"Preform"</span></code>. This is not the place to document what Preform
notation means, but for example:
</p>
<pre class="display">
<span class="plain">&lt;declaration&gt; ::=</span>
<span class="plain">declare &lt;dominion&gt; independent ==&gt; R[1]</span>
<span class="plain">&lt;dominion&gt; ::=</span>
<span class="plain">canada |</span>
<span class="plain">india |</span>
<span class="plain">malaya</span>
</pre>
<p class="inwebparagraph"></p>
<hr class="tocbar">
<ul class="toc"><li><a href="M-htwaw.html">Back to 'How to Write a Web'</a></li><li><a href="M-awwp.html">Continue with 'Advanced Weaving with Patterns'</a></li></ul><hr class="tocbar">
<!--End of weave-->
</main>
</body>
</html>