Add support for keil c51

Open
#4,983 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
38/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
c, vim
Domain
tooling

Research direction

Start with the proposed ale_linters#c#c51#GetCommand and ale_linters#c#c51#HandleOutput entry points, then review how ale#linter#Define registers the C51 linter. Done means C51 is registered for C files and its compiler output produces the shown error and warning locations and messages.

Written by the indexing model from the issue text.

Description

new tool

I make a linter for keil c51. It has worked good for me recently, so I suggest to add it.
My code:

" 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'),
\})
Dominant language
Vim Script
Stars
14k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dense-analysis/ale

All issues in dense-analysis/ale

Similar issues

More DevTools issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.