Include charset.h and category.h.
[bpt/emacs.git] / src / syntax.h
CommitLineData
9889c728 1/* Declarations having to do with GNU Emacs syntax tables.
3a22ee35 2 Copyright (C) 1985, 1993, 1994 Free Software Foundation, Inc.
9889c728
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
7c938215 8the Free Software Foundation; either version 2, or (at your option)
9889c728
JB
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
9889c728
JB
20
21
22extern Lisp_Object Qsyntax_table_p;
23extern Lisp_Object Fsyntax_table_p (), Fsyntax_table (), Fset_syntax_table ();
24
25/* The standard syntax table is stored where it will automatically
26 be used in all new buffers. */
27#define Vstandard_syntax_table buffer_defaults.syntax_table
28
e46c910e
RS
29/* A syntax table is a chartable whose elements are cons cells
30 (CODE+FLAGS . MATCHING-CHAR). MATCHING-CHAR can be nil if the char
31 is not a kind of parenthesis.
9889c728 32
e46c910e 33 The low 8 bits of CODE+FLAGS is a code, as follows: */
9889c728
JB
34
35enum syntaxcode
36 {
37 Swhitespace, /* for a whitespace character */
38 Spunct, /* for random punctuation characters */
39 Sword, /* for a word constituent */
40 Ssymbol, /* symbol constituent but not word constituent */
41 Sopen, /* for a beginning delimiter */
42 Sclose, /* for an ending delimiter */
43 Squote, /* for a prefix character like Lisp ' */
44 Sstring, /* for a string-grouping character like Lisp " */
45 Smath, /* for delimiters like $ in Tex. */
46 Sescape, /* for a character that begins a C-style escape */
47 Scharquote, /* for a character that quotes the following character */
48 Scomment, /* for a comment-starting character */
49 Sendcomment, /* for a comment-ending character */
c8cdcb16 50 Sinherit, /* use the standard syntax table for this character */
9889c728
JB
51 Smax /* Upper bound on codes that are meaningful */
52 };
53
e46c910e
RS
54/* Fetch the syntax entry for char C from table TABLE.
55 This returns the whole entry (normally a cons cell)
56 and does not do any kind of inheritance. */
c8cdcb16 57
e46c910e
RS
58#if 1
59#define RAW_SYNTAX_ENTRY(table, c) \
60 (XCHAR_TABLE (table)->contents[(unsigned char) (c)])
61
62#define SET_RAW_SYNTAX_ENTRY(table, c, val) \
63 (XCHAR_TABLE (table)->contents[(unsigned char) (c)] = (val))
c8cdcb16 64#else
e46c910e
RS
65#define RAW_SYNTAX_ENTRY(table, c) \
66 ((c) >= 128 \
67 ? raw_syntax_table_lookup (table, c) \
68 : XCHAR_TABLE (table)->contents[(unsigned char) (c)])
69
70#define SET_RAW_SYNTAX_ENTRY(table, c, val) \
71 ((c) >= 128 \
72 ? set_raw_syntax_table_lookup (table, c, (val)) \
73 : XCHAR_TABLE (table)->contents[(unsigned char) (c)] = (val))
c8cdcb16 74#endif
9889c728 75
e46c910e
RS
76/* Extract the information from the entry for character C
77 in syntax table TABLE. Do inheritance. */
c8cdcb16
RS
78
79#ifdef __GNUC__
e46c910e
RS
80#define SYNTAX_ENTRY(c) \
81 ({ Lisp_Object temp, table; \
82 unsigned char cc = (c); \
83 table = current_buffer->syntax_table; \
84 while (!NILP (table)) \
85 { \
86 temp = RAW_SYNTAX_ENTRY (table, cc); \
87 if (!NILP (temp)) \
88 break; \
89 table = XCHAR_TABLE (table)->parent; \
90 } \
91 temp; })
92
93#define SYNTAX(c) \
94 ({ Lisp_Object temp; \
95 temp = SYNTAX_ENTRY (c); \
96 (CONSP (temp) \
97 ? (enum syntaxcode) (XINT (XCONS (temp)->car) & 0xff) \
98 : wrong_type_argument (Qconsp, temp)); })
99
100#define SYNTAX_WITH_FLAGS(c) \
101 ({ Lisp_Object temp; \
102 temp = SYNTAX_ENTRY (c); \
103 (CONSP (temp) \
104 ? XINT (XCONS (temp)->car) \
105 : wrong_type_argument (Qconsp, temp)); })
106
107#define SYNTAX_MATCH(c) \
108 ({ Lisp_Object temp; \
109 temp = SYNTAX_ENTRY (c); \
110 (CONSP (temp) \
111 ? XINT (XCONS (temp)->cdr) \
112 : wrong_type_argument (Qconsp, temp)); })
c8cdcb16 113#else
e46c910e
RS
114extern Lisp_Object syntax_temp;
115extern Lisp_Object syntax_parent_lookup ();
116
117#define SYNTAX_ENTRY(c) \
118 (syntax_temp \
119 = RAW_SYNTAX_ENTRY (current_buffer->syntax_table, (c)), \
120 (NILP (syntax_temp) \
121 ? (syntax_temp \
55862685
RS
122 = syntax_parent_lookup (current_buffer->syntax_table, \
123 (unsigned char) (c))) \
e46c910e
RS
124 : syntax_temp))
125
126#define SYNTAX(c) \
9d40ebd2 127 (syntax_temp = SYNTAX_ENTRY ((c)), \
e46c910e
RS
128 (CONSP (syntax_temp) \
129 ? (enum syntaxcode) (XINT (XCONS (syntax_temp)->car) & 0xff) \
9d40ebd2 130 : wrong_type_argument (Qconsp, syntax_temp)))
e46c910e
RS
131
132#define SYNTAX_WITH_FLAGS(c) \
9d40ebd2 133 (syntax_temp = SYNTAX_ENTRY ((c)), \
e46c910e
RS
134 (CONSP (syntax_temp) \
135 ? XINT (XCONS (syntax_temp)->car) \
9d40ebd2 136 : wrong_type_argument (Qconsp, syntax_temp)))
e46c910e
RS
137
138#define SYNTAX_MATCH(c) \
9d40ebd2 139 (syntax_temp = SYNTAX_ENTRY ((c)), \
e46c910e
RS
140 (CONSP (syntax_temp) \
141 ? XINT (XCONS (syntax_temp)->cdr) \
9d40ebd2 142 : wrong_type_argument (Qconsp, syntax_temp)))
c8cdcb16 143#endif
9889c728 144
a306d6f1 145/* Then there are six single-bit flags that have the following meanings:
9889c728
JB
146 1. This character is the first of a two-character comment-start sequence.
147 2. This character is the second of a two-character comment-start sequence.
148 3. This character is the first of a two-character comment-end sequence.
149 4. This character is the second of a two-character comment-end sequence.
150 5. This character is a prefix, for backward-prefix-chars.
a306d6f1
RS
151 Note that any two-character sequence whose first character has flag 1
152 and whose second character has flag 2 will be interpreted as a comment start.
153
154 bit 6 is used to discriminate between two different comment styles.
155 Languages such as C++ allow two orthogonal syntax start/end pairs
156 and bit 6 is used to determine whether a comment-end or Scommentend
157 ends style a or b. Comment start sequences can start style a or b.
158 Style a is always the default.
159 */
9889c728 160
e46c910e 161#define SYNTAX_COMSTART_FIRST(c) ((SYNTAX_WITH_FLAGS (c) >> 16) & 1)
c8cdcb16 162
e46c910e 163#define SYNTAX_COMSTART_SECOND(c) ((SYNTAX_WITH_FLAGS (c) >> 17) & 1)
c8cdcb16 164
e46c910e 165#define SYNTAX_COMEND_FIRST(c) ((SYNTAX_WITH_FLAGS (c) >> 18) & 1)
c8cdcb16 166
e46c910e 167#define SYNTAX_COMEND_SECOND(c) ((SYNTAX_WITH_FLAGS (c) >> 19) & 1)
c8cdcb16 168
e46c910e 169#define SYNTAX_PREFIX(c) ((SYNTAX_WITH_FLAGS (c) >> 20) & 1)
9889c728 170
a306d6f1 171/* extract the comment style bit from the syntax table entry */
e46c910e 172#define SYNTAX_COMMENT_STYLE(c) ((SYNTAX_WITH_FLAGS (c) >> 21) & 1)
a306d6f1 173
9889c728
JB
174/* This array, indexed by a character, contains the syntax code which that
175 character signifies (as a char). For example,
176 (enum syntaxcode) syntax_spec_code['w'] is Sword. */
177
178extern unsigned char syntax_spec_code[0400];
179
180/* Indexed by syntax code, give the letter that describes it. */
181
c8cdcb16 182extern char syntax_code_spec[14];