[gtksourceview] Add highlighting for Automake and update Makefile



commit 3d99486edf812ab0ae6a29ed9ba3d4701f66661a
Author: P. F. Chimento <philip chimento gmail com>
Date:   Thu Sep 15 19:08:14 2011 +0200

    Add highlighting for Automake and update Makefile
    
    This adds an automake.lang to the syntax highlighting, fixing bug
    577596. It also updates makefile.lang so that it highlights shell code
    in the bodies of make rules (which changes are also reflected in
    Automake.) It also adds a new smoke test for the Automake syntax.

 data/language-specs/Makefile.am   |    1 +
 data/language-specs/automake.lang |  329 +++++++++++++++++++++++++++++++++++++
 data/language-specs/makefile.lang |   23 +--
 po/POTFILES.skip                  |    1 +
 tests/testfiles.sh                |   28 +++-
 5 files changed, 368 insertions(+), 14 deletions(-)
---
diff --git a/data/language-specs/Makefile.am b/data/language-specs/Makefile.am
index 1a6c7fd..c3919c0 100644
--- a/data/language-specs/Makefile.am
+++ b/data/language-specs/Makefile.am
@@ -3,6 +3,7 @@ TESTS = check-language.sh
 LANGUAGES =			\
 	ada.lang		\
 	asp.lang		\
+	automake.lang		\
 	awk.lang		\
 	bennugd.lang		\
 	bibtex.lang		\
