all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* modify-syntax-entry with single and two character comments
@ 2004-10-27 17:55 Spike Ilacqua
  2004-10-27 19:11 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Spike Ilacqua @ 2004-10-27 17:55 UTC (permalink / raw)


I'm trying to build a syntax table for a language that as two comment 
modes.  "|" starts a single line comment, and works like "#" in Perl. 
"|* ... *|" can contain a comment and may be multiple lines, basically 
the same a C's "/* ... */".  I've tried a number of variations and the 
closest I get is:

     (modify-syntax-entry ?\n ">" st)
     (modify-syntax-entry ?\| "<1b4b" st)
     (modify-syntax-entry ?\* ".2b3b" st)


which works for "|* ... *|" and recognizes "|" as the start of a comment 
but doesn't see a newline as the end of a comment that starts with "|". 
  This on the other hand:

     (modify-syntax-entry ?\n ">b" st)
     (modify-syntax-entry ?\| "<b14" st)
     (modify-syntax-entry ?\* ".23" st)

Doesn't recognize the "|* .. *|" comments.  Any suggestions on how to 
make this work?

One note, I have:

      (list "\\(||\\)" 1 '(1 . nil))

in the font-lock-syntactic-keywords to make sure that "||" isn't treated 
as a comment.  But I don't think that's part of the problem.


Thanks,
->Spike

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: modify-syntax-entry with single and two character comments
  2004-10-27 17:55 modify-syntax-entry with single and two character comments Spike Ilacqua
@ 2004-10-27 19:11 ` Stefan Monnier
  2004-10-27 20:16   ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2004-10-27 19:11 UTC (permalink / raw)


>      (modify-syntax-entry ?\n ">" st)
>      (modify-syntax-entry ?\| "<1b4b" st)
>      (modify-syntax-entry ?\* ".2b3b" st)

The syntax string has the following structure:
- 1st char is the main syntax category.
- 2nd char is only used for ( and ) categories.
- the rest are flags with no ordering.

I.e. in your above code the "<1b4b" is equivalent to "< b4b" because the
`1' is ignored.  It's also equivalent to "< 4bb" (because ordering of
flags is ignored) which is equivalent to "< 4b" (because turning ON a flag
twice is the same as turning it ON once).

A correct syntax-table would be:

      (modify-syntax-entry ?\n ">" st)
      (modify-syntax-entry ?\| "< 14" st)
      (modify-syntax-entry ?\* ". 23b" st)

which says:
- | starts a non-b comment and \n ends such a non-b comment.
- | can be the 1nd char of a 2-char comment-starter or the 2nd char of
  a 2-char comment-ender.
- * can be the 2nd char of a 2-char b-style comment-starter or the 3rd char
  of a 2-char b-style comment-ender.

Sadly, this will not work because current Emacsen will immediately think
that | starts the comment without checking the subsequent char to see if
it's a *.

Please report a bug via M-x report-emacs-bug about it.

To work around this problem, two solutions:

1 - use "| " instead of "|" as the non-b comment-starter:

      (modify-syntax-entry ?\n ">" st)
      (modify-syntax-entry ?\| ". 14" st)
      (modify-syntax-entry ?\* ". 23b" st)
      (modify-syntax-entry ?\  "  2" st)

    Any char that can reasonably be expected to appear after a |
    comment-starter should then have the `2' flag added to its syntax :-(

2 - use font-lock-syntactic-keywords to change the syntax of | when it is
    followed by a *.  This is less intrusive but will only work when
    font-lock is used and has been applied to the text.


-- Stefan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: modify-syntax-entry with single and two character comments
  2004-10-27 19:11 ` Stefan Monnier
@ 2004-10-27 20:16   ` Stefan Monnier
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2004-10-27 20:16 UTC (permalink / raw)


> Sadly, this will not work because current Emacsen will immediately think
> that | starts the comment without checking the subsequent char to see if
> it's a *.

> Please report a bug via M-x report-emacs-bug about it.

Actually, don't bother: I just fixed it in Emacs-CVS.


        Stefan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-10-27 20:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-10-27 17:55 modify-syntax-entry with single and two character comments Spike Ilacqua
2004-10-27 19:11 ` Stefan Monnier
2004-10-27 20:16   ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.