1<?xml version="1.0" encoding="UTF-8"?> 2<!-- 3 4 This file is part of GtkSourceView 5 6 Author: Marcello Pogliani 7 Copyright (C) 2013 Marcello Pogliani <marcello.pogliani@gmail.com> 8 9 GtkSourceView is free software; you can redistribute it and/or 10 modify it under the terms of the GNU Lesser General Public 11 License as published by the Free Software Foundation; either 12 version 2.1 of the License, or (at your option) any later version. 13 14 GtkSourceView is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 Lesser General Public License for more details. 18 19 You should have received a copy of the GNU Lesser General Public License 20 along with this library; if not, see <http://www.gnu.org/licenses/>. 21 22--> 23 24<language id="lex" name="Lex" _section="Source" version="2.0"> 25 <metadata> 26 <property name="globs">*.l;*.lex;*.flex</property> 27 <property name="line-comment-start">//</property> 28 <property name="block-comment-start">/*</property> 29 <property name="block-comment-end">*/</property> 30 </metadata> 31 32 <styles> 33 <style id="token" name="Token" map-to="def:keyword" /> 34 <style id="keyword" name="Keyword" map-to="def:keyword" /> 35 <style id="regexp" name="Pattern" map-to="def:identifier" /> 36 <style id="expression" name="Expression" map-to="def:type" /> 37 </styles> 38 39 <definitions> 40 41 <define-regex id="identifier">[a-zA-Z_.][a-zA-Z0-9_.]*</define-regex> 42 <define-regex id="start-cond"><\%{identifier}(,\%{identifier})*></define-regex> 43 44 <!-- blocks for embedded C code --> 45 <context id="inline-c"> 46 <start>^%{</start> 47 <end>^%}</end> 48 <include> 49 <context sub-pattern="0" where="start" style-ref="keyword"/> 50 <context sub-pattern="0" where="end" style-ref="keyword"/> 51 <context ref="c:c"/> 52 </include> 53 </context> 54 55 <context id="top-block"> 56 <start>^%top{</start> 57 <end>^}</end> 58 <include> 59 <context sub-pattern="0" where="start" style-ref="keyword"/> 60 <context sub-pattern="0" where="end" style-ref="keyword"/> 61 <context ref="c:c"/> 62 </include> 63 </context> 64 65 <context id="c-with-brackets"> 66 <include> 67 <context> 68 <start>{</start> 69 <end>}</end> 70 <include> 71 <context ref="c-with-brackets"/> 72 </include> 73 </context> 74 <context ref="c:c"/> 75 </include> 76 </context> 77 78 <context id="indented-lines-c-code"> 79 <start>^(?=[ \t])</start> 80 <end>$</end> 81 <include> 82 <context ref="c:c" /> 83 </include> 84 </context> 85 86 <!-- (1) definition section (before the first %%) --> 87 <context id="definitions"> 88 <include> 89 <context ref="inline-c"/> <!-- %{ ... %} --> 90 <context ref="top-block"/> <!-- %top --> 91 <context ref="indented-lines-c-code" /> <!-- indented lines are copied verbatim to output, hence they're pure C code --> 92 <context ref="option-or-scope"/> 93 <context ref="def:c-like-comment"/> 94 <context ref="def:c-like-comment-multiline"/> 95 <context ref="def:c-like-close-comment-outside-comment"/> 96 <context ref="definition"/> 97 </include> 98 </context> 99 100 <context id="definition" style-ref="expression"> 101 <start>^\%{identifier}</start> 102 <end>$</end> 103 <include> 104 <context sub-pattern="0" where="start" style-ref="token"/> 105 </include> 106 </context> 107 108 <context id="option-or-scope" style-ref="keyword"> 109 <prefix>^%</prefix> 110 <keyword>option</keyword> 111 <keyword>s</keyword> 112 <keyword>x</keyword> 113 <keyword>pointer</keyword> 114 <keyword>array</keyword> 115 </context> 116 117 <!-- (2) rule section (after the first %%) --> 118 <context id="rule-section"> 119 <start>^%%</start> 120 <include> 121 <context sub-pattern="0" where="start" style-ref="token"/> 122 <context ref="rule"/> 123 <context ref="indented-lines-c-code"/> 124 <context ref="inline-c"/> 125 <context ref="user-code"/> 126 </include> 127 </context> 128 129 <context id="rule"> 130 <start>^(?=[^% \t])</start> 131 <end>$</end> 132 <include> 133 <context id="pattern" style-ref="expression"> 134 <start>^</start> 135 <end>[ \t]</end> 136 <include> 137 <context ref="round-brackets" /> 138 <context ref="square-brackets" /> 139 <context> 140 <start>"</start> 141 <end>"</end> 142 <include> 143 <context ref="escaped-char" /> 144 </include> 145 </context> 146 <context ref="start-condition" /> <!-- <SOMETHING>pattern --> 147 <context ref="start-condition-block" /> <!-- <SOMETHING>{ block } --> 148 <context ref="escaped-char" /> 149 </include> 150 </context> 151 <context ref="c-with-brackets"/> 152 </include> 153 </context> 154 155 <context id="start-condition" style-ref="keyword"> 156 <match>^\%{start-cond}(?=[^{])</match> 157 </context> 158 159 <context id="start-condition-block"> 160 <start>(^\%{start-cond}){</start> 161 <end>}</end> 162 <include> 163 <context sub-pattern="1" where="start" style-ref="keyword"/> 164 <context ref="c-with-brackets" /> 165 </include> 166 </context> 167 168 <context id="escaped-char"> 169 <match>\\.</match> 170 </context> 171 172 <context id="square-brackets"> 173 <start>\[</start> 174 <end>\]</end> 175 <include> 176 <context ref="escaped-char" /> 177 <context ref="square-brackets" /> 178 </include> 179 </context> 180 181 <context id="round-brackets"> 182 <start>\(</start> 183 <end>\)</end> 184 <include> 185 <context ref="escaped-char" /> 186 <context ref="round-brackets" /> 187 </include> 188 </context> 189 190 <!-- (3) user code section, this is pure C --> 191 <context id="user-code"> 192 <start>^%%</start> 193 <include> 194 <context sub-pattern="0" where="start" style-ref="token"/> 195 <context ref="c:c"/> 196 </include> 197 </context> 198 199 <!-- Main context --> 200 <context id="lex" class="no-spell-check"> 201 <include> 202 <context ref="definitions"/> 203 <context ref="rule-section"/> 204 </include> 205 </context> 206 207 </definitions> 208</language> 209