Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List comprehension is highlighted as error! #94

Closed
ngphuoc opened this issue Jan 27, 2017 · 7 comments
Closed

List comprehension is highlighted as error! #94

ngphuoc opened this issue Jan 27, 2017 · 7 comments

Comments

@ngphuoc
Copy link

ngphuoc commented Jan 27, 2017

The closing square bracket is highlighted as error in [i for i in 1:10]

2017-01-27-114529_176x71_scrot

@carlobaldassi
Copy link
Contributor

I can not reproduce this, so I'll need more details. Does it happen under all circumstances, or do you have a specific example? Does the error persist if you refresh the file with CTRL-L? And if you reload it?

@ngphuoc
Copy link
Author

ngphuoc commented Jan 27, 2017

Sorry, I the error happens when I use the luochen1990\rainbow vim plugin. I have to config start and end brackets for all predefined block: juliaModuleBlock, juliaFunctionBlock, juliaRepeatBlock, juliaConditionalBlock. The juliaRepeatBlock makes this [i for i in 1:10 end] correct, but I don't know what is the name of this juliaListComprehensionBlock? block[i for i in 1:10]

below is my .vimrc

call plug#begin('~/.vim/plugged')
Plug 'JuliaEditorSupport/julia-vim'
Plug 'luochen1990/rainbow'
call plug#end()

syntax enable
filetype plugin indent on

let g:rainbow_active = 1

let g:rainbow_conf = {
    \   'guifgs': ['royalblue3', 'darkorange3', 'seagreen3', 'firebrick'],
    \   'ctermfgs': ['darkgreen', 'darkblue', 'darkgray', 'brown', 'darkcyan', 'darkred', 'darkmagenta', 'gray', 'black', 'red'],
    \   'operators': '_,_',
    \   'parentheses': ['start=/(/ end=/)/ fold', 'start=/\[/ end=/\]/ fold', 'start=/{/ end=/}/ fold'],
    \   'separately': {
    \       '*': {},
    \       'julia': {
    \           'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/', 'start=/(/ end=/)/ containedin=juliaConditionalBlock', 'start=/\[/ end=/\]/ containedin=juliaConditionalBlock', 'start=/{/ end=/}/ containedin=juliaConditionalBlock', 'start=/(/ end=/)/ containedin=juliaModuleBlock', 'start=/\[/ end=/\]/ containedin=juliaModuleBlock', 'start=/{/ end=/}/ containedin=juliaModuleBlock', 'start=/(/ end=/)/ containedin=juliaFunctionBlock', 'start=/\[/ end=/\]/ containedin=juliaFunctionBlock', 'start=/{/ end=/}/ containedin=juliaFunctionBlock', 'start=/(/ end=/)/ containedin=juliaRepeatBlock', 'start=/\[/ end=/\]/ containedin=juliaRepeatBlock', 'start=/{/ end=/}/ containedin=juliaRepeatBlock', 'start=/(/ end=/)/ containedin=juliaModuleBlock', 'start=/\[/ end=/\]/ containedin=juliaModuleBlock', 'start=/{/ end=/}/ containedin=juliaModuleBlock'],
    \       },
    \       'vim': {
    \           'parentheses': ['start=/(/ end=/)/', 'start=/\[/ end=/\]/', 'start=/{/ end=/}/ fold', 'start=/(/ end=/)/ containedin=vimFuncBody', 'start=/\[/ end=/\]/ containedin=vimFuncBody', 'start=/{/ end=/}/ fold containedin=vimFuncBody'],
    \       },
    \

Could you advise some hint? Many thanks.

@ngphuoc
Copy link
Author

ngphuoc commented Jan 27, 2017

I have the same error using junegunn/rainbow_parentheses.vim

2017-01-27-134536_276x93_scrot

I've also checked that python list comprehension is OK for both rainbow plugins

2017-01-27-134452_400x109_scrot

@carlobaldassi
Copy link
Contributor

I have investigated the issue. The problem is that rainbow supersedes the syntax file definitions of the parentheses. As a quick fix for the issue at hand, you can just add contains=juliaComprehensionFor,juliaComprehensionIf for all () and [] parentheses definitions.

However, you should be aware that 1) there are more block types than the ones you have defined (see here); 2) the syntax file uses contained, contains and containedin directives to (more or less) faithfully reproduce julia's own parsing rules, which are quite complex, and messing with that (as rainbow does) will very likely lead to other (more subtle) issues. For example, in some contexts the end keyword is recognized as an indexing expression (see e.g. this). Basically, you'd need to look into the julia syntax file and reproduce what's done there. And coordinate with that in case of changes.

My advice is to just disable rainbow for julia files...

@ngphuoc
Copy link
Author

ngphuoc commented Jan 31, 2017

Thank you for your solution! I have been able to config it to recognize 1 level list comprehension. I still get an error for list of list comprehension, but 1 level is enough for me currently.

@ngphuoc ngphuoc closed this as completed Jan 31, 2017
@carlocab
Copy link

@ngphuoc Apologies for reviving this long-dead issue, but do you mind sharing the snippet of your config that helped you resolve the problem for 1 level of list comprehensions? I hope you still have a copy of it.

@fchorney
Copy link

fchorney commented Oct 7, 2022

I also apologize for reviving this another 2 years later. I would love a solution for this as I am hitting the exact same issue with rainbow and julia-vim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants