dense-analysis / dense-analysis/ale
Add support for keil c51
- Dominant language
- Vim Script
- Stars
- 14k
- Forks
- 1.5k
- Avg merge
- 17h 49m
- Merged PRs (30d)
- 1
Description
I make a linter for keil c51. It has worked good for me recently, so I suggest to add it.
My code:
```vim
" ALE Linter for C51 Compiler
call ale#Set('c_c51_executable', 'c51')
call ale#Set('c_c51_options', 'NOPRINT NOOBJECT')
call ale#Set('c_c51_inc_path','.;.')
" 获取C51编译器的命令
" get the command
function! ale_linters#c#c51#GetCommand(buffer) abort
let l:file = expand('%:p')
return ale#Var(a:buffer, 'c_c51_executable') . ' ' . l:file . ' ' . ale#Var(a:buffer, 'c_c51_options') . ' ' . 'INCDIR("' . ale#Var(a:buffer,'c_c51_inc_path') . '")'
endfunction
" 处理C51编译器的输出
" handle the output of the keil c51
function! ale_linters#c#c51#HandleOutput(buffer, output) abort
let l:errors = []
for l:line in a:output
" 匹配错误和警告行
" match errors and warnings
if l:line =~ '\v\*\*\*\s+(ERROR|WARNING)\s+\w+\s+IN\s+LINE\s+\d+'
" 提取错误类型、行号、文件路径和错误消息
" get the information of errors and warnings
let l:match = matchlist(l:line, '\v\*\*\*\s+(ERROR|WARNING)\s+(\w+)\s+IN\s+LINE\s+(\d+)\s+OF\s+\S+:\s*(.*)')
if !empty(l:match)
let l:type = l:match[1]
let l:error_code = l:match[2]
let l:line_number = str2nr(l:match[3])
let l:message = l:match[4]
let l:file_path = expand('%:p')
call add(l:errors, {
\ 'filename': l:file_path,
\ 'lnum': l:line_number,
\ 'type': l:type == 'ERROR' ? 'E' : 'W',
\ 'text': l:message
\})
endif
endif
endfor
return l:errors
endfunction
" 注册C51 Linter
" register keil c51 linter
call ale#linter#Define('c', {
\ 'name': 'c51',
\ 'output_stream': 'both',
\ 'executable': {b -> ale#Var(b, 'c_c51_executable')},
\ 'command': function('ale_linters#c#c51#GetCommand'),
\ 'callback': function('ale_linters#c#c51#HandleOutput'),
\})
```
Contributor guide
Assessment
This issue has not been assessed yet.