Better error message, better highlighting

master
Yevgen Muntyan 2006-09-06 12:25:56 -05:00
parent 4ccd0dcd5f
commit d445431691
6 changed files with 119 additions and 80 deletions

View File

@ -53,7 +53,7 @@
/* Regex used to match "\%{...@start}". */ /* Regex used to match "\%{...@start}". */
#define START_REF_REGEX "(?<!\\\\)(\\\\\\\\)*\\\\%\\{(.*?)@start\\}" #define START_REF_REGEX "(?<!\\\\)(\\\\\\\\)*\\\\%\\{(.*?)@start\\}"
/* Priority of one-time idle that is installed after buffer is modified. */ /* Priority of one-time idle which is installed after buffer is modified. */
#define FIRST_UPDATE_PRIORITY G_PRIORITY_HIGH_IDLE #define FIRST_UPDATE_PRIORITY G_PRIORITY_HIGH_IDLE
/* Maximal amount of time allowed to spent in this first idle. Should be /* Maximal amount of time allowed to spent in this first idle. Should be
* small enough, since in worst case we block ui for this time after each keypress. * small enough, since in worst case we block ui for this time after each keypress.

View File

@ -868,7 +868,7 @@ replace_by_id (const EggRegex *egg_regex,
if (subst == NULL) if (subst == NULL)
g_set_error (&tmp_error, g_set_error (&tmp_error,
PARSER_ERROR, PARSER_ERROR_WRONG_ID, PARSER_ERROR, PARSER_ERROR_WRONG_ID,
_("wrong id '%s' in regex '%s'"), id, regex); _("Unknown id '%s' in regex '%s'"), id, regex);
if (tmp_error == NULL) if (tmp_error == NULL)
{ {
@ -1136,6 +1136,9 @@ expand_regex (ParserState *parser_state,
if (do_expand_vars) if (do_expand_vars)
{ {
tmp_regex = expand_regex_vars (parser_state, regex, len, error); tmp_regex = expand_regex_vars (parser_state, regex, len, error);
if (tmp_regex == NULL)
return NULL;
} }
else else
{ {

View File

@ -15,6 +15,10 @@
<style id="data-type" _name="Data Type" map-to="def:data-type"/> <style id="data-type" _name="Data Type" map-to="def:data-type"/>
<style id="printf" _name="printf conversion" map-to="def:character"/> <style id="printf" _name="printf conversion" map-to="def:character"/>
<style id="escaped-character" _name="Escaped Character" map-to="def:escape"/> <style id="escaped-character" _name="Escaped Character" map-to="def:escape"/>
<style id="floating-point" _name="Float" map-to="def:floating-point"/>
<style id="decimal" _name="Decimal" map-to="def:decimal"/>
<style id="octal" _name="Octal" map-to="def:base-n-integer"/>
<style id="hexadecimal" _name="Hex" map-to="def:base-n-integer"/>
</styles> </styles>
<definitions> <definitions>
@ -36,7 +40,7 @@
<define-regex id="escaped-character" extended="true"> <define-regex id="escaped-character" extended="true">
\\( # leading backslash \\( # leading backslash
[\\\"\'nrtfav\?e] | # escaped character [\\\"\'nrtfav\?e] | # escaped character
[0-7]{1,3} | # on, two, or three octal digits [0-7]{1,3} | # one, two, or three octal digits
x[0-9A-Fa-f]{0,2} # 'x' followed by zero, one, or two hex digits x[0-9A-Fa-f]{0,2} # 'x' followed by zero, one, or two hex digits
) )
</define-regex> </define-regex>
@ -121,11 +125,40 @@
<match>'(\%{escaped-character}|.)'</match> <match>'(\%{escaped-character}|.)'</match>
</context> </context>
<!-- Numbers --> <!-- http://www.lysator.liu.se/c/ANSI-C-grammar-l.html -->
<context ref="def:float"/> <context id="float" style-ref="floating-point">
<context ref="def:decimal"/> <match extended="true">
<context ref="def:octal"/> (?&lt;![\w\.])
<context ref="def:hexadecimal"/> ((\.[0-9]+ | [0-9]+\.[0-9]*) ([Ee][+-]?[0-9]*)? |
([0-9]+[Ee][+-]?[0-9]*))
[fFlL]?
(?![\w\.])
</match>
</context>
<context id="hexadecimal" style-ref="hexadecimal">
<match extended="true">
(?&lt;![\w\.])
0[xX][a-fA-F0-9]+[uUlL]*
(?![\w\.])
</match>
</context>
<context id="octal" style-ref="octal">
<match extended="true">
(?&lt;![\w\.])
0[0-7]+[uUlL]*
(?![\w\.])
</match>
</context>
<context id="decimal" style-ref="decimal">
<match extended="true">
(?&lt;![\w\.])
[0-9]+[uUlL]*
(?![\w\.])
</match>
</context>
<!-- Keywords --> <!-- Keywords -->
<context id="keywords" style-ref="keyword"> <context id="keywords" style-ref="keyword">

View File

@ -26,25 +26,16 @@
<!-- $^ never matches. --> <!-- $^ never matches. -->
<define-regex id="never-match">$^</define-regex> <define-regex id="never-match">$^</define-regex>
<!-- FIXME: these four are broken (and should be removed, I think) --> <define-regex id="decimal" extended="true">
<define-regex id="decimal" extended="true" case-insensitive="true">
\b
([1-9][0-9]* | 0) ([1-9][0-9]* | 0)
(u (ll?)? | ll? u?)?
\b
</define-regex> </define-regex>
<define-regex id="octal" extended="true" case-insensitive="true"> <define-regex id="octal" extended="true">
\b
0 [0-7]+ 0 [0-7]+
(u (ll?)? | ll? u?)?
\b
</define-regex> </define-regex>
<define-regex id="hexadecimal" extended="true" case-insensitive="true"> <define-regex id="hexadecimal" extended="true">
\b 0 [xX] [0-9a-fA-F]+
0x [0-9a-f]+
(u (ll?)? | ll? u?)?
\b
</define-regex> </define-regex>
<!-- FIXME: these one is broke, and is it useful at all? -->
<define-regex id="float" extended="true" case-insensitive="true"> <define-regex id="float" extended="true" case-insensitive="true">
\b \b
([0-9]+ e [-+]? [0-9]+ | ([0-9]+ e [-+]? [0-9]+ |

View File

@ -6,69 +6,11 @@
<style id="math" _name="Math Mode"/> <style id="math" _name="Math Mode"/>
<style id="include" _name="Include" map-to="def:keyword"/> <style id="include" _name="Include" map-to="def:keyword"/>
<style id="most-used-commands" _name="Command" map-to="def:keyword"/> <style id="most-used-commands" _name="Command" map-to="def:keyword"/>
<style id="command" _name="Keyword" map-to="def:keyword"/> <style id="command" _name="Command" map-to="def:keyword"/>
<style id="verbatim" _name="Verbatim" map-to="def:comment"/> <style id="verbatim" _name="Verbatim" map-to="def:comment"/>
</styles> </styles>
<definitions> <definitions>
<context id="latex">
<include>
<context id="comment" style-ref="comment">
<start>%</start>
<end>$</end>
<include>
<context ref="def:comment:*"/>
</include>
</context>
<context id="verbatim-comment" style-ref="comment">
<start>\\begin\{comment\}</start>
<end>\\end\{comment\}</end>
<include>
<context ref="def:comment:*"/>
</include>
</context>
<context id="math" style-ref="math">
<start>\$\$</start>
<end>\$\$</end>
</context>
<context id="inline-math" style-ref="inline-math">
<start>\$</start>
<end>\$</end>
</context>
<context id="verbatim-env" style-ref="verbatim">
<start extended="true">
/
\\begin\{
(
verbatim\*?|
lstlisting|
alltt
)
\}
/x
</start>
<end>\\end\{\%{1@start}\}</end>
</context>
<context id="verbatim-inline" style-ref="verbatim">
<start>\\(verb\*?|lstinline)(\S)</start>
<end>\%{2@start}</end>
</context>
<context id="include" style-ref="include">
<prefix>\\</prefix>
<keyword>input</keyword>
<keyword>include</keyword>
<keyword>includeonly</keyword>
<keyword>usepackage</keyword>
</context>
<context id="most-used-commands" style-ref="most-used-commands"> <context id="most-used-commands" style-ref="most-used-commands">
<prefix>\\</prefix> <prefix>\\</prefix>
@ -125,6 +67,77 @@
<match>\\[a-zA-Z]+</match> <match>\\[a-zA-Z]+</match>
</context> </context>
<context id="latex">
<include>
<context id="comment" style-ref="comment">
<start>%</start>
<end>$</end>
<include>
<context ref="def:comment:*"/>
</include>
</context>
<context id="verbatim-comment" style-ref="comment">
<start>\\begin\{comment\}</start>
<end>\\end\{comment\}</end>
<include>
<context ref="def:comment:*"/>
</include>
</context>
<context id="math" style-ref="math">
<start>\$\$</start>
<end>\$\$</end>
<include>
<context ref="most-used-commands"/>
<context ref="specials-symbol"/>
<context ref="command"/>
</include>
</context>
<context id="inline-math" style-ref="inline-math">
<start>\$</start>
<end>\$</end>
<include>
<context ref="most-used-commands"/>
<context ref="specials-symbol"/>
<context ref="command"/>
</include>
</context>
<context id="verbatim-env" style-ref="verbatim">
<start extended="true">
/
\\begin\{
(
verbatim\*?|
lstlisting|
alltt
)
\}
/x
</start>
<end>\\end\{\%{1@start}\}</end>
</context>
<context id="verbatim-inline" style-ref="verbatim">
<start>\\(verb\*?|lstinline)(\S)</start>
<end>\%{2@start}</end>
</context>
<context id="include" style-ref="include">
<prefix>\\</prefix>
<keyword>input</keyword>
<keyword>include</keyword>
<keyword>includeonly</keyword>
<keyword>usepackage</keyword>
</context>
<context ref="most-used-commands"/>
<context ref="specials-symbol"/>
<context ref="command"/>
</include> </include>
</context> </context>
</definitions> </definitions>

View File

@ -140,6 +140,5 @@
</context> </context>
</definitions> </definitions>
<brackets>&lt;&gt;</brackets>
<block-comment start="&lt;!--" end="-->"/> <block-comment start="&lt;!--" end="-->"/>
</language> </language>