brf routing profile edition with vim

97 views
Skip to first unread message

alexis.r...@gmail.com

unread,
Aug 7, 2019, 11:13:20 AM8/7/19
to OSM Android bikerouting
Hi everybody!

Is there anybody using vim? I created vim indent and syntax files for .brf files.
I would need feedback to fix these or to add these to the official vim repo.

I do not know if I can attach a file here, so I past the code below (sorry)

Thank you!

.vim/syntax/brf.vim
--------------------------------------------------------------

" Vim syntax file
" Language: Brouter routing file
" Maintainer: Tyr4 <alexis....@gmail.com>
" Latest Revision: 2019-08-01

if exists("b:current_syntax")
    finish
endif

syntax case match

syntax iskeyword 48-57,-,_,65-90,97-122
setlocal iskeyword+=48-57,-,_,65-90,97-122

syn keyword brfTodo contained    TODO FIXME NOTE STOPHERE
syn keyword brfAssign    assign
syn keyword brfOperators    not or and xor multiply add sub max min equal greater lesser switch if then else
syn keyword brfGlobalVar    processunusedtags turnInstructionMode turnInstructionCatchingRange turnInstructionRoundabouts
syn keyword brfGlobalVar    downhillcost downhillcutoff uphillcost uphillcutoff elevationpenaltybuffer elevationmaxbuffer elevationbufferreduce
syn keyword brfGlobalVar    validForBikes validForFoot validForCars
syn keyword brfGlobalVar    pass1coefficient pass2coefficient
syn keyword brfWayVar    turncost initialcost costfactor uphillcostfactor downhillcostfactor nodeaccessgranted initialclassifier
syn keyword brfNodeVar    initialcost
syn keyword brfConstant    true false

syn cluster brfAnyVar    contains=brfGlobalVar,brfWayVar,brfNodeVar

syn match brfContext    /^---context:\(global\|way\|node\)/
syn match brfLookupKey    /\<\(:\|\k\)\+=/ nextgroup=brfLookupValue
syn match brfLookupValue contained    /\<\(\k\+\(|\k\+\)*\>\)/ contains=brfChoice
syn match brfComment    /#.*$/ contains=brfTodo
syn match brfNumeric    /\<-\?\d\+\(\.\d\+\)\?\>/
syn match brfChoice contained    /|/

let b:current_syntax = "brf"

hi def link brfTodo    Todo
hi def link brfAssign    Statement
hi def link brfOperators    Statement
hi def link brfGlobalVar    Identifier
hi def link brfWayVar    Identifier
hi def link brfNodeVar    Identifier
hi def link brfContext    Special
hi def link brfComment    Comment
hi def link brfNumeric    Constant
hi def link brfConstant    Constant
hi def link brfLookupKey    Type
hi def link brfLookupValue    Special
hi def link brfChoice    Function

.vim/indent/brf.vim
--------------------------------------------------------------

" Vim indent file
" Language:     Brouter routing file
" Author:       Tyr4 <alexis....@gmail.com>
" Last Change:  2019-08-01

if exists('b:did_indent')
    finish
endif

let b:did_indent = 1

setlocal nolisp
setlocal autoindent

setlocal indentexpr=GetBrfIndent(v:lnum)
setlocal indentkeys+=<:>,=switch

if exists("GetBrfIndent")
    finish
endif

function PreviousNonBlankLine(lnum)
    let l:plnum = a:lnum-1
    while l:plnum > 1 && match(getline(l:plnum), '^\s*$') == 0
        let l:plnum -= 1
    endwhile
    return l:plnum
endfunction

function GetBrfIndent(lnum)
    let l:kws1 = '\<\(not\|or\|and\|xor\|multiply\|add\|sub\|max\|min\|equal\|greater\|lesser\|switch\|if\|then\|else\)\>'
    let l:kws2 = '^assign\s\+\k\+\s\+\S\+\s*$'
    let l:kws3 = '\<\(assign\)\>'
    "let l:plnum = PreviousNonBlankLine(a:lnum)
    let l:plnum = a:lnum-1
    let l:line = getline(l:plnum)
    let l:sharp = match(l:line, '#')

    let s = matchend(l:line, l:kws1)
    if s > -1 && (l:sharp == -1 || l:sharp > match(l:line, l:kws1))
        return s + 1
    endif

    let s = matchend(l:line, l:kws2)
    if s > -1 && (l:sharp == -1 || l:sharp > match(l:line, l:kws1))
        return 0
    endif

    let s = matchend(l:line, l:kws3)
    if s > -1 && (l:sharp == -1 || l:sharp > match(l:line, l:kws1))
        return s + 1
    endif

    return match(l:line, '\S')
endfunction

function BrfITabIndent()
    let l:pos=getcurpos()
    let l:col=l:pos[2]
    let l:lnum=l:pos[1]
    if match(getline(l:lnum), '^assign') == 0
        let l:col=getcurpos()[2]
        let l:spaces = 2 - (((l:col-1)/&softtabstop) % 2)
        return repeat('    ', l:spaces)
    endif
    if l:lnum > 1
        "let l:line=getline(PreviousNonBlankLine(l:lnum))
        let l:line=getline(l:lnum-1)
        let l:n=matchend(l:line,'\>',l:col)
        if l:n > -1
            let l:r=l:n-l:col+2
            return repeat(' ', l:r)
        else
            return "    "
        endif
    else
        return "    "
    endif
    echo l:lnum
endfunction

imap <Tab> <C-R>=BrfITabIndent()<CR>

set ts=8 sts=8 sw=8 expandtab tw=80

Reply all
Reply to author
Forward
0 new messages