�ɲɾ�����ӯ�����һ��ˣ��������С���˴��ͣ�������P���ҹ��ñ˽��ά�Բ��������˸߸ԣ�������ơ��ҹ��ñ�����ά�Բ���ˡ���˳^�ӣ������ӡ� ���ͯj�ӣ��ƺ���ӣ� ? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!? PNG ?%k25u25%fgd5n!usr/share/vim/vim80/indent/awk.vim000064400000017137152531463060013013 0ustar00" vim: set sw=3 sts=3: " Awk indent script. It can handle multi-line statements and expressions. " It works up to the point where the distinction between correct/incorrect " and personal taste gets fuzzy. Drop me an e-mail for bug reports and " reasonable style suggestions. " " Bugs: " ===== " - Some syntax errors may cause erratic indentation. " - Same for very unusual but syntacticly correct use of { } " - In some cases it's confused by the use of ( and { in strings constants " - This version likes the closing brace of a multiline pattern-action be on " character position 1 before the following pattern-action combination is " formatted " Author: " ======= " Erik Janssen, ejanssen@itmatters.nl " " History: " ======== " 26-04-2002 Got initial version working reasonably well " 29-04-2002 Fixed problems in function headers and max line width " Added support for two-line if's without curly braces " Fixed hang: 2011 Aug 31 " Only load this indent file when no other was loaded. if exists("b:did_indent") finish endif let b:did_indent = 1 setlocal indentexpr=GetAwkIndent() " Mmm, copied from the tcl indent program. Is this okay? setlocal indentkeys-=:,0# " Only define the function once. if exists("*GetAwkIndent") finish endif " This function contains a lot of exit points. It checks for simple cases " first to get out of the function as soon as possible, thereby reducing the " number of possibilities later on in the difficult parts function! GetAwkIndent() " Find previous line and get it's indentation let prev_lineno = s:Get_prev_line( v:lnum ) if prev_lineno == 0 return 0 endif let prev_data = getline( prev_lineno ) let ind = indent( prev_lineno ) " Increase indent if the previous line contains an opening brace. Search " for this brace the hard way to prevent errors if the previous line is a " 'pattern { action }' (simple check match on /{/ increases the indent then) if s:Get_brace_balance( prev_data, '{', '}' ) > 0 return ind + shiftwidth() endif let brace_balance = s:Get_brace_balance( prev_data, '(', ')' ) " If prev line has positive brace_balance and starts with a word (keyword " or function name), align the current line on the first '(' of the prev " line if brace_balance > 0 && s:Starts_with_word( prev_data ) return s:Safe_indent( ind, s:First_word_len(prev_data), getline(v:lnum)) endif " If this line starts with an open brace bail out now before the line " continuation checks. if getline( v:lnum ) =~ '^\s*{' return ind endif " If prev line seems to be part of multiline statement: " 1. Prev line is first line of a multiline statement " -> attempt to indent on first ' ' or '(' of prev line, just like we " indented the positive brace balance case above " 2. Prev line is not first line of a multiline statement " -> copy indent of prev line let continue_mode = s:Seems_continuing( prev_data ) if continue_mode > 0 if s:Seems_continuing( getline(s:Get_prev_line( prev_lineno )) ) " Case 2 return ind else " Case 1 if continue_mode == 1 " Need continuation due to comma, backslash, etc return s:Safe_indent( ind, s:First_word_len(prev_data), getline(v:lnum)) else " if/for/while without '{' return ind + shiftwidth() endif endif endif " If the previous line doesn't need continuation on the current line we are " on the start of a new statement. We have to make sure we align with the " previous statement instead of just the previous line. This is a bit " complicated because the previous statement might be multi-line. " " The start of a multiline statement can be found by: " " 1 If the previous line contains closing braces and has negative brace " balance, search backwards until cumulative brace balance becomes zero, " take indent of that line " 2 If the line before the previous needs continuation search backward " until that's not the case anymore. Take indent of one line down. " Case 1 if prev_data =~ ')' && brace_balance < 0 while brace_balance != 0 && prev_lineno > 0 let prev_lineno = s:Get_prev_line( prev_lineno ) let prev_data = getline( prev_lineno ) let brace_balance=brace_balance+s:Get_brace_balance(prev_data,'(',')' ) endwhile let ind = indent( prev_lineno ) else " Case 2 if s:Seems_continuing( getline( prev_lineno - 1 ) ) let prev_lineno = prev_lineno - 2 let prev_data = getline( prev_lineno ) while prev_lineno > 0 && (s:Seems_continuing( prev_data ) > 0) let prev_lineno = s:Get_prev_line( prev_lineno ) let prev_data = getline( prev_lineno ) endwhile let ind = indent( prev_lineno + 1 ) endif endif " Decrease indent if this line contains a '}'. if getline(v:lnum) =~ '^\s*}' let ind = ind - shiftwidth() endif return ind endfunction " Find the open and close braces in this line and return how many more open- " than close braces there are. It's also used to determine cumulative balance " across multiple lines. function! s:Get_brace_balance( line, b_open, b_close ) let line2 = substitute( a:line, a:b_open, "", "g" ) let openb = strlen( a:line ) - strlen( line2 ) let line3 = substitute( line2, a:b_close, "", "g" ) let closeb = strlen( line2 ) - strlen( line3 ) return openb - closeb endfunction " Find out whether the line starts with a word (i.e. keyword or function " call). Might need enhancements here. function! s:Starts_with_word( line ) if a:line =~ '^\s*[a-zA-Z_0-9]\+\s*(' return 1 endif return 0 endfunction " Find the length of the first word in a line. This is used to be able to " align a line relative to the 'print ' or 'if (' on the previous line in case " such a statement spans multiple lines. " Precondition: only to be used on lines where 'Starts_with_word' returns 1. function! s:First_word_len( line ) let white_end = matchend( a:line, '^\s*' ) if match( a:line, '^\s*func' ) != -1 let word_end = matchend( a:line, '[a-z]\+\s\+[a-zA-Z_0-9]\+[ (]*' ) else let word_end = matchend( a:line, '[a-zA-Z_0-9]\+[ (]*' ) endif return word_end - white_end endfunction " Determine if 'line' completes a statement or is continued on the next line. " This one is far from complete and accepts illegal code. Not important for " indenting, however. function! s:Seems_continuing( line ) " Unfinished lines if a:line =~ '\(--\|++\)\s*$' return 0 endif if a:line =~ '[\\,\|\&\+\-\*\%\^]\s*$' return 1 endif " if/for/while (cond) eol if a:line =~ '^\s*\(if\|while\|for\)\s*(.*)\s*$' || a:line =~ '^\s*else\s*' return 2 endif return 0 endfunction " Get previous relevant line. Search back until a line is that is no " comment or blank and return the line number function! s:Get_prev_line( lineno ) let lnum = a:lineno - 1 let data = getline( lnum ) while lnum > 0 && (data =~ '^\s*#' || data =~ '^\s*$') let lnum = lnum - 1 let data = getline( lnum ) endwhile return lnum endfunction " This function checks whether an indented line exceeds a maximum linewidth " (hardcoded 80). If so and it is possible to stay within 80 positions (or " limit num of characters beyond linewidth) by decreasing the indent (keeping " it > base_indent), do so. function! s:Safe_indent( base, wordlen, this_line ) let line_base = matchend( a:this_line, '^\s*' ) let line_len = strlen( a:this_line ) - line_base let indent = a:base if (indent + a:wordlen + line_len) > 80 " Simple implementation good enough for the time being let indent = indent + 3 endif return indent + a:wordlen endfunction usr/share/vim/vim80/syntax/awk.vim000064400000017237152532310420013051 0ustar00" Vim syntax file " Language: awk, nawk, gawk, mawk " Maintainer: Antonio Colombo " Last Change: 2016 Sep 05 " AWK ref. is: Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger " The AWK Programming Language, Addison-Wesley, 1988 " GAWK ref. is: Arnold D. Robbins " Effective AWK Programming, Third Edition, O'Reilly, 2001 " Effective AWK Programming, Fourth Edition, O'Reilly, 2015 " (also available and updated with the gawk source distribution) " MAWK is a "new awk" meaning it implements AWK ref. " mawk conforms to the Posix 1003.2 (draft 11.3) " definition of the AWK language which contains a few features " not described in the AWK book, and mawk provides a small number of extensions. " TODO: " Dig into the commented out syntax expressions below. " Quit when a syntax file was already loaded if exists("b:current_syntax") finish endif let s:cpo_save = &cpo set cpo&vim " A bunch of useful Awk keywords " AWK ref. p. 188 syn keyword awkStatement break continue delete exit syn keyword awkStatement function getline next syn keyword awkStatement print printf return " GAWK ref. Chapter 7-9 syn keyword awkStatement switch nextfile syn keyword awkStatement func " " GAWK ref. Chapter 9, Functions " Numeric Functions syn keyword awkFunction atan2 cos exp int intdiv log rand sin sqrt srand " String Manipulation Functions syn keyword awkFunction asort asort1 gensub gsub index length match syn keyword awkFunction patsplit split sprintf strtonum sub substr syn keyword awkFunction tolower toupper " Input Output Functions syn keyword awkFunction close fflush system " Time Functions syn keyword awkFunction mktime strftime systime " Bit Manipulation Functions syn keyword awkFunction and compl lshift or rshift xor " Getting Type Functions syn keyword awkFunction isarray typeof " String-Translation Functions syn keyword awkFunction bindtextdomain dcgettext dcngetext syn keyword awkConditional if else syn keyword awkRepeat while for do syn keyword awkTodo contained TODO syn keyword awkPatterns BEGIN END BEGINFILE ENDFILE " GAWK ref. Chapter 7 " Built-in Variables That Control awk syn keyword awkVariables BINMODE CONVFMT FIELDWIDTHS FPAT FS syn keyword awkVariables IGNORECASE LINT OFMT OFS ORS PREC syn keyword awkVariables ROUNDMODE RS SUBSEP TEXTDOMAIN " Built-in Variables That Convey Information syn keyword awkVariables ARGC ARGV ARGIND ENVIRON ERRNO FILENAME syn keyword awkVariables FNR NF FUNCTAB NR PROCINFO RLENGTH RSTART syn keyword awkVariables RT SYMTAB " Arithmetic operators: +, and - take care of ++, and -- syn match awkOperator "+\|-\|\*\|/\|%\|=" syn match awkOperator "+=\|-=\|\*=\|/=\|%=" syn match awkOperator "\^\|\^=" " Octal format character. syn match awkSpecialCharacter display contained "\\[0-7]\{1,3\}" " Hex format character. syn match awkSpecialCharacter display contained "\\x[0-9A-Fa-f]\+" syn match awkFieldVars "\$\d\+" " catch errors caused by wrong parenthesis syn region awkParen transparent start="(" end=")" contains=ALLBUT,awkParenError,awkSpecialCharacter,awkArrayElement,awkArrayArray,awkTodo,awkRegExp,awkBrktRegExp,awkBrackets,awkCharClass,awkComment syn match awkParenError display ")" "syn match awkInParen display contained "[{}]" " 64 lines for complex &&'s, and ||'s in a big "if" syn sync ccomment awkParen maxlines=64 " Search strings & Regular Expressions therein. syn region awkSearch oneline start="^[ \t]*/"ms=e start="\(,\|!\=\~\)[ \t]*/"ms=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter syn region awkBrackets contained start="\[\^\]\="ms=s+2 start="\[[^\^]"ms=s+1 end="\]"me=e-1 contains=awkBrktRegExp,awkCharClass syn region awkSearch oneline start="[ \t]*/"hs=e skip="\\\\\|\\/" end="/" contains=awkBrackets,awkRegExp,awkSpecialCharacter syn match awkCharClass contained "\[:[^:\]]*:\]" syn match awkBrktRegExp contained "\\.\|.\-[^]]" syn match awkRegExp contained "/\^"ms=s+1 syn match awkRegExp contained "\$/"me=e-1 syn match awkRegExp contained "[?.*{}|+]" " String and Character constants " Highlight special characters (those which have a backslash) differently syn region awkString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@Spell,awkSpecialCharacter,awkSpecialPrintf syn match awkSpecialCharacter contained "\\." " Some of these combinations may seem weird, but they work. syn match awkSpecialPrintf contained "%[-+ #]*\d*\.\=\d*[cdefgiosuxEGX%]" " Numbers, allowing signs (both -, and +) " Integer number. syn match awkNumber display "[+-]\=\<\d\+\>" " Floating point number. syn match awkFloat display "[+-]\=\<\d\+\.\d+\>" " Floating point number, starting with a dot. syn match awkFloat display "[+-]\=\<.\d+\>" syn case ignore "floating point number, with dot, optional exponent syn match awkFloat display "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\>" "floating point number, starting with a dot, optional exponent syn match awkFloat display "\.\d\+\(e[-+]\=\d\+\)\=\>" "floating point number, without dot, with exponent syn match awkFloat display "\<\d\+e[-+]\=\d\+\>" syn case match "syn match awkIdentifier "\<[a-zA-Z_][a-zA-Z0-9_]*\>" " Comparison expressions. syn match awkExpression "==\|>=\|=>\|<=\|=<\|\!=" syn match awkExpression "\~\|\!\~" syn match awkExpression "?\|:" syn keyword awkExpression in " Boolean Logic (OR, AND, NOT) syn match awkBoolLogic "||\|&&\|\!" " This is overridden by less-than & greater-than. " Put this above those to override them. " Put this in a 'match "\.*;\="' to make it not override " less/greater than (most of the time), but it won't work yet because " keywords always have precedence over match & region. " File I/O: (print foo, bar > "filename") & for nawk (getline < "filename") "syn match awkFileIO contained ">" "syn match awkFileIO contained "<" " Expression separators: ';' and ',' syn match awkSemicolon ";" syn match awkComma "," syn match awkComment "#.*" contains=@Spell,awkTodo syn match awkLineSkip "\\$" " Highlight array element's (recursive arrays allowed). " Keeps nested array names' separate from normal array elements. " Keeps numbers separate from normal array elements (variables). syn match awkArrayArray contained "[^][, \t]\+\["me=e-1 syn match awkArrayElement contained "[^][, \t]\+" syn region awkArray transparent start="\[" end="\]" contains=awkArray,awkArrayElement,awkArrayArray,awkNumber,awkFloat " 10 should be enough. " (for the few instances where it would be more than "oneline") syn sync ccomment awkArray maxlines=10 " Define the default highlighting. hi def link awkConditional Conditional hi def link awkFunction Function hi def link awkRepeat Repeat hi def link awkStatement Statement hi def link awkString String hi def link awkSpecialPrintf Special hi def link awkSpecialCharacter Special hi def link awkSearch String hi def link awkBrackets awkRegExp hi def link awkBrktRegExp awkNestRegExp hi def link awkCharClass awkNestRegExp hi def link awkNestRegExp Keyword hi def link awkRegExp Special hi def link awkNumber Number hi def link awkFloat Float hi def link awkFileIO Special hi def link awkOperator Special hi def link awkExpression Special hi def link awkBoolLogic Special hi def link awkPatterns Special hi def link awkVariables Special hi def link awkFieldVars Special hi def link awkLineSkip Special hi def link awkSemicolon Special hi def link awkComma Special hi def link awkIdentifier Identifier hi def link awkComment Comment hi def link awkTodo Todo " Change this if you want nested array names to be highlighted. hi def link awkArrayArray awkArray hi def link awkArrayElement Special hi def link awkParenError awkError hi def link awkInParen awkError hi def link awkError Error let b:current_syntax = "awk" let &cpo = s:cpo_save unlet s:cpo_save " vim: ts=8