Skip to content

Commit

Permalink
syntax: refactor integer regexes
Browse files Browse the repository at this point in the history
* Correct decimal integers to not match floating point values.
* Fix binary, octal, and hexadecimal expressions so to not match when
  the last character of the sequence is an underscore.
* Remove commented out numeric error expressions.
  • Loading branch information
bhcleek authored and mjolk committed Oct 4, 2022
1 parent 8aaa34c commit 8c8e7e2
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions syntax/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,10 @@ endif
syn match goSingleDecl /\%(import\|var\|const\) [^(]\@=/ contains=goImport,goVar,goConst

" Integers
syn match goDecimalInt "\<-\=\(0\|[1-9]_\?\(\d\|\d\+_\?\d\+\)*\)\%([Ee][-+]\=\d\+\)\=\>"
"syn match goDecimalError "\<-\=\(_\(\d\+_*\)\+\|\([1-9]\d*_*\)\+__\(\d\+_*\)\+\|\([1-9]\d*_*\)\+_\+\)\%([Ee][-+]\=\d\+\)\=\>"
syn match goHexadecimalInt "\<-\=0[xX]_\?\(\x\+_\?\)\+\>"
"syn match goHexadecimalError "\<-\=0[xX]_\?\(\x\+_\?\)*\(\([^-+%&|^*/ \t0-9A-Fa-f_)]\|__\)\S*\|_\)\>"
syn match goOctalInt "\<-\=0[oO]\?_\?\(\o\+_\?\)\+\>"
"syn match goOctalError "\<-\=0[0-7oO_]*\(\([^-+%&|^*/ \t0-7oOxX_/)\]\}\:;]\|[oO]\{2,\}\|__\)\S*\|_\|[oOxX]\)\>"
syn match goBinaryInt "\<-\=0[bB]_\?\([01]\+_\?\)\+\>"
"syn match goBinaryError "\<-\=0[bB]_\?[01_]*\([^-+%&|^*/ \t01_)]\S*\|__\S*\|_\)\>"
syn match goDecimalInt "\<-\=\%(0\|\%(\d\|\d_\d\)\+\)\>"
syn match goHexadecimalInt "\<-\=0[xX]_\?\%(\x\|\x_\x\)\+\>"
syn match goOctalInt "\<-\=0[oO]\?_\?\%(\o\|\o_\o\)\+\>"
syn match goBinaryInt "\<-\=0[bB]_\?\%([01]\|[01]_[01]\)\+\>"

hi def link goDecimalInt Integer
hi def link goDecimalError Error
Expand Down

0 comments on commit 8c8e7e2

Please sign in to comment.