Skip to content

Commit

Permalink
Indent: Fix issue 51: Strings interfering in indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Feb 18, 2016
1 parent dd07375 commit 7d83a3e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
15 changes: 8 additions & 7 deletions indent/verilog_systemverilog.vim
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,16 @@ function! GetVerilogSystemVerilogIndent()

endfunction

function! s:StripComments(lnum)
function! s:GetLineStripped(lnum)
let l:temp = getline(a:lnum)

" Remove inline comments
" Remove inline comments unless the whole line is a comment
if l:temp !~ '^\s*'.s:vlog_comment.'\s*$'
let l:temp = substitute(l:temp, '/\*.\{-}\*/\|//.*', '', 'g')
endif

return l:temp
" Remove strings
return substitute(l:temp, '".\{-}"', '""', 'g')
endfunction

function! s:SearchBackForPattern(pattern, current_line_no)
Expand Down Expand Up @@ -218,7 +219,7 @@ function! s:GetContextIndent()
continue
endif

let l:line = s:StripComments(l:lnum)
let l:line = s:GetLineStripped(l:lnum)

call s:Verbose("GetContextIndent:" . l:lnum . ": " . l:line)

Expand Down Expand Up @@ -269,19 +270,19 @@ function! s:GetContextIndent()
if l:line =~ '\<end\>' && l:line !~ '\<begin\>.*\<end\>' && l:line !~ '\<begin\>\s*$'
let l:lnum = s:SearchForBlockStart('\<begin\>', '', '\<end\>', l:lnum, 1)
let l:oneline_mode = 0
let l:line = s:StripComments(l:lnum)
let l:line = s:GetLineStripped(l:lnum)
endif

if l:line =~ s:vlog_join
let l:lnum = s:SearchForBlockStart('^\s*\<fork\>', '', s:vlog_join, l:lnum, 1)
let l:oneline_mode = 0
let l:line = s:StripComments(l:lnum)
let l:line = s:GetLineStripped(l:lnum)
endif

if l:line =~ '\<endcase\>'
let l:lnum = s:SearchForBlockStart(s:vlog_case, '', '\<endcase\>', l:lnum, 1)
let l:oneline_mode = 0
let l:line = s:StripComments(l:lnum)
let l:line = s:GetLineStripped(l:lnum)
endif

if l:line =~ '[()]'
Expand Down
9 changes: 9 additions & 0 deletions test/indent.sv
Original file line number Diff line number Diff line change
Expand Up @@ -933,4 +933,13 @@ function void sink_driver::build_phase(uvm_phase phase);
do_something();
endfunction

// Code from: https://github.com/vhda/verilog_systemverilog.vim/issues/51
case (XfrState)
One_XFR : XfrState_str = "One";
Two_XFR : XfrState_str = "Two";
End_XFR : XfrState_str = "End";
default : XfrState_str = "N/A";
endcase
// End of copied code

// vim: set expandtab softtabstop=4 shiftwidth=4 nofoldenable:

0 comments on commit 7d83a3e

Please sign in to comment.