Blob Blame History Raw
<?xml version="1.0" encoding="UTF-8"?>
<!--

 This file is part of GtkSourceView

 Author: Yevgen Muntyan <muntyan@tamu.edu>
 Copyright (C) 2006-2008 Yevgen Muntyan <muntyan@tamu.edu>

 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, see <http://www.gnu.org/licenses/>.

-->
<language id="yacc" name="Yacc" _section="Other" version="2.0">
  <metadata>
    <property name="mimetypes">text/x-yacc;text/x-bison</property>
    <property name="globs">*.y;*.yacc</property>
    <property name="line-comment-start">//</property>
    <property name="block-comment-start">/*</property>
    <property name="block-comment-end">*/</property>
  </metadata>

  <styles>
    <!--FIXME make it better names, and make them translatable -->
    <style id="keyword" name="keyword" map-to="def:keyword"/>
    <style id="token-type" name="token type" map-to="def:type"/>
    <style id="rule" name="rule" map-to="def:identifier"/>
  </styles>

  <definitions>
    <context id="inline-c">
      <start>^%{</start>
      <end>^%}</end>
      <include>
        <context sub-pattern="0" where="start" style-ref="keyword"/>
        <context sub-pattern="0" where="end" style-ref="keyword"/>
        <context ref="c:c"/>
      </include>
    </context>

    <context id="options" style-ref="keyword">
      <prefix>^%</prefix>
      <keyword>debug</keyword>
      <keyword>defines</keyword>
      <keyword>destructor</keyword>
      <keyword>dprec</keyword>
      <keyword>error-verbose</keyword>
      <keyword>expect</keyword>
      <keyword>glr-parser</keyword>
      <keyword>initial-action</keyword>
      <keyword>left</keyword>
      <keyword>lex-param</keyword>
      <keyword>locations</keyword>
      <keyword>merge</keyword>
      <keyword>name-prefix</keyword>
      <keyword>no[_-]lines</keyword>
      <keyword>nonassoc</keyword>
      <keyword>output</keyword>
      <keyword>parse-param</keyword>
      <keyword>prec</keyword>
      <keyword>pure[_-]parser</keyword>
      <keyword>raw</keyword>
      <keyword>require</keyword>
      <keyword>right</keyword>
      <keyword>start</keyword>
      <keyword>token[_-]table</keyword>
      <keyword>union</keyword>
    </context>

    <context id="token" end-at-line-end="true">
      <start>^(%(token|type))(&lt;[A-Za-z_][A-Za-z0-9_]*&gt;)?(?![\w_-])</start>
      <include>
        <context sub-pattern="1" where="start" style-ref="keyword"/>
        <context sub-pattern="3" where="start" style-ref="token-type"/>
        <context ref="c:string"/>
        <context ref="c:char"/>
        <context ref="c:float"/>
        <context ref="c:hexadecimal"/>
        <context ref="c:octal"/>
        <context ref="c:decimal"/>
        <context ref="def:c-like-comment"/>
        <context ref="def:c-like-comment-multiline"/>
        <context ref="def:c-like-close-comment-outside-comment"/>
      </include>
    </context>

    <context id="before-grammar">
      <include>
        <context ref="inline-c"/>
        <context ref="options"/>
        <context ref="token"/>
        <context ref="def:c-like-comment"/>
        <context ref="def:c-like-comment-multiline"/>
        <context ref="def:c-like-close-comment-outside-comment"/>
      </include>
    </context>

    <context id="after-grammar">
      <start>^%%</start>
      <include>
        <context sub-pattern="0" where="start" style-ref="keyword"/>
        <context ref="c:c"/>
      </include>
    </context>

    <context id="c-with-brackets">
      <include>
        <context>
          <start>{</start>
          <end>}</end>
          <include>
            <context ref="c-with-brackets"/>
          </include>
        </context>
        <context style-ref="keyword">
          <match>(\$(&lt;[\w\d_-]*&gt;)?[\$0-9]+|[@][$0-9]+)</match>
        </context>
        <context ref="c:c"/>
      </include>
    </context>

    <context id="rule-code">
      <start>{</start>
      <end>}</end>
      <include>
        <context sub-pattern="0" where="start" style-ref="keyword"/>
        <context sub-pattern="0" where="end" style-ref="keyword"/>
        <context ref="c-with-brackets"/>
      </include>
    </context>

    <context id="rule">
      <start>[a-zA-Z_.][a-zA-Z0-9_.]*</start>
      <end>;</end>
      <include>
        <context sub-pattern="0" where="start" style-ref="rule"/>
        <context ref="def:c-like-comment"/>
        <context ref="def:c-like-comment-multiline"/>
        <context ref="def:c-like-close-comment-outside-comment"/>
        <context ref="c:char"/>
        <context ref="c:string"/>
        <context ref="rule-code"/>
      </include>
    </context>

    <context id="grammar">
      <start>^%%</start>
      <include>
        <context sub-pattern="0" where="start" style-ref="keyword"/>
        <context ref="def:c-like-comment"/>
        <context ref="def:c-like-comment-multiline"/>
        <context ref="def:c-like-close-comment-outside-comment"/>
        <context ref="c:char"/>
        <context ref="c:string"/>
        <context ref="rule"/>
        <context ref="after-grammar"/>
      </include>
    </context>

    <context id="yacc">
      <include>
        <context ref="before-grammar"/>
        <context ref="grammar"/>
      </include>
    </context>
  </definitions>
</language>