summaryrefslogtreecommitdiff
path: root/devdocs/elisp/syntax-table-internals.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/elisp/syntax-table-internals.html')
-rw-r--r--devdocs/elisp/syntax-table-internals.html89
1 files changed, 89 insertions, 0 deletions
diff --git a/devdocs/elisp/syntax-table-internals.html b/devdocs/elisp/syntax-table-internals.html
new file mode 100644
index 00000000..ba4bb53e
--- /dev/null
+++ b/devdocs/elisp/syntax-table-internals.html
@@ -0,0 +1,89 @@
+ <h3 class="section">Syntax Table Internals</h3> <p>Syntax tables are implemented as char-tables (see <a href="char_002dtables">Char-Tables</a>), but most Lisp programs don’t work directly with their elements. Syntax tables do not store syntax data as syntax descriptors (see <a href="syntax-descriptors">Syntax Descriptors</a>); they use an internal format, which is documented in this section. This internal format can also be assigned as syntax properties (see <a href="syntax-properties">Syntax Properties</a>). </p> <p>Each entry in a syntax table is a <em>raw syntax descriptor</em>: a cons cell of the form <code>(<var>syntax-code</var>
+. <var>matching-char</var>)</code>. <var>syntax-code</var> is an integer which encodes the syntax class and syntax flags, according to the table below. <var>matching-char</var>, if non-<code>nil</code>, specifies a matching character (similar to the second character in a syntax descriptor). </p> <p>Use <code>aref</code> (see <a href="array-functions">Array Functions</a>) to get the raw syntax descriptor of a character, e.g. <code>(aref <span class="nolinebreak">(syntax-table)</span> ch)</code>. </p> <p>Here are the syntax codes corresponding to the various syntax classes: </p> <table> <tr>
+<td width="20%"><i>Code</i></td>
+<td width="30%"><i>Class</i></td>
+<td width="20%"><i>Code</i></td>
+<td width="30%"><i>Class</i></td>
+</tr> <tr>
+<td width="20%">0</td>
+<td width="30%">whitespace</td>
+<td width="20%">8</td>
+<td width="30%">paired delimiter</td>
+</tr> <tr>
+<td width="20%">1</td>
+<td width="30%">punctuation</td>
+<td width="20%">9</td>
+<td width="30%">escape</td>
+</tr> <tr>
+<td width="20%">2</td>
+<td width="30%">word</td>
+<td width="20%">10</td>
+<td width="30%">character quote</td>
+</tr> <tr>
+<td width="20%">3</td>
+<td width="30%">symbol</td>
+<td width="20%">11</td>
+<td width="30%">comment-start</td>
+</tr> <tr>
+<td width="20%">4</td>
+<td width="30%">open parenthesis</td>
+<td width="20%">12</td>
+<td width="30%">comment-end</td>
+</tr> <tr>
+<td width="20%">5</td>
+<td width="30%">close parenthesis</td>
+<td width="20%">13</td>
+<td width="30%">inherit</td>
+</tr> <tr>
+<td width="20%">6</td>
+<td width="30%">expression prefix</td>
+<td width="20%">14</td>
+<td width="30%">generic comment</td>
+</tr> <tr>
+<td width="20%">7</td>
+<td width="30%">string quote</td>
+<td width="20%">15</td>
+<td width="30%">generic string</td>
+</tr> </table> <p>For example, in the standard syntax table, the entry for ‘<samp>(</samp>’ is <code>(4 . 41)</code>. 41 is the character code for ‘<samp>)</samp>’. </p> <p>Syntax flags are encoded in higher order bits, starting 16 bits from the least significant bit. This table gives the power of two which corresponds to each syntax flag. </p> <table> <tr>
+<td width="15%"><i>Prefix</i></td>
+<td width="30%"><i>Flag</i></td>
+<td width="15%"><i>Prefix</i></td>
+<td width="30%"><i>Flag</i></td>
+</tr> <tr>
+<td width="15%">‘<samp>1</samp>’</td>
+<td width="30%"><code>(ash 1 16)</code></td>
+<td width="15%">‘<samp>p</samp>’</td>
+<td width="30%"><code>(ash 1 20)</code></td>
+</tr> <tr>
+<td width="15%">‘<samp>2</samp>’</td>
+<td width="30%"><code>(ash 1 17)</code></td>
+<td width="15%">‘<samp>b</samp>’</td>
+<td width="30%"><code>(ash 1 21)</code></td>
+</tr> <tr>
+<td width="15%">‘<samp>3</samp>’</td>
+<td width="30%"><code>(ash 1 18)</code></td>
+<td width="15%">‘<samp>n</samp>’</td>
+<td width="30%"><code>(ash 1 22)</code></td>
+</tr> <tr>
+<td width="15%">‘<samp>4</samp>’</td>
+<td width="30%"><code>(ash 1 19)</code></td>
+<td width="15%">‘<samp>c</samp>’</td>
+<td width="30%"><code>(ash 1 23)</code></td>
+</tr> </table> <dl> <dt id="string-to-syntax">Function: <strong>string-to-syntax</strong> <em>desc</em>
+</dt> <dd><p>Given a syntax descriptor <var>desc</var> (a string), this function returns the corresponding raw syntax descriptor. </p></dd>
+</dl> <dl> <dt id="syntax-class-to-char">Function: <strong>syntax-class-to-char</strong> <em>syntax</em>
+</dt> <dd><p>Given a raw syntax descriptor <var>syntax</var> (an integer), this function returns the corresponding syntax descriptor (a character). </p></dd>
+</dl> <dl> <dt id="syntax-after">Function: <strong>syntax-after</strong> <em>pos</em>
+</dt> <dd><p>This function returns the raw syntax descriptor for the character in the buffer after position <var>pos</var>, taking account of syntax properties as well as the syntax table. If <var>pos</var> is outside the buffer’s accessible portion (see <a href="narrowing">accessible portion</a>), the return value is <code>nil</code>. </p></dd>
+</dl> <dl> <dt id="syntax-class">Function: <strong>syntax-class</strong> <em>syntax</em>
+</dt> <dd>
+<p>This function returns the syntax code for the raw syntax descriptor <var>syntax</var>. More precisely, it takes the raw syntax descriptor’s <var>syntax-code</var> component, masks off the high 16 bits which record the syntax flags, and returns the resulting integer. </p> <p>If <var>syntax</var> is <code>nil</code>, the return value is <code>nil</code>. This is so that the expression </p> <div class="example"> <pre class="example">(syntax-class (syntax-after pos))
+</pre>
+</div> <p>evaluates to <code>nil</code> if <code>pos</code> is outside the buffer’s accessible portion, without throwing errors or returning an incorrect code. </p>
+</dd>
+</dl><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
+ <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Table-Internals.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Syntax-Table-Internals.html</a>
+ </p>
+</div>