@@ -69,6 +69,10 @@ let s:opprec[s:NODE_ENV] = 9
69
69
let s: opprec [s: NODE_REG ] = 9
70
70
" vint: +ProhibitUsingUndeclaredVariable
71
71
72
+ function ! s: Err (msg, pos) abort
73
+ return printf (' vimlparser: pycompiler: %s: line %d col %d' , a: msg , a: pos .lnum, a: pos .col )
74
+ endfunction
75
+
72
76
" Reserved Python keywords (dict for faster lookup).
73
77
let s: reserved_keywords = {
74
78
\ ' False' : 1 ,
@@ -673,27 +677,33 @@ function s:PythonCompiler.compile_sequalcs(node)
673
677
endfunction
674
678
675
679
function s: PythonCompiler .compile_match (node)
676
- return printf (' viml_eqreg(%s, %s)' , self .compile (a: node .left ), self .compile (a: node .right ))
680
+ let right = s: compile_regpat_node (a: node .right )
681
+ return printf (' viml_eqreg(%s, %s)' , self .compile (a: node .left ), right )
677
682
endfunction
678
683
679
684
function s: PythonCompiler .compile_matchci (node)
680
- return printf (' viml_eqregq(%s, %s)' , self .compile (a: node .left ), self .compile (a: node .right ))
685
+ let right = s: compile_regpat_node (a: node .right )
686
+ return printf (' viml_eqregq(%s, %s)' , self .compile (a: node .left ), right )
681
687
endfunction
682
688
683
689
function s: PythonCompiler .compile_matchcs (node)
684
- return printf (' viml_eqregh(%s, %s)' , self .compile (a: node .left ), self .compile (a: node .right ))
690
+ let right = s: compile_regpat_node (a: node .right )
691
+ return printf (' viml_eqregh(%s, %s)' , self .compile (a: node .left ), right )
685
692
endfunction
686
693
687
694
function s: PythonCompiler .compile_nomatch (node)
688
- return printf (' not viml_eqreg(%s, %s)' , self .compile (a: node .left ), self .compile (a: node .right ))
695
+ let right = s: compile_regpat_node (a: node .right )
696
+ return printf (' not viml_eqreg(%s, %s)' , self .compile (a: node .left ), right )
689
697
endfunction
690
698
691
699
function s: PythonCompiler .compile_nomatchci (node)
692
- return printf (' not viml_eqregq(%s, %s, flags=re.IGNORECASE)' , self .compile (a: node .left ), self .compile (a: node .right ))
700
+ let right = s: compile_regpat_node (a: node .right )
701
+ return printf (' not viml_eqregq(%s, %s, flags=re.IGNORECASE)' , self .compile (a: node .left ), right )
693
702
endfunction
694
703
695
704
function s: PythonCompiler .compile_nomatchcs (node)
696
- return printf (' not viml_eqregh(%s, %s)' , self .compile (a: node .left ), self .compile (a: node .right ))
705
+ let right = s: compile_regpat_node (a: node .right )
706
+ return printf (' not viml_eqregh(%s, %s)' , self .compile (a: node .left ), right )
697
707
endfunction
698
708
699
709
function s: PythonCompiler .compile_is (node)
@@ -879,6 +889,85 @@ function s:PythonCompiler.compile_op2(node, op)
879
889
endfunction
880
890
881
891
892
+ let s: pat_vim2py = {
893
+ \ ' [0-9a-zA-Z]' : ' [0-9a-zA-Z]' ,
894
+ \ ' [@*!=><&~#]' : ' [@*!=><&~#]' ,
895
+ \ ' \<ARGOPT\>' : ' \bARGOPT\b' ,
896
+ \ ' \<BANG\>' : ' \bBANG\b' ,
897
+ \ ' \<EDITCMD\>' : ' \bEDITCMD\b' ,
898
+ \ ' \<NOTRLCOM\>' : ' \bNOTRLCOM\b' ,
899
+ \ ' \<TRLBAR\>' : ' \bTRLBAR\b' ,
900
+ \ ' \<USECTRLV\>' : ' \bUSECTRLV\b' ,
901
+ \ ' \<USERCMD\>' : ' \bUSERCMD\b' ,
902
+ \ ' \<\(XFILE\|FILES\|FILE1\)\>' : ' \b(XFILE|FILES|FILE1)\b' ,
903
+ \ ' \S' : ' \S' ,
904
+ \ ' \a' : ' [A-Za-z]' ,
905
+ \ ' \d' : ' \d' ,
906
+ \ ' \h' : ' [A-Za-z_]' ,
907
+ \ ' \s' : ' \s' ,
908
+ \ ' \v^d%[elete][lp]$' : ' ^d(elete|elet|ele|el|e)[lp]$' ,
909
+ \ ' \v^s%(c[^sr][^i][^p]|g|i[^mlg]|I|r[^e])' :
910
+ \ ' ^s(c[^sr][^i][^p]|g|i[^mlg]|I|r[^e])' ,
911
+ \ ' \w' : ' [0-9A-Za-z_]' ,
912
+ \ ' \w\|[:#]' : ' [0-9A-Za-z_]|[:#]' ,
913
+ \ ' \x' : ' [0-9A-Fa-f]' ,
914
+ \ ' ^++' : ' ^\+\+' ,
915
+ \ ' ^++bad=\(keep\|drop\|.\)\>' : ' ^\+\+bad=(keep|drop|.)\b' ,
916
+ \ ' ^++bad=drop' : ' ^\+\+bad=drop' ,
917
+ \ ' ^++bad=keep' : ' ^\+\+bad=keep' ,
918
+ \ ' ^++bin\>' : ' ^\+\+bin\b' ,
919
+ \ ' ^++edit\>' : ' ^\+\+edit\b' ,
920
+ \ ' ^++enc=\S' : ' ^\+\+enc=\S' ,
921
+ \ ' ^++encoding=\S' : ' ^\+\+encoding=\S' ,
922
+ \ ' ^++ff=\(dos\|unix\|mac\)\>' : ' ^\+\+ff=(dos|unix|mac)\b' ,
923
+ \ ' ^++fileformat=\(dos\|unix\|mac\)\>' :
924
+ \ ' ^\+\+fileformat=(dos|unix|mac)\b' ,
925
+ \ ' ^++nobin\>' : ' ^\+\+nobin\b' ,
926
+ \ ' ^[A-Z]' : ' ^[A-Z]' ,
927
+ \ ' ^\$\w\+' : ' ^\$[0-9A-Za-z_]+' ,
928
+ \ ' ^\(!\|global\|vglobal\)$' : ' ^(!|global|vglobal)$' ,
929
+ \ ' ^\(WHILE\|FOR\)$' : ' ^(WHILE|FOR)$' ,
930
+ \ ' ^\(vimgrep\|vimgrepadd\|lvimgrep\|lvimgrepadd\)$' :
931
+ \ ' ^(vimgrep|vimgrepadd|lvimgrep|lvimgrepadd)$' ,
932
+ \ ' ^\d' : ' ^\d' ,
933
+ \ ' ^\h' : ' ^[A-Za-z_]' ,
934
+ \ ' ^\s' : ' ^\s' ,
935
+ \ ' ^\s*\\' : ' ^\s*\\' ,
936
+ \ ' ^[ \t]$' : ' ^[ \t]$' ,
937
+ \ ' ^[A-Za-z]$' : ' ^[A-Za-z]$' ,
938
+ \ ' ^[0-9A-Za-z]$' : ' ^[0-9A-Za-z]$' ,
939
+ \ ' ^[0-9]$' : ' ^[0-9]$' ,
940
+ \ ' ^[0-9A-Fa-f]$' : ' ^[0-9A-Fa-f]$' ,
941
+ \ ' ^[0-9A-Za-z_]$' : ' ^[0-9A-Za-z_]$' ,
942
+ \ ' ^[A-Za-z_]$' : ' ^[A-Za-z_]$' ,
943
+ \ ' ^[0-9A-Za-z_:#]$' : ' ^[0-9A-Za-z_:#]$' ,
944
+ \ ' ^[A-Za-z_][0-9A-Za-z_]*$' : ' ^[A-Za-z_][0-9A-Za-z_]*$' ,
945
+ \ ' ^[A-Z]$' : ' ^[A-Z]$' ,
946
+ \ ' ^[a-z]$' : ' ^[a-z]$' ,
947
+ \ ' ^[vgslabwt]:$\|^\([vgslabwt]:\)\?[A-Za-z_][0-9A-Za-z_#]*$' :
948
+ \ ' ^[vgslabwt]:$|^([vgslabwt]:)?[A-Za-z_][0-9A-Za-z_#]*$' ,
949
+ \ ' ^[0-7]$' : ' ^[0-7]$' ,
950
+ \ ' ^[0-9A-Fa-f][0-9A-Fa-f]$' : ' ^[0-9A-Fa-f][0-9A-Fa-f]$' ,
951
+ \ ' ^\.[0-9A-Fa-f]$' : ' ^\.[0-9A-Fa-f]$' ,
952
+ \ ' ^[0-9A-Fa-f][^0-9A-Fa-f]$' : ' ^[0-9A-Fa-f][^0-9A-Fa-f]$' ,
953
+ \}
954
+
955
+ function ! s: compile_regpat_node (node) abort
956
+ " vint: -ProhibitUsingUndeclaredVariable
957
+ if a: node .type !=# s: NODE_STRING
958
+ " vint: +ProhibitUsingUndeclaredVariable
959
+ throw s: Err (printf (' expected regexp string node, but got node.type = %d' , a: node .type ), a: node .pos)
960
+ endif
961
+ if a: node .value[0 ] !=# " '"
962
+ throw s: Err (' must use single quote' , a: node .pos)
963
+ endif
964
+ let vimpat = substitute (a: node .value[1 :-2 ], " ''" , " '" , ' g' )
965
+ if ! has_key (s: pat_vim2py , vimpat)
966
+ throw s: Err (printf (' the pattern does not exist: %s' , vimpat), a: node .pos)
967
+ endif
968
+ return ' r"' . s: pat_vim2py [vimpat] . ' "'
969
+ endfunction
970
+
882
971
let s: viml_builtin_functions = map (copy (s: VimLParser .builtin_functions), ' v:val.name' )
883
972
884
973
let s: script_dir = expand (' <sfile>:h' )
0 commit comments