I am trying to understand why SQL mode accepts -* as a comment block start.

In sql.el, I read:

(defvar sql-mode-syntax-table
  (let ((table (make-syntax-table)))
    ;; C-style comments /**/ ...
    (modify-syntax-entry ?/ ". 14" table)
    (modify-syntax-entry ?* ". 23" table)
    ;; double-dash starts comments
    (modify-syntax-entry ?- ". 12b" table)
    table) "...")

Elisp manual "Syntax Flags" describes the flags for comment sequences. The digits indeed say -* is a two-character comment-start sequence: 1 makes - the start and 2 makes * the second character.

But b is a comment style flag, separating -- from /* and */, which have the default (a) style. This sounds like -* should not count as a comment-start:

‘b’ means that ‘-’ as a comment delimiter belongs to the alternative “b” comment style. For a two-character comment starter, this flag is only significant on the second char, and for a 2-character comment ender it is only significant on the first char.


Each comment delimiter has a style and only matches comment delimiters of the same style. Thus if a comment starts with the comment-start sequence of style “b”, it will extend until the next matching comment-end sequence of style “b”.

So it turns out that the style flag only regulates which characters will end the comment block. Not which characters can be used together in a two-character comment sequence!

Am I right that this is why -* starts a comment block?

1 Answer 1


These syntax-table settings imply that there are 4 comment-start markers:

  • /* of style a
  • -- of style b
  • -* of style a
  • /- of style b

IIUC two of those are undesired and need to be "weeded out" via syntax-propertize-function.

  • Aha! Now I understand. Indeed /- also starts a (line) comment and can actually occur in SQL (-* cannot be valid syntax). May 9, 2019 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.