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