Mercurial > emacs
comparison src/syntax.c @ 96988:77625aa3eac4
(struct lisp_parse_state, char_quoted, inc_bytepos)
(dec_bytepos, find_defun_start): Use EMACS_INT for buffer positions.
| author | Stefan Monnier <monnier@iro.umontreal.ca> |
|---|---|
| date | Thu, 24 Jul 2008 20:27:57 +0000 |
| parents | 6521e10c7e45 |
| children | 08af05537037 |
comparison
equal
deleted
inserted
replaced
| 96987:359d8fb73538 | 96988:77625aa3eac4 |
|---|---|
| 63 | 63 |
| 64 /* This is the internal form of the parse state used in parse-partial-sexp. */ | 64 /* This is the internal form of the parse state used in parse-partial-sexp. */ |
| 65 | 65 |
| 66 struct lisp_parse_state | 66 struct lisp_parse_state |
| 67 { | 67 { |
| 68 int depth; /* Depth at end of parsing. */ | 68 int depth; /* Depth at end of parsing. */ |
| 69 int instring; /* -1 if not within string, else desired terminator. */ | 69 int instring; /* -1 if not within string, else desired terminator. */ |
| 70 int incomment; /* -1 if in unnestable comment else comment nesting */ | 70 int incomment; /* -1 if in unnestable comment else comment nesting */ |
| 71 int comstyle; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */ | 71 int comstyle; /* comment style a=0, or b=1, or ST_COMMENT_STYLE. */ |
| 72 int quoted; /* Nonzero if just after an escape char at end of parsing */ | 72 int quoted; /* Nonzero if just after an escape char at end of parsing */ |
| 73 int thislevelstart; /* Char number of most recent start-of-expression at current level */ | 73 int mindepth; /* Minimum depth seen while scanning. */ |
| 74 int prevlevelstart; /* Char number of start of containing expression */ | 74 /* Char number of most recent start-of-expression at current level */ |
| 75 int location; /* Char number at which parsing stopped. */ | 75 EMACS_INT thislevelstart; |
| 76 int mindepth; /* Minimum depth seen while scanning. */ | 76 /* Char number of start of containing expression */ |
| 77 int comstr_start; /* Position just after last comment/string starter. */ | 77 EMACS_INT prevlevelstart; |
| 78 Lisp_Object levelstarts; /* Char numbers of starts-of-expression | 78 EMACS_INT location; /* Char number at which parsing stopped. */ |
| 79 of levels (starting from outermost). */ | 79 EMACS_INT comstr_start; /* Position of last comment/string starter. */ |
| 80 Lisp_Object levelstarts; /* Char numbers of starts-of-expression | |
| 81 of levels (starting from outermost). */ | |
| 80 }; | 82 }; |
| 81 | 83 |
| 82 /* These variables are a cache for finding the start of a defun. | 84 /* These variables are a cache for finding the start of a defun. |
| 83 find_start_pos is the place for which the defun start was found. | 85 find_start_pos is the place for which the defun start was found. |
| 84 find_start_value is the defun start position found for it. | 86 find_start_value is the defun start position found for it. |
| 93 static struct buffer *find_start_buffer; | 95 static struct buffer *find_start_buffer; |
| 94 static EMACS_INT find_start_begv; | 96 static EMACS_INT find_start_begv; |
| 95 static int find_start_modiff; | 97 static int find_start_modiff; |
| 96 | 98 |
| 97 | 99 |
| 98 static int find_defun_start P_ ((EMACS_INT, EMACS_INT)); | |
| 99 static int back_comment P_ ((EMACS_INT, EMACS_INT, EMACS_INT, int, int, | |
| 100 EMACS_INT *, EMACS_INT *)); | |
| 101 static int char_quoted P_ ((int, int)); | |
| 102 static Lisp_Object skip_chars P_ ((int, Lisp_Object, Lisp_Object, int)); | 100 static Lisp_Object skip_chars P_ ((int, Lisp_Object, Lisp_Object, int)); |
| 103 static Lisp_Object skip_syntaxes P_ ((int, Lisp_Object, Lisp_Object)); | 101 static Lisp_Object skip_syntaxes P_ ((int, Lisp_Object, Lisp_Object)); |
| 104 static Lisp_Object scan_lists P_ ((EMACS_INT, EMACS_INT, EMACS_INT, int)); | 102 static Lisp_Object scan_lists P_ ((EMACS_INT, EMACS_INT, EMACS_INT, int)); |
| 105 static void scan_sexps_forward P_ ((struct lisp_parse_state *, | 103 static void scan_sexps_forward P_ ((struct lisp_parse_state *, |
| 106 EMACS_INT, EMACS_INT, EMACS_INT, int, | 104 EMACS_INT, EMACS_INT, EMACS_INT, int, |
| 288 /* Returns TRUE if char at CHARPOS is quoted. | 286 /* Returns TRUE if char at CHARPOS is quoted. |
| 289 Global syntax-table data should be set up already to be good at CHARPOS | 287 Global syntax-table data should be set up already to be good at CHARPOS |
| 290 or after. On return global syntax data is good for lookup at CHARPOS. */ | 288 or after. On return global syntax data is good for lookup at CHARPOS. */ |
| 291 | 289 |
| 292 static int | 290 static int |
| 293 char_quoted (charpos, bytepos) | 291 char_quoted (EMACS_INT charpos, EMACS_INT bytepos) |
| 294 register int charpos, bytepos; | |
| 295 { | 292 { |
| 296 register enum syntaxcode code; | 293 register enum syntaxcode code; |
| 297 register int beg = BEGV; | 294 register EMACS_INT beg = BEGV; |
| 298 register int quoted = 0; | 295 register int quoted = 0; |
| 299 int orig = charpos; | 296 EMACS_INT orig = charpos; |
| 300 | 297 |
| 301 while (charpos > beg) | 298 while (charpos > beg) |
| 302 { | 299 { |
| 303 int c; | 300 int c; |
| 304 DEC_BOTH (charpos, bytepos); | 301 DEC_BOTH (charpos, bytepos); |
| 317 } | 314 } |
| 318 | 315 |
| 319 /* Return the bytepos one character after BYTEPOS. | 316 /* Return the bytepos one character after BYTEPOS. |
| 320 We assume that BYTEPOS is not at the end of the buffer. */ | 317 We assume that BYTEPOS is not at the end of the buffer. */ |
| 321 | 318 |
| 322 INLINE int | 319 INLINE EMACS_INT |
| 323 inc_bytepos (bytepos) | 320 inc_bytepos (bytepos) |
| 324 int bytepos; | 321 EMACS_INT bytepos; |
| 325 { | 322 { |
| 326 if (NILP (current_buffer->enable_multibyte_characters)) | 323 if (NILP (current_buffer->enable_multibyte_characters)) |
| 327 return bytepos + 1; | 324 return bytepos + 1; |
| 328 | 325 |
| 329 INC_POS (bytepos); | 326 INC_POS (bytepos); |
| 331 } | 328 } |
| 332 | 329 |
| 333 /* Return the bytepos one character before BYTEPOS. | 330 /* Return the bytepos one character before BYTEPOS. |
| 334 We assume that BYTEPOS is not at the start of the buffer. */ | 331 We assume that BYTEPOS is not at the start of the buffer. */ |
| 335 | 332 |
| 336 INLINE int | 333 INLINE EMACS_INT |
| 337 dec_bytepos (bytepos) | 334 dec_bytepos (bytepos) |
| 338 int bytepos; | 335 EMACS_INT bytepos; |
| 339 { | 336 { |
| 340 if (NILP (current_buffer->enable_multibyte_characters)) | 337 if (NILP (current_buffer->enable_multibyte_characters)) |
| 341 return bytepos - 1; | 338 return bytepos - 1; |
| 342 | 339 |
| 343 DEC_POS (bytepos); | 340 DEC_POS (bytepos); |
| 356 | 353 |
| 357 There is no promise at which position the global syntax data is | 354 There is no promise at which position the global syntax data is |
| 358 valid on return from the subroutine, so the caller should explicitly | 355 valid on return from the subroutine, so the caller should explicitly |
| 359 update the global data. */ | 356 update the global data. */ |
| 360 | 357 |
| 361 static int | 358 static EMACS_INT |
| 362 find_defun_start (pos, pos_byte) | 359 find_defun_start (pos, pos_byte) |
| 363 EMACS_INT pos, pos_byte; | 360 EMACS_INT pos, pos_byte; |
| 364 { | 361 { |
| 365 EMACS_INT opoint = PT, opoint_byte = PT_BYTE; | 362 EMACS_INT opoint = PT, opoint_byte = PT_BYTE; |
| 366 | 363 |
