ptomato / sublime_autotools

Autotools syntax highlighting for Sublime Text
GNU General Public License v3.0
17 stars 15 forks source link

Autoconf syntax not *quite* right #1

Closed stephenfin closed 9 years ago

stephenfin commented 10 years ago

I'm seeing some small issues with larger m4 files using the 'Autoconf M4' syntax - namely openvswitch.m4. The file slowly breaks as you work down the file, starting with this block:

dnl Checks for Netlink support.
AC_DEFUN([OVS_CHECK_NETLINK],
  [AC_CHECK_HEADER([linux/netlink.h],
                   [HAVE_NETLINK=yes],
                   [HAVE_NETLINK=no],
                   [#include <sys/socket.h>
   #include <linux/types.h>
   ])
   AM_CONDITIONAL([HAVE_NETLINK], [test "$HAVE_NETLINK" = yes])
   if test "$HAVE_NETLINK" = yes; then
      AC_DEFINE([HAVE_NETLINK], [1],
                [Define to 1 if Netlink protocol is available.])
   fi])

This suggests a misconfigured regex to me. I'll attempt to debug myself, but I'm not familiar with the 'tmLanguage' personally.

ptomato commented 10 years ago

Wow, this block highlights two of the things that the Autoconf syntax can't (yet) do...

Some macros, like AC_CHECK_HEADER, can contain C code as one of their arguments, like the fourth argument of AC_CHECK_HEADER does. I don't currently support this.

But the thing that is really breaking the highlight is these lines:

if test "$HAVE_NETLINK" = yes; then
      AC_DEFINE([HAVE_NETLINK], [1],
                [Define to 1 if Netlink protocol is available.])
fi

The highlighter can deal with interspersed M4 and shell code, but not with M4 code on the inside a shell statement, such as if. (Since I highlight the shell code by reusing the built-in source.shell highlighter, I'd have to redefine a large part of it to fix that.) But even that wouldn't break the rest of the file - normally the AC_DEFINE would just not be highlighted - if it weren't for the if in "Define to 1 if..." Sublime Text's built-in shell highlighter sees that as the beginning of another if statement which never terminates, and so all bets are off.

I can think of a couple workarounds:

AS_IF([test "$HAVE_NETLINK" = yes],
    [AC_DEFINE([HAVE_NETLINK], [1],
        [Define to 1 if Netlink protocol is available.])])

or simply changing the string to Define to 1 when Netlink protocol is available or something else that doesn't include the word if, but of course that's not what you want. The file should highlight correctly as it is. I'll see if I get some time to look into this.

ptomato commented 9 years ago

I think I've fixed this, you should be able to use the current version on master to highlight that file correctly. I'll test this out a bit by using it myself for a few more days before releasing it as 1.1.0.

stephenfin commented 9 years ago

Looking good to me (for my purposes anyway). Nicely done