Szabolcs
unread,Jan 30, 2008, 8:45:30 AM1/30/08Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to vim_use
When writing syntax files, is it possible to store pieces of regular
expressions in a variable, and reuse them in several match patterns?
This would have been useful for me when trying to get right an unusual
kind of floating point format, which may look like this: 12.3`4.5*^6
(This just means 12.3 * 10^6 with 4.5 digits of precision.) I think
I got it working correctly for the limited case decimal numbers, but
it looks terribly unreadable and I made several mistakes before I got
it right. I'm also interested in how this could be improved:
syntax match someInteger display "\<\d\+\(\*\^\d\+\)\="
syntax match someFloat display "\<\d\+\.\d*\(`\{1,2}\(\(\d\+\(\.\d*\)
\=\)\|\(\.\d+\)\)\=\)\=\(\*\^\d\+\)\="
syntax match someFloat display "\.\d\+\(`\{1,2}\(\(\d\+\(\.\d*\)\=\)\|
\(\.\d+\)\)\=\)\=\(\*\^\d\+\)\="
syntax match someFloat display "\<\d\+`\{1,2}\(\(\d\+\(\.\d*\)\=\)\|\
(\.\d+\)\)\=\(\*\^\d\+\)\="
Note how some of the pieces are repeated:
This is the part following the ` (or ``) sign, repeated 3x: \(\(\d\+\
(\.\d*\)\=\)\|\(\.\d+\)\)\=
And this is the optional exponent, repeated 4x: \(\*\^\d\+\)\=
It would be nice to simplify this before I try to extend it to bases
other than 10, e.g. in base 18 this should be working: 18^^h.
2g``5.7*^2 (it is 5560.`10.9 in decimal notation).