Next: , Previous: , Up: Syntax Tables   [Contents][Index]

34.7 Syntax Table Internals

Syntax tables are implemented as char-tables (see Char-Tables), but most Lisp programs don’t work directly with their elements. Syntax tables do not store syntax data as syntax descriptors (see Syntax Descriptors); they use an internal format, which is documented in this section. This internal format can also be assigned as syntax properties (see Syntax Properties).

Each entry in a syntax table is a raw syntax descriptor: a cons cell of the form (syntax-code . matching-char). syntax-code is an integer which encodes the syntax class and syntax flags, according to the table below. matching-char, if non-nil, specifies a matching character (similar to the second character in a syntax descriptor).

Here are the syntax codes corresponding to the various syntax classes:

CodeClassCodeClass
0whitespace8paired delimiter
1punctuation9escape
2word10character quote
3symbol11comment-start
4open parenthesis12comment-end
5close parenthesis13inherit
6expression prefix14generic comment
7string quote15generic string

For example, in the standard syntax table, the entry for ‘(’ is (4 . 41). 41 is the character code for ‘)’.

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.

PrefixFlagPrefixFlag
1(lsh 1 16)p(lsh 1 20)
2(lsh 1 17)b(lsh 1 21)
3(lsh 1 18)n(lsh 1 22)
4(lsh 1 19)
Function: string-to-syntax desc

Given a syntax descriptor desc (a string), this function returns the corresponding raw syntax descriptor.

Function: syntax-after pos

This function returns the raw syntax descriptor for the character in the buffer after position pos, taking account of syntax properties as well as the syntax table. If pos is outside the buffer’s accessible portion (see accessible portion), the return value is nil.

Function: syntax-class syntax

This function returns the syntax code for the raw syntax descriptor syntax. More precisely, it takes the raw syntax descriptor’s syntax-code component, masks off the high 16 bits which record the syntax flags, and returns the resulting integer.

If syntax is nil, the return value is returns nil. This is so that the expression

(syntax-class (syntax-after pos))

evaluates to nil if pos is outside the buffer’s accessible portion, without throwing errors or returning an incorrect code.

Next: , Previous: , Up: Syntax Tables   [Contents][Index]