diff --git a/data/language-specs/automake.lang b/data/language-specs/automake.lang
new file mode 100644
index 0000000..a623bff
--- /dev/null
+++ b/data/language-specs/automake.lang
@@ -0,0 +1,329 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ This file is part of GtkSourceView
+
+ Author: P. F. Chimento <philip chimento gmail com>
+ Copyright (C) 2011 P. F. Chimento <philip chimento gmail com>
+
+ GtkSourceView is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ GtkSourceView is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+
+-->
+<language id="automake" _name="Automake" version="2.0" section="Sources">
+  <metadata>
+    <property name="globs">Makefile.am;GNUmakefile.am</property>
+    <property name="line-comment-start">#</property>
+  </metadata>
+
+  <!--
+    Early versions of this were based on Vim's Automake syntax highlighting
+    file. This language definition is for Automake's Makefile.am files. It is
+    based on the definition of Makefile, except it highlights Makefile variables
+    which are significant to Automake, as well as Autoconf-style @variable@
+    substitutions.
+  -->
+
+  <styles>
+    <style id="lhs"       _name="Automake Variable" map-to="def:identifier"/>
+    <style id="primary"   _name="Primary"           map-to="def:type"/>
+    <style id="secondary" _name="Secondary"         map-to="def:statement"/>
+    <style id="prefix"    _name="Prefix"            map-to="def:statement"/>
+    <style id="target"    _name="Optional Target"   map-to="def:statement"/>
+    <style id="dirname"   _name="Built-in Target"   map-to="def:statement"/>
+    <style id="keyword"   _name="Other Keyword"     map-to="def:statement"/>
+    <style id="subst"     _name="Substitution"      map-to="def:preprocessor"/>
+  </styles>
+
+  <definitions>
+    <!-- Allow substitutions on RHS of assignment -->
+    <replace id="makefile:assignment-rhs" ref="assignment-rhs"/>
+    <!-- Also allow substitutions in makefile's shell code -->
+    <replace id="makefile:command" ref="command"/>
+
+    <!-- Also allow substitutions in automake variable names, that's why the
+    @ is in here; as in libfoobar_ VERSION@_SOURCES -->
+    <define-regex id="variable">[A-Za-z0-9_ ]+</define-regex>
+
+    <!-- What is allowed on a line before an Automake variable - no tabs! -->
+    <define-regex id="space">^ *</define-regex>
+
+    <!-- What must come after an Automake variable - one of the assignment
+    operators =, +=, ?=, := (Not sure what := does, but Webkit's GNUmakefile.am
+    uses it, for example -->
+    <define-regex id="operator">\s*[\+\?:]?=</define-regex>
+
+    <!-- Prefixes for primaries and secondaries -->
+    <define-regex id="prefix">(?:no)?dist|no(?:base|trans)</define-regex>
+
+    <!-- "Primaries", or the last component of Product List Variables -->
+    <define-regex id="primary" extended="true">
+      PROGRAMS|
+      (?:LT)?LIBRARIES|
+      LISP|
+      PYTHON|
+      JAVA|
+      SCRIPTS|
+      DATA|
+      HEADERS|
+      MANS|
+      TEXINFOS
+    </define-regex>
+
+    <!-- Non-directory installation targets -->
+    <define-regex id="target">noinst|check|EXTRA</define-regex>
+
+    <!-- The list of things that can go before "FLAGS" -->
+    <define-regex id="flags" extended="true">
+      C|
+      CCAS|
+      CPP|
+      CXX|
+      F|
+      GCJ|
+      JAVAC|
+      L|
+      LD|
+      LIBTOOL|
+      (?:[A-Z]+_)?LOG|
+      MAKEINFO(?:HTML)?|
+      OBJC|
+      R|
+      UPC|
+      VALA|
+      Y
+    </define-regex>
+
+    <!-- "Secondaries", or the last component of Product Source Variables -->
+    <define-regex id="secondary" extended="true">
+      AR|
+      DEPENDENCIES|
+      LDADD|
+      LIBADD|
+      LINK|
+      SHORTNAME|
+      SOURCES|
+      \%{flags}FLAGS
+    </define-regex>
+
+    <!-- Names of other Automake variables that aren't primaries, secondaries,
+    flags, or target directories -->
+    <define-regex id="keyword" extended="true">
+      ACLOCAL_AMFLAGS|
+      AM_DEFAULT_SOURCE_EXT|
+      AUTOMAKE_OPTIONS|
+      BUILT_SOURCES|
+      CC|
+      CLASSPATH_ENV|
+      (?:DIST|MAINTAINER|MOSTLY)?CLEANFILES|
+      COMPILE|
+      (?:CXX|FC|OBJC|UPC)(?:COMPILE|LINK)?|
+      DEFAULT_INCLUDES|
+      DEFS|
+      DISTCHECK_CONFIGURE_FLAGS|
+      DVIPS|
+      ETAGS_ARGS|
+      EXTRA_DIST|
+      F77(?:COMPILE)?|
+      FLINK|
+      INCLUDE|
+      JAVAC|
+      JAVAROOT|
+      LIBS|
+      LINK|
+      (?:[A-Z]+_)?LOG_COMPILER|
+      MAKEINFO(?:HTML)?|
+      (?:OMIT|TAGS)_DEPENDENCIES|
+      (?:DIST_)?SUBDIRS|
+      SUFFIXES|
+      TESTS(?:_ENVIRONMENT)?|
+      TEXI2(?:DVI|PDF)|
+      TEXINFO_TEX|
+      VALAC
+    </define-regex>
+
+    <!-- Predefined directory targets -->
+    <define-regex id="dirname" extended="true">
+      s?bin|
+      (?:pkg)?lib(?:exec)?|
+      (?:pkg)?data|
+      (?:pkg|old)?include|
+      dataroot|
+      sysconf|
+      (?:shared|local)state|
+      doc|
+      info|
+      html|
+      dvi|
+      pdf|
+      ps|
+      lisp|
+      locale|
+      man[1-8]?(?:ext)?|
+      src|
+      (?:pkg)?python|
+      (?:pkg)?pyexec
+    </define-regex>
+
+    <!-- Substitutions from AC_SUBST -->
+    <context id="subst" style-ref="subst">
+      <match>@\%{variable}@</match>
+    </context>
+
+    <!-- Lines starting with ## are not copied into Makefile.in, and no
+    substitutions are performed -->
+    <context id="nosubcomment" end-at-line-end="true" class-disabled="no-spell-check">
+      <start>^##</start>
+      <include>
+        <context ref="def:in-comment"/>
+      </include>
+    </context>
+
+    <!-- Copy of def:shell-like-comment, except it includes substitutions -->
+    <context id="comment" end-at-line-end="true" class-disabled="no-spell-check">
+      <start>#</start>
+      <include>
+        <context ref="subst"/>
+        <context ref="def:in-comment"/>
+      </include>
+    </context>
+
+    <!-- Assignment to a FLAGS variable -->
+    <context id="flags-assignment" end-at-line-end="true">
+      <start>\%{space}((?:AM_)?\%{flags}FLAGS)\%{operator}</start>
+      <include>
+        <context sub-pattern="1" where="start" style-ref="keyword"/>
+        <context ref="assignment-rhs"/>
+      </include>
+    </context>
+
+    <!-- Assignment to a non-primary, secondary, flags, or dir variable -->
+    <context id="keyword-assignment" end-at-line-end="true">
+      <start>\%{space}(\%{keyword})\%{operator}</start>
+      <include>
+        <context sub-pattern="1" where="start" style-ref="keyword"/>
+        <context ref="assignment-rhs"/>
+      </include>
+    </context>
+
+    <!-- Assignment to a primary. The subpatterns are named. Subpattern names
+    must not conflict subpattern names in other expressions, so some are
+    prefixed with a 'p' -->
+    <context id="primary-assignment" end-at-line-end="true">
+      <start extended="true">
+        \%{space}                           # beginning of line
+        (?P&lt;pprefix&gt;(?:\%{prefix}_)*) # any number of prefixes_
+        (?:                                 # either...
+          (?P&lt;target&gt;\%{target})|     # ...a nondir target (e.g. noinst),
+          (?P&lt;dirname&gt;\%{dirname})|   # ...a dir target (e.g. bin)
+          (?P&lt;pvariable&gt;\%{variable}) # ...or a user-defined dir
+        )
+        (?P&lt;primary&gt;_\%{primary})     # and a _PRIMARY
+        \%{operator}                        # an assignment operator
+      </start>
+      <include>
+        <context sub-pattern="primary" where="start" style-ref="primary"/>
+        <context sub-pattern="pprefix" where="start" style-ref="prefix"/>
+        <context sub-pattern="target" where="start" style-ref="target"/>
+        <context sub-pattern="dirname" where="start" style-ref="dirname"/>
+        <context sub-pattern="pvariable" where="start" style-ref="lhs"/>
+        <context ref="assignment-rhs"/>
+      </include>
+    </context>
+
+    <!-- Assignment to a secondary. Again, some subpatterns have to be prefixed
+    with an 's' -->
+    <context id="secondary-assignment" end-at-line-end="true">
+      <start extended="true">
+        \%{space}                           # beginning of line
+        (?P&lt;sprefix&gt;
+          (?:(?:\%{prefix}|EXTRA)_)*)       # any number of prefix_ or EXTRA_
+        (?P&lt;svariable&gt;\%{variable})   # the canonicalized_program_name
+        (?P&lt;secondary&gt;_\%{secondary}) # and a _SECONDARY
+        \%{operator}                        # an assignment operator
+      </start>
+      <include>
+        <context sub-pattern="sprefix" where="start" style-ref="prefix"/>
+        <context sub-pattern="svariable" where="start" style-ref="lhs"/>
+        <context sub-pattern="secondary" where="start" style-ref="secondary"/>
+        <context ref="assignment-rhs"/>
+      </include>
+    </context>
+
+    <!-- Assignment to a directory variable (e.g. foobardir) -->
+    <context id="dir-assignment" end-at-line-end="true">
+      <start>\%{space}(\%{variable})(dir)\%{operator}</start>
+      <include>
+        <context id="dir-lhs" sub-pattern="1" where="start" style-ref="lhs"/>
+        <context id="dir" sub-pattern="2" where="start" style-ref="keyword"/>
+        <context ref="assignment-rhs"/>
+      </include>
+    </context>
+
+    <!-- What is allowed on the right-hand side of an assignment -->
+    <context id="assignment-rhs" end-at-line-end="true">
+      <start></start>
+      <include>
+        <context ref="def:line-continue"/>
+        <context ref="def:shell-like-comment"/>
+        <context ref="makefile:variable"/>
+        <context ref="makefile:string"/>
+        <context ref="def:single-quoted-string"/>
+        <context ref="sh:backtick-subshell"/>
+        <context ref="subst"/>
+      </include>
+    </context>
+
+    <!-- Copy of makefile:command, except it includes substitutions -->
+    <context id="command" extend-parent="false" end-at-line-end="true">
+      <start></start>
+      <include>
+        <context ref="def:line-continue"/>
+        <context ref="subst"/>
+        <context ref="sh:sh" original="true"/>
+      </include>
+    </context>
+
+    <!-- All the contexts listed here represent an assignment to a variable
+    (Automake variable or otherwise), and they all contain the "assignment-rhs"
+    context -->
+    <context id="assignment">
+      <include>
+        <context ref="flags-assignment"/>
+        <context ref="keyword-assignment"/>
+        <context ref="primary-assignment"/>
+        <context ref="secondary-assignment"/>
+        <context ref="dir-assignment"/>
+        <context ref="makefile:assignment"/>
+      </include>
+    </context>
+
+    <!-- The main context -->
+    <context id="automake">
+      <include>
+        <context ref="makefile:directives" style-ref="def:keyword"/>
+        <context ref="makefile:functions" style-ref="def:function"/>
+        <context ref="subst" style-ref="subst"/>
+        <!-- Must come before 'comment' -->
+        <context ref="nosubcomment" style-ref="def:comment"/>
+        <context ref="comment" style-ref="def:comment"/>
+        <context ref="assignment"/>
+        <!-- Must come after 'comment', otherwise we can get rules starting
+        with #; must also come after 'assignment' because of := operator -->
+        <context ref="makefile:rule"/>
+      </include>
+    </context>
+  </definitions>
+
+</language>
diff --git a/data/language-specs/makefile.lang b/data/language-specs/makefile.lang
index d1de08e..824aad7 100644
--- a/data/language-specs/makefile.lang
+++ b/data/language-specs/makefile.lang
@@ -23,7 +23,7 @@
 <language id="makefile" _name="Makefile" version="2.0" _section="Sources">
   <metadata>
     <property name="mimetypes">text/x-makefile</property>
-    <property name="globs">[Mm]akefile;GNUmakefile;[Mm]akefile.*;*.make;*.mak;*.mk</property>
+    <property name="globs">[Mm]akefile;GNUmakefile;*.make;*.mak;*.mk</property>
     <property name="line-comment-start">#</property>
   </metadata>
 
@@ -42,6 +42,9 @@
   </styles>
 
   <definitions>
+    <replace id="sh:sh" ref="command"/>
+    <replace id="sh:variable" ref="sh-variable"/>
+
     <define-regex id="variable">[a-zA-Z_][a-zA-Z0-9_]*</define-regex>
 
     <context id="variable-1">
@@ -65,12 +68,10 @@
       </include>
     </context>
 
-    <context id="backtick-string" style-ref="function" end-at-line-end="true">
-      <start>`</start>
-      <end>`</end>
+    <context id="sh-variable">
       <include>
-        <context ref="def:escape"/>
-        <context ref="def:line-continue"/>
+        <context ref="variable"/>
+        <context ref="sh:variable" original="true"/>
       </include>
     </context>
 
@@ -92,7 +93,7 @@
         <context ref="variable"/>
         <context ref="string"/>
         <context ref="def:single-quoted-string"/>
-        <context ref="backtick-string"/>
+        <context ref="sh:backtick-subshell"/>
       </include>
     </context>
 
@@ -100,11 +101,7 @@
       <start></start>
       <include>
         <context ref="def:line-continue"/>
-        <context ref="def:shell-like-comment"/>
-        <context ref="variable"/>
-        <context ref="string"/>
-        <context ref="def:single-quoted-string"/>
-        <context ref="backtick-string"/>
+        <context ref="sh:sh" original="true"/>
       </include>
     </context>
 
@@ -156,7 +153,7 @@
         <context ref="def:shell-like-comment"/>
 
         <context id="assignment" end-at-line-end="true">
-          <start>^(\%{variable})\s*[\+]?=</start>
+          <start>^(\%{variable})\s*[\+\?:]?=</start>
             <include>
               <context sub-pattern="1" where="start" style-ref="assignment-lhs"/>
               <context ref="assignment-rhs"/>
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index e7376ca..34e60ec 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -1,3 +1,4 @@
 data/styles/testdark.xml
 gtksourceview/regex/glib/gregex.c
 tests/test-scheme.xml
+data/language-specs/automake.lang
diff --git a/tests/testfiles.sh b/tests/testfiles.sh
index 360ef21..c496c95 100755
--- a/tests/testfiles.sh
+++ b/tests/testfiles.sh
@@ -10,7 +10,7 @@
 # latex.lang m4.lang makefile.lang ms.lang perl.lang po.lang prolog.lang
 # python.lang sh.lang texinfo.lang xml.lang yacc.lang libtool.lang
 # pkgconfig.lang objc.lang chdr.lang testv1.lang t2t.lang fortran.lang
-# forth.lang octave.lang
+# forth.lang octave.lang automake.lang
 
 dir="testdir"
 mkdir -p $dir/
@@ -1015,3 +1015,29 @@ function NewFunction() {
   multiline comment*/
 }
 EOFEOF
+
+cat > $dir/Makefile.am <<EOFEOF
+ACLOCAL_AMFLAGS = -I m4
+
+EXTRA_DIST += README.W32
+
+if HAVE_DOXYGEN
+  DOXYDIR = docs
+endif
+
+doc_DATA = AUTHORS ChangeLog COPYING INSTALL NEWS README
+
+bin_PROGRAMS = jupiter
+jupiter_SOURCES = main.c
+jupiter_CPPFLAGS = -I\$(top_srcdir)/common
+jupiter_LDADD = ../common/libjupcommon.a
+
+check_SCRIPTS = greptest.sh
+TESTS = \$(check_SCRIPTS)
+
+greptest.sh:
+	echo './jupiter | grep "Hello from .*jupiter!"' > greptest.sh
+	chmod +x greptest.sh
+
+CLEANFILES = greptest.sh
+EOFEOF



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]