From 0fdd4b10ef8d58bf3da20ee7673958a9eab14488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Nadeau=2C=20ing?= Date: Wed, 26 Apr 2017 10:41:01 -0400 Subject: [PATCH 1/2] Add missing format parsing for printf format: - %m will print strerror(errno) for scanf format: - optional 'm' can be used with string conversions - [ is a valid conversion specifier literal %: - do not match when literal % is used with other flags known bug: the following is not be hilighted properly: printf("%ms"); the 's' it not part of the conversion specifier in this case but is when used with scanf. --- grammars/c.cson | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/grammars/c.cson b/grammars/c.cson index 63bf26e..f970d63 100644 --- a/grammars/c.cson +++ b/grammars/c.cson @@ -711,7 +711,8 @@ ((-?\\d+)|\\*(-?\\d+\\$)?)? # minimum field width (\\.((-?\\d+)|\\*(-?\\d+\\$)?)?)? # precision (hh|h|ll|l|j|t|z|q|L|vh|vl|v|hv|hl)? # length modifier - [diouxXDOUeEfFgGaACcSspn%] # conversion type + ((m?\\[((\\^\\]|\\])?[^\\]]+)\\])|m[sc]|[diouxXDOUeEfFgGaACcSspnm]) # conversion type + | %% # literal % ''' 'name': 'constant.other.placeholder.c' } From 9d9f54b196ff27c181f16f5142e8ef0261387580 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Nadeau=2C=20ing?= Date: Tue, 31 Oct 2017 10:32:06 -0400 Subject: [PATCH 2/2] Rewrite string_placeholder's regex --- grammars/c.cson | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/grammars/c.cson b/grammars/c.cson index f970d63..85616aa 100644 --- a/grammars/c.cson +++ b/grammars/c.cson @@ -704,14 +704,23 @@ 'string_placeholder': 'patterns': [ { - 'match': '''(?x) % - (\\d+\\$)? # field (argument #) - [#0\\- +']* # flags + 'match': '''(?x) + (%|%\\d+\\$) # conversion specification start: either % or %m$ where m is an integer + [#0\\- +'I\\*m]* # flags: I is gnulibc extention [,;:_]? # separator character (AltiVec) - ((-?\\d+)|\\*(-?\\d+\\$)?)? # minimum field width - (\\.((-?\\d+)|\\*(-?\\d+\\$)?)?)? # precision - (hh|h|ll|l|j|t|z|q|L|vh|vl|v|hv|hl)? # length modifier - ((m?\\[((\\^\\]|\\])?[^\\]]+)\\])|m[sc]|[diouxXDOUeEfFgGaACcSspnm]) # conversion type + (-?\\d+|\\*\\d+\\$)? # width + (\\.(\\d+|\\*(\\d+\\$)?))? # precision + ( + ((hh|h|l|ll|j|z|Z|t)?[diuUoOxXn]{1})| + ((l|L)?[fFeEgGaA]{1})| + p| # pointer address + (l?[cs]{1})| # character and string with w_char support + (\\[((\\^\\]|\\])?[^\\]]+)\\])| # scanset + m| # Glibc extension + ((ll)?[fFeEgGaA]{1})| # nonstandard GNU's extention + ((q|L)?[diuoxXn]{1})| # BSD and nonstandard GNU's extention + [CS]{1} # nonstandard SUSv2/3/4's extention + ) | %% # literal % ''' 'name': 'constant.other.placeholder.c'