Mercurial > vim
annotate runtime/plugin/logiPat.vim @ 20596:4ec94bcaef86
Added tag v8.2.0851 for changeset 3609e842f8229ebc52cbb5e172eabcf75be81e2b
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 30 May 2020 20:00:04 +0200 |
parents | b73f9ed65072 |
children | 02bd0fe77c68 |
rev | line source |
---|---|
8869
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
1 " LogiPat: Boolean logical pattern matcher |
6855
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
2 " Author: Charles E. Campbell |
8869
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
3 " Date: Apr 04, 2016 |
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
4 " Version: 4 |
6855
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
5 " Purpose: to do Boolean-logic based regular expression pattern matching |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
6 " Copyright: Copyright (C) 1999-2011 Charles E. Campbell {{{1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
7 " Permission is hereby granted to use and distribute this code, |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
8 " with or without modifications, provided that this copyright |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
9 " notice is copied with it. Like most anything else that's free, |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
10 " LogiPat.vim is provided *as is* and comes with no warranty |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
11 " of any kind, either expressed or implied. By using this |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
12 " plugin, you agree that in no event will the copyright |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
13 " holder be liable for any damages resulting from the use |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
14 " of this software. |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
15 " |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
16 " Usage: {{{1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
17 " :LogiPat ... |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
18 " |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
19 " Boolean logic supported: |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
20 " () grouping operators |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
21 " ! not the following pattern |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
22 " | logical or |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
23 " & logical and |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
24 " "..pattern.." |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
25 " Example: {{{1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
26 " :LogiPat !("january"|"february") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
27 " would match all strings not containing the strings january |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
28 " or february |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
29 " GetLatestVimScripts: 1290 1 :AutoInstall: LogiPat.vim |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
30 " |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
31 " Behold, you will conceive in your womb, and bring forth a son, {{{1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
32 " and will call his name Jesus. He will be great, and will be |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
33 " called the Son of the Most High. The Lord God will give him the |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
34 " throne of his father, David, and he will reign over the house of |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
35 " Jacob forever. There will be no end to his kingdom. (Luke 1:31-33 WEB) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
36 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
37 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
38 " Load Once: {{{1 |
8869
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
39 if &cp || exists("loaded_logiPat") |
6855
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
40 finish |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
41 endif |
8869
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
42 let g:loaded_logiPat = "v4" |
6855
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
43 let s:keepcpo = &cpo |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
44 set cpo&vim |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
45 "DechoRemOn |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
46 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
47 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
48 " Public Interface: {{{1 |
8869
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
49 com! -nargs=* LogiPat call LogiPat(<q-args>,1) |
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
50 sil! com -nargs=* LP call LogiPat(<q-args>,1) |
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
51 sil! com -nargs=* LPR call LogiPat(<q-args>,1,"r") |
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
52 com! -nargs=+ LPE echomsg LogiPat(<q-args>) |
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
53 com! -nargs=+ LogiPatFlags let s:LogiPatFlags="<args>" |
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
54 sil! com -nargs=+ LPF let s:LogiPatFlags="<args>" |
6855
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
55 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
56 " ===================================================================== |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
57 " Functions: {{{1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
58 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
59 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
60 " LogiPat: this function interprets the boolean-logic pattern {{{2 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
61 fun! LogiPat(pat,...) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
62 " call Dfunc("LogiPat(pat<".a:pat.">)") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
63 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
64 " LogiPat(pat,dosearch) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
65 if a:0 > 0 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
66 let dosearch= a:1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
67 else |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
68 let dosearch= 0 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
69 endif |
8869
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
70 if a:0 >= 3 |
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
71 let s:LogiPatFlags= a:3 |
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
72 endif |
6855
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
73 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
74 let s:npatstack = 0 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
75 let s:nopstack = 0 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
76 let s:preclvl = 0 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
77 let expr = a:pat |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
78 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
79 " Lexer/Parser |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
80 while expr != "" |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
81 " call Decho("expr<".expr.">") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
82 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
83 if expr =~ '^"' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
84 " push a Pattern; accept "" as a single " in the pattern |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
85 let expr = substitute(expr,'^\s*"','','') |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
86 let pat = substitute(expr,'^\(\%([^"]\|\"\"\)\{-}\)"\([^"].*$\|$\)','\1','') |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
87 let pat = substitute(pat,'""','"','g') |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
88 let expr = substitute(expr,'^\(\%([^"]\|\"\"\)\{-}\)"\([^"].*$\|$\)','\2','') |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
89 let expr = substitute(expr,'^\s*','','') |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
90 " call Decho("pat<".pat."> expr<".expr.">") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
91 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
92 call s:LP_PatPush('.*'.pat.'.*') |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
93 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
94 elseif expr =~ '^[!()|&]' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
95 " push an operator |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
96 let op = strpart(expr,0,1) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
97 let expr = strpart(expr,strlen(op)) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
98 " allow for those who can't resist doubling their and/or operators |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
99 if op =~ '[|&]' && expr[0] == op |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
100 let expr = strpart(expr,strlen(op)) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
101 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
102 call s:LP_OpPush(op) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
103 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
104 elseif expr =~ '^\s' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
105 " skip whitespace |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
106 let expr= strpart(expr,1) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
107 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
108 else |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
109 echoerr "operator<".strpart(expr,0,1)."> not supported (yet)" |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
110 let expr= strpart(expr,1) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
111 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
112 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
113 endwhile |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
114 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
115 " Final Execution |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
116 call s:LP_OpPush('Z') |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
117 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
118 let result= s:LP_PatPop(1) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
119 " call Decho("result=".result) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
120 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
121 " sanity checks and cleanup |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
122 if s:npatstack > 0 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
123 echoerr s:npatstack." patterns left on stack!" |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
124 let s:npatstack= 0 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
125 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
126 if s:nopstack > 0 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
127 echoerr s:nopstack." operators left on stack!" |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
128 let s:nopstack= 0 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
129 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
130 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
131 " perform the indicated search |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
132 if dosearch |
8869
b73f9ed65072
commit https://github.com/vim/vim/commit/939a1abe935a539f2d4c90a56cb0682cbaf3bbb0
Christian Brabandt <cb@256bit.org>
parents:
6855
diff
changeset
|
133 if exists("s:LogiPatFlags") && s:LogiPatFlags != "" |
6855
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
134 " call Decho("search(result<".result."> LogiPatFlags<".s:LogiPatFlags.">)") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
135 call search(result,s:LogiPatFlags) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
136 else |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
137 " call Decho("search(result<".result.">)") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
138 call search(result) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
139 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
140 let @/= result |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
141 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
142 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
143 " call Dret("LogiPat ".result) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
144 return result |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
145 endfun |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
146 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
147 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
148 " s:String: Vim6.4 doesn't have string() {{{2 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
149 func! s:String(str) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
150 return "'".escape(a:str, '"')."'" |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
151 endfunc |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
152 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
153 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
154 " LP_PatPush: {{{2 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
155 fun! s:LP_PatPush(pat) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
156 " call Dfunc("LP_PatPush(pat<".a:pat.">)") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
157 let s:npatstack = s:npatstack + 1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
158 let s:patstack_{s:npatstack} = a:pat |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
159 " call s:StackLook("patpush") "Decho |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
160 " call Dret("LP_PatPush : npatstack=".s:npatstack) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
161 endfun |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
162 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
163 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
164 " LP_PatPop: pop a number/variable from LogiPat's pattern stack {{{2 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
165 fun! s:LP_PatPop(lookup) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
166 " call Dfunc("LP_PatPop(lookup=".a:lookup.")") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
167 if s:npatstack > 0 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
168 let ret = s:patstack_{s:npatstack} |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
169 let s:npatstack = s:npatstack - 1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
170 else |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
171 let ret= "---error---" |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
172 echoerr "(LogiPat) invalid expression" |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
173 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
174 " call s:StackLook("patpop") "Decho |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
175 " call Dret("LP_PatPop ".ret) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
176 return ret |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
177 endfun |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
178 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
179 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
180 " LP_OpPush: {{{2 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
181 fun! s:LP_OpPush(op) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
182 " call Dfunc("LP_OpPush(op<".a:op.">)") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
183 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
184 " determine new operator's precedence level |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
185 if a:op == '(' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
186 let s:preclvl= s:preclvl + 10 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
187 let preclvl = s:preclvl |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
188 elseif a:op == ')' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
189 let s:preclvl= s:preclvl - 10 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
190 if s:preclvl < 0 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
191 let s:preclvl= 0 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
192 echoerr "too many )s" |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
193 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
194 let preclvl= s:preclvl |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
195 elseif a:op =~ '|' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
196 let preclvl= s:preclvl + 2 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
197 elseif a:op =~ '&' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
198 let preclvl= s:preclvl + 4 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
199 elseif a:op == '!' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
200 let preclvl= s:preclvl + 6 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
201 elseif a:op == 'Z' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
202 let preclvl= -1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
203 else |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
204 echoerr "expr<".expr."> not supported (yet)" |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
205 let preclvl= s:preclvl |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
206 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
207 " call Decho("new operator<".a:op."> preclvl=".preclvl) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
208 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
209 " execute higher-precdence operators |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
210 " call Decho("execute higher-precedence operators") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
211 call s:LP_Execute(preclvl) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
212 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
213 " push new operator onto operator-stack |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
214 " call Decho("push new operator<".a:op."> onto stack with preclvl=".preclvl." at nopstack=".(s:nopstack+1)) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
215 if a:op =~ '!' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
216 let s:nopstack = s:nopstack + 1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
217 let s:opprec_{s:nopstack} = preclvl |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
218 let s:opstack_{s:nopstack} = a:op |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
219 elseif a:op =~ '|' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
220 let s:nopstack = s:nopstack + 1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
221 let s:opprec_{s:nopstack} = preclvl |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
222 let s:opstack_{s:nopstack} = a:op |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
223 elseif a:op == '&' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
224 let s:nopstack = s:nopstack + 1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
225 let s:opprec_{s:nopstack} = preclvl |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
226 let s:opstack_{s:nopstack} = a:op |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
227 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
228 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
229 " call s:StackLook("oppush") "Decho |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
230 " call Dret("LP_OpPush : s:preclvl=".s:preclvl) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
231 endfun |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
232 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
233 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
234 " LP_Execute: execute operators from opstack using pattern stack {{{2 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
235 fun! s:LP_Execute(preclvl) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
236 " call Dfunc("LP_Execute(preclvl=".a:preclvl.") npatstack=".s:npatstack." nopstack=".s:nopstack) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
237 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
238 " execute all higher precedence operators |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
239 while s:nopstack > 0 && a:preclvl < s:opprec_{s:nopstack} |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
240 let op= s:opstack_{s:nopstack} |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
241 " call Decho("op<".op."> nop=".s:nopstack." [preclvl=".a:preclvl."] < [opprec_".s:nopstack."=".s:opprec_{s:nopstack}."]") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
242 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
243 let s:nopstack = s:nopstack - 1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
244 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
245 if op == '!' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
246 let n1= s:LP_PatPop(1) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
247 call s:LP_PatPush(s:LP_Not(n1)) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
248 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
249 elseif op == '|' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
250 let n1= s:LP_PatPop(1) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
251 let n2= s:LP_PatPop(1) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
252 call s:LP_PatPush(s:LP_Or(n2,n1)) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
253 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
254 elseif op =~ '&' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
255 let n1= s:LP_PatPop(1) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
256 let n2= s:LP_PatPop(1) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
257 call s:LP_PatPush(s:LP_And(n2,n1)) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
258 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
259 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
260 " call s:StackLook("execute") "Decho |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
261 endwhile |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
262 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
263 " call Dret("LP_Execute") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
264 endfun |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
265 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
266 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
267 " LP_Not: writes a logical-not for a pattern {{{2 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
268 fun! s:LP_Not(pat) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
269 " call Dfunc("LP_Not(pat<".a:pat.">)") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
270 if a:pat =~ '^\.\*' && a:pat =~ '\.\*$' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
271 let pat= substitute(a:pat,'^\.\*\(.*\)\.\*$','\1','') |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
272 let ret= '^\%(\%('.pat.'\)\@!.\)*$' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
273 else |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
274 let ret= '^\%(\%('.a:pat.'\)\@!.\)*$' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
275 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
276 " call Dret("LP_Not ".ret) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
277 return ret |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
278 endfun |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
279 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
280 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
281 " LP_Or: writes a logical-or branch using two patterns {{{2 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
282 fun! s:LP_Or(pat1,pat2) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
283 " call Dfunc("LP_Or(pat1<".a:pat1."> pat2<".a:pat2.">)") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
284 let ret= '\%('.a:pat1.'\|'.a:pat2.'\)' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
285 " call Dret("LP_Or ".ret) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
286 return ret |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
287 endfun |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
288 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
289 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
290 " LP_And: writes a logical-and concat using two patterns {{{2 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
291 fun! s:LP_And(pat1,pat2) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
292 " call Dfunc("LP_And(pat1<".a:pat1."> pat2<".a:pat2.">)") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
293 let ret= '\%('.a:pat1.'\&'.a:pat2.'\)' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
294 " call Dret("LP_And ".ret) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
295 return ret |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
296 endfun |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
297 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
298 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
299 " StackLook: {{{2 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
300 fun! s:StackLook(description) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
301 " call Dfunc("StackLook(description<".a:description.">)") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
302 let iop = 1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
303 let ifp = 1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
304 " call Decho("Pattern Operator") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
305 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
306 " print both pattern and operator |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
307 while ifp <= s:npatstack && iop <= s:nopstack |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
308 let fp = s:patstack_{ifp} |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
309 let op = s:opstack_{iop}." (P".s:opprec_{s:nopstack}.')' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
310 let fplen= strlen(fp) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
311 if fplen < 30 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
312 let fp= fp.strpart(" ",1,30-fplen) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
313 endif |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
314 " call Decho(fp.op) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
315 let ifp = ifp + 1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
316 let iop = iop + 1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
317 endwhile |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
318 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
319 " print just pattern |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
320 while ifp <= s:npatstack |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
321 let fp = s:patstack_{ifp} |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
322 " call Decho(fp) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
323 let ifp = ifp + 1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
324 endwhile |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
325 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
326 " print just operator |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
327 while iop <= s:nopstack |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
328 let op = s:opstack_{iop}." (P".s:opprec_{s:nopstack}.')' |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
329 " call Decho(" ".op) |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
330 let iop = iop + 1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
331 endwhile |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
332 " call Dret("StackLook") |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
333 endfun |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
334 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
335 " --------------------------------------------------------------------- |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
336 " Cleanup And Modeline: {{{1 |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
337 let &cpo= s:keepcpo |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
338 unlet s:keepcpo |
ee45d3b0579b
Add the logiPat plugin to the distribution.
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
339 " vim: ts=4 fdm=marker |