/* GNU Emacs routines to deal with syntax tables; also word and list parsing.
- Copyright (C) 1985, 1987, 1993-1995, 1997-1999, 2001-2012
- Free Software Foundation, Inc.
+ Copyright (C) 1985, 1987, 1993-1995, 1997-1999, 2001-2013 Free
+ Software Foundation, Inc.
This file is part of GNU Emacs.
#include <config.h>
-#include <ctype.h>
#include <sys/types.h>
-#include <setjmp.h>
+
#include "lisp.h"
#include "commands.h"
#include "character.h"
/* Char number of start of containing expression */
ptrdiff_t prevlevelstart;
ptrdiff_t location; /* Char number at which parsing stopped. */
+ ptrdiff_t location_byte; /* Corresponding byte position. */
ptrdiff_t comstr_start; /* Position of last comment/string starter. */
Lisp_Object levelstarts; /* Char numbers of starts-of-expression
of levels (starting from outermost). */
ptrdiff_t, ptrdiff_t, ptrdiff_t, EMACS_INT,
int, Lisp_Object, int);
static int in_classes (int, Lisp_Object);
+
+/* This setter is used only in this file, so it can be private. */
+static void
+bset_syntax_table (struct buffer *b, Lisp_Object val)
+{
+ b->INTERNAL_FIELD (syntax_table) = val;
+}
\f
/* Whether the syntax of the character C has the prefix flag set. */
int syntax_prefix_flag_p (int c)
direction than the intervals - or in an interval. We update the
current syntax-table basing on the property of this interval, and
update the interval to start further than CHARPOS - or be
- NULL_INTERVAL. We also update lim_property to be the next value of
+ NULL. We also update lim_property to be the next value of
charpos to call this subroutine again - or be before/after the
start/end of OBJECT. */
i = interval_of (charpos, object);
gl_state.backward_i = gl_state.forward_i = i;
invalidate = 0;
- if (NULL_INTERVAL_P (i))
+ if (!i)
return;
/* interval_of updates only ->position of the return value, so
update the parents manually to speed up update_interval. */
/* We are guaranteed to be called with CHARPOS either in i,
or further off. */
- if (NULL_INTERVAL_P (i))
+ if (!i)
error ("Error in syntax_table logic for to-the-end intervals");
else if (charpos < i->position) /* Move left. */
{
}
}
- while (!NULL_INTERVAL_P (i))
+ while (i)
{
if (cnt && !EQ (tmp_table, textget (i->plist, Qsyntax_table)))
{
/* e_property at EOB is not set to ZV but to ZV+1, so that
we can do INC(from);UPDATE_SYNTAX_TABLE_FORWARD without
having to check eob between the two. */
- + (NULL_INTERVAL_P (next_interval (i)) ? 1 : 0);
+ + (next_interval (i) ? 0 : 1);
gl_state.forward_i = i;
}
else
cnt++;
i = count > 0 ? next_interval (i) : previous_interval (i);
}
- eassert (NULL_INTERVAL_P (i)); /* This property goes to the end. */
+ eassert (i == NULL); /* This property goes to the end. */
if (count > 0)
gl_state.e_property = gl_state.stop;
else
/* Return the bytepos one character before BYTEPOS.
We assume that BYTEPOS is not at the start of the buffer. */
-static inline ptrdiff_t
+static ptrdiff_t
dec_bytepos (ptrdiff_t bytepos)
{
if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
/* Only the standard syntax table should have a default element.
Other syntax tables should inherit from parents instead. */
- XCHAR_TABLE (copy)->defalt = Qnil;
+ set_char_table_defalt (copy, Qnil);
/* Copied syntax tables should all have parents.
If we copied one with no parent, such as the standard syntax table,
{
int idx;
check_syntax_table (table);
- BVAR (current_buffer, syntax_table) = table;
+ bset_syntax_table (current_buffer, table);
/* Indicate that this buffer now has a specified syntax table. */
idx = PER_BUFFER_VAR_IDX (syntax_table);
SET_PER_BUFFER_VALUE_P (current_buffer, idx, 1);
}
DEFUN ("string-to-syntax", Fstring_to_syntax, Sstring_to_syntax, 1, 1, 0,
- doc: /* Convert a syntax specification STRING into syntax cell form.
-STRING should be a string as it is allowed as argument of
-`modify-syntax-entry'. Value is the equivalent cons cell
-\(CODE . MATCHING-CHAR) that can be used as value of a `syntax-table'
-text property. */)
+ doc: /* Convert a syntax descriptor STRING into a raw syntax descriptor.
+STRING should be a string of the form allowed as argument of
+`modify-syntax-entry'. The return value is a raw syntax descriptor: a
+cons cell \(CODE . MATCHING-CHAR) which can be used, for example, as
+the value of a `syntax-table' text property. */)
(Lisp_Object string)
{
register const unsigned char *p;
" string quote. \\ escape.
$ paired delimiter. ' expression quote or prefix operator.
< comment starter. > comment ender.
- / character-quote. @ inherit from `standard-syntax-table'.
+ / character-quote. @ inherit from parent table.
| generic string fence. ! generic comment fence.
Only single-character comment start and end sequences are represented thus.
insert_string ("\twhich means: ");
- switch (SWITCH_ENUM_CAST (code))
+ switch (code)
{
case Swhitespace:
insert_string ("whitespace"); break;
if (prefix)
continue;
- switch (SWITCH_ENUM_CAST (code))
+ switch (code)
{
case Sescape:
case Scharquote:
else if (SYNTAX_FLAGS_PREFIX (syntax))
continue;
- switch (SWITCH_ENUM_CAST (code))
+ switch (code)
{
case Sword:
case Ssymbol:
if (SYNTAX_FLAGS_PREFIX (prev_from_syntax))
continue;
- switch (SWITCH_ENUM_CAST (code))
+ switch (code)
{
case Sescape:
case Scharquote:
stop: /* Here if stopping before start of sexp. */
from = prev_from; /* We have just fetched the char that starts it; */
+ from_byte = prev_from_byte;
goto done; /* but return the position before it. */
endquoted:
state.prevlevelstart
= (curlevel == levelstart) ? -1 : (curlevel - 1)->last;
state.location = from;
+ state.location_byte = from_byte;
state.levelstarts = Qnil;
while (curlevel > levelstart)
state.levelstarts = Fcons (make_number ((--curlevel)->last),
Sixth arg COMMENTSTOP non-nil means stop at the start of a comment.
If it is symbol `syntax-table', stop after the start of a comment or a
string, or after end of a comment or a string. */)
- (Lisp_Object from, Lisp_Object to, Lisp_Object targetdepth, Lisp_Object stopbefore, Lisp_Object oldstate, Lisp_Object commentstop)
+ (Lisp_Object from, Lisp_Object to, Lisp_Object targetdepth,
+ Lisp_Object stopbefore, Lisp_Object oldstate, Lisp_Object commentstop)
{
struct lisp_parse_state state;
EMACS_INT target;
(NILP (commentstop)
? 0 : (EQ (commentstop, Qsyntax_table) ? -1 : 1)));
- SET_PT (state.location);
+ SET_PT_BOTH (state.location, state.location_byte);
return Fcons (make_number (state.depth),
Fcons (state.prevlevelstart < 0
Qchar_table_extra_slots = intern_c_string ("char-table-extra-slots");
/* Create objects which can be shared among syntax tables. */
- Vsyntax_code_object = Fmake_vector (make_number (Smax), Qnil);
- for (i = 0; i < ASIZE (Vsyntax_code_object); i++)
+ Vsyntax_code_object = make_uninit_vector (Smax);
+ for (i = 0; i < Smax; i++)
ASET (Vsyntax_code_object, i, Fcons (make_number (i), Qnil));
/* Now we are ready to set up this property, so we can
DEFSYM (Qscan_error, "scan-error");
Fput (Qscan_error, Qerror_conditions,
- pure_cons (Qscan_error, pure_cons (Qerror, Qnil)));
+ listn (CONSTYPE_PURE, 2, Qscan_error, Qerror));
Fput (Qscan_error, Qerror_message,
build_pure_c_string ("Scan error"));