File Coverage

blib/lib/App/Dochazka/CLI/TokenMap.pm
Criterion Covered Total %
statement 11 11 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 15 15 100.0


line stmt bran cond sub pod time code
1             # *************************************************************************
2             # Copyright (c) 2014-2016, SUSE LLC
3             #
4             # All rights reserved.
5             #
6             # Redistribution and use in source and binary forms, with or without
7             # modification, are permitted provided that the following conditions are met:
8             #
9             # 1. Redistributions of source code must retain the above copyright notice,
10             # this list of conditions and the following disclaimer.
11             #
12             # 2. Redistributions in binary form must reproduce the above copyright
13             # notice, this list of conditions and the following disclaimer in the
14             # documentation and/or other materials provided with the distribution.
15             #
16             # 3. Neither the name of SUSE LLC nor the names of its contributors may be
17             # used to endorse or promote products derived from this software without
18             # specific prior written permission.
19             #
20             # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21             # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22             # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23             # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24             # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25             # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26             # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27             # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28             # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29             # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30             # POSSIBILITY OF SUCH DAMAGE.
31             # *************************************************************************
32             #
33             # Token map
34             #
35             package App::Dochazka::CLI::TokenMap;
36              
37 20     20   304 use 5.012;
  20         42  
38 20     20   66 use strict;
  20         21  
  20         322  
39 20     20   54 use warnings;
  20         22  
  20         435  
40              
41 20     20   63 use Exporter qw( import );
  20         22  
  20         7234  
42              
43             our @EXPORT_OK = qw( $completion_map $token_map );
44              
45              
46              
47             =head1 NAME
48              
49             App::Dochazka::CLI::TokenMap - Token map
50              
51              
52              
53             =head1 PACKAGE VARIABLES
54              
55             =over
56              
57             =item C<< $token_map >>
58              
59             Maps tokens to regular expression "strings". These strings are just the
60             "business end" - the final regular expression is generated from each string in
61             L.
62              
63             Whatever information you need to get out of the token needs to be in
64             parentheses. If the token is just a reserved word from which no information
65             need be extracted, just put the entire thing in parentheses.
66              
67             Note that the regex comparison that takes place in
68             L uses the 'i' modifier for a case-insensitive
69             comparison.
70              
71             =back
72              
73             =cut
74              
75             our $token_map = {
76             # ACTIVE => '(active)',
77             ACTIVITY => '(activi\S*)',
78             ADD => '(add\S*)',
79             # ADMIN => '(adm\S*)',
80             AID => '(aid\S*)',
81             ALL => '(all\S*)',
82             # APRIL => '(apr\S*)',
83             # AUGUST => '(aug\S*)',
84             BUGREPORT => '(bug\S*)',
85             CLEAR => '(cle\S*)',
86             CODE => '(cod\S*)',
87             COMMIT => '(comm\S*)',
88             COMPONENT => '(comp\S*)',
89             CONFIGINFO => '(conf\S*)',
90             COOKIEJAR => '(coo\S*)',
91             CORE => '(cor\S*)',
92             COUNT => '(cou\S*)',
93             CURRENT => '(cur\S*)',
94             DATE => '(date)',
95             DATELIST => '(datel\S*)',
96             DBSTATUS => '(dbs\S*)',
97             # DECEMBER => '(dec\S*)',
98             DELETE => '(del\S*)',
99             DISABLED => '(dis\S*)',
100             DOCU => '(doc\S*)',
101             DRY_RUN => '(dry\S*)',
102             DUMP => '(dum\S*)',
103             ECHO => '(ech\S*)',
104             EFFECTIVE => '(eff\S*)',
105             EID => '(eid[^\s=]*)',
106             EMPLOYEE => '(emp[^\s=]*)',
107             EMPLOYEE_SPEC => '((emp|sec_id|nick|eid)\S*=([%[:alnum:]_][%[:alnum:]_-]*)*)',
108             EXIT => '(((exi)|(qui)|(\\\\q))\S*)',
109             # FEBRUARY => '(feb\S*)',
110             FETCH => '(fet\S*)',
111             FILLUP => '(fil\S*)',
112             FORBIDDEN => '(for\S*)',
113             # FRIDAY => '(fri\S*)', RESERVED BY _DOW
114             FULLNAME => '(ful\S*)',
115             GENERATE => '(gen\S*)',
116             GET => '(get\S*)',
117             HISTORY => '(his\S*)',
118             HOLIDAY => '(hol\S*)',
119             HTML => '(htm\S*)',
120             IID => '(iid\S*)',
121             IMPORT => '(imp\S*)',
122             # INACTIVE => '(ina\S*)',
123             INSERT => '(ins\S*)',
124             INTERVAL => '(int\S*)',
125             # JANUARY => '(jan\S*)',
126             # JULY => '(jul\S*)',
127             # JUNE => '(jun\S*)',
128             LDAP => '(lda\S*)',
129             LID => '(lid\S*)',
130             LIST => '(lis\S*)',
131             LOCK => '(loc\S*)',
132             # MARCH => '(mar\S*)',
133             # MAY => '(may\S*)',
134             MEMORY => '(mem\S*)',
135             META => '(met\S*)',
136             # MONDAY => '(mon\S*)', RESERVED BY _DOW
137             NEW => '(new\S*)',
138             NICK => '(nic[^\s=]*)',
139             NOOP => '(noo\S*)',
140             # NOVEMBER => '(nov\S*)',
141             # OCTOBER => '(oct\S*)',
142             PARAM => '(par\S*)',
143             # PASSERBY => '(passe\S*)',
144             PASSWORD => '(passw\S*)',
145             PATH => '(pat\S*)',
146             PHID => '(phi[^\s=]*)',
147             PHISTORY_SPEC => 'phi[^\s=]*=(\d+)',
148             POD => '(pod\S*)',
149             POST => '(pos\S*)',
150             PRIV => '(pri\S*)',
151             PRIV_SPEC => '((active)|(adm\S*)|(ina\S*)|(passe\S*))',
152             PROFILE => '(prof\S*)',
153             PROMPT => '(prom\S*)',
154             PUT => '(put\S*)',
155             REMARK => '(rem\S*)',
156             REPORT => '(rep\S*)',
157             # SATURDAY => '(sat\S*)', RESERVED BY _DOW
158             SCHEDULE => '(sch\S*)',
159             SCHEDULE_SPEC => '((sco|sid)[^\s=]*=([%[:alnum:]_][%[:alnum:]_-]*)*)',
160             SCODE => '(sco[^\s=]*)',
161             SEARCH => '(sea\S*)',
162             SEC_ID => '(sec[^\s=]*)',
163             SELF => '(sel\S*)',
164             # SEPTEMBER => '(sep\S*)',
165             SESSION => '(ses\S*)',
166             SET => '(set\S*)',
167             SHID => '(shi[^\s=]*)',
168             SHISTORY_SPEC => 'shi[^\s=]*=(\d+)',
169             SHOW => '(sho\S*)',
170             SID => '(sid[^\s=]*)',
171             SITE => '(sit\S*)',
172             # SUNDAY => '(sun\S*)', RESERVED BY _DOW
173             SUMMARY => '(sum\S*)',
174             SUPERVISOR => '(sup\S*)',
175             TEAM => '(tea\S*)',
176             TEXT => '(tex\S*)',
177             # THURSDAY => '(thu\S*)', RESERVED BY _DOW
178             # TODAY => '(tod\S*)', RESERVED BY _TIMESTAMP
179             # TOMORROW => '(tom\S*)', RESERVED BY _TIMESTAMP
180             # TUESDAY => '(tue\S*)', RESERVED BY _DOW
181             VERSION => '(ver\S*)',
182             # WEDNESDAY => '(wed\S*)', RESERVED BY _DOW
183             WHOAMI => '(who\S*)',
184             # YESTERDAY => '(yes\S*)', RESERVED BY _TIMESTAMP
185             _DATE => '(((\d{2,4}-)?\d{1,2}-\d{1,2})|(tod\S*)|(tom\S*)|(yes\S*)|([\+\-]\d{1,3}))',
186             _DOCU => '(([^\{\s]+)|(\"[^\"]*\"))',
187             _DOW => '((mon\S*)|(tue\S*)|(wed\S*)|(thu\S*)|(fri\S*)|(sat\S*)|(sun\S*))',
188             _HYPHEN => '(-)',
189             _JSON => '(\{[^\{]*\})',
190             _MONTH => '((jan\S*)|(feb\S*)|(mar\S*)|(apr\S*)|(may\S*)|(jun\S*)|(jul\S*)|(aug\S*)|(sep\S*)|(oct\S*)|(nov\S*)|(dec\S*))',
191             _NUM => '([123456789][0123456789]*)',
192             _PATH => '([[:alnum:]_.][[:alnum:]_/.-]+)',
193             _TERM => '([%[:alnum:]_][%[:alnum:]_-]*)',
194             _TIME => '(\d{1,2}:\d{1,2}(:\d{1,2})?)',
195             _TIMERANGE => '(\d{1,2}:\d{1,2}-\d{1,2}:\d{1,2})',
196             _TIMESTAMP => '(\"?(\d{2,4}-)?\d{1,2}-\d{1,2}(\s+\d{1,2}:\d{1,2}(:\d{1,2})?)?\"?)',
197             _TIMESTAMPDEPR => '(\"?((?((\d{2,4}-)?\d{1,2}-\d{1,2})|(tod\S*)|(tom\S*)|(yes\S*))\s+)?(?\d{1,2}:\d{1,2}(:\d{1,2})?)\"?)',
198             _TSRANGE => '([\[\(][^\[\(\]\)]*,[^\[\(]*[\]\)])',
199             };
200              
201             our $completion_map = {
202             active => 'PRIV_SPEC',
203             activity => 'ACTIVITY',
204             add => 'ADD',
205             admin => 'PRIV_SPEC',
206             aid => 'AID',
207             all => 'ALL',
208             april => '_MONTH',
209             august => '_MONTH',
210             bugreport => 'BUGREPORT',
211             clear => 'CLEAR',
212             code => 'CODE',
213             commit => 'COMMIT',
214             component => 'COMPONENT',
215             configinfo => 'CONFIGINFO',
216             cookiejar => 'COOKIEJAR',
217             core => 'CORE',
218             count => 'COUNT',
219             current => 'CURRENT',
220             date => 'DATE',
221             datelist => 'DATELIST',
222             dbstatus => 'DBSTATUS',
223             december => '_MONTH',
224             delete => 'DELETE',
225             disabled => 'DISABLED',
226             docu => 'DOCU',
227             dry_run => 'DRY_RUN',
228             dump => 'DUMP',
229             echo => 'ECHO',
230             effective => 'EFFECTIVE',
231             eid => 'EID',
232             'eid=' => 'EMPLOYEE_SPEC',
233             employee => 'EMPLOYEE',
234             'employee=' => 'EMPLOYEE_SPEC',
235             exit => 'EXIT',
236             february => '_MONTH',
237             fetch => 'FETCH',
238             fillup => 'FILLUP',
239             forbidden => 'FORBIDDEN',
240             friday => '_DOW',
241             fullname => 'FULLNAME',
242             generate => 'GENERATE',
243             get => 'GET',
244             history => 'HISTORY',
245             holiday => 'HOLIDAY',
246             html => 'HTML',
247             iid => 'IID',
248             import => 'IMPORT',
249             inactive => 'PRIV_SPEC',
250             insert => 'INSERT',
251             interval => 'INTERVAL',
252             january => '_MONTH',
253             july => '_MONTH',
254             june => '_MONTH',
255             ldap => 'LDAP',
256             lid => 'LID',
257             list => 'LIST',
258             lock => 'LOCK',
259             march => '_MONTH',
260             may => '_MONTH',
261             memory => 'MEMORY',
262             meta => 'META',
263             monday => '_DOW',
264             new => 'NEW',
265             nick => 'NICK',
266             'nick=' => 'EMPLOYEE_SPEC',
267             noop => 'NOOP',
268             november => '_MONTH',
269             october => '_MONTH',
270             param => 'PARAM',
271             passerby => 'PRIV_SPEC',
272             password => 'PASSWORD',
273             path => 'PATH',
274             phid => 'PHID',
275             'phid=' => 'PHISTORY_SPEC',
276             pod => 'POD',
277             post => 'POST',
278             priv => 'PRIV',
279             profile => 'PROFILE',
280             prompt => 'PROMPT',
281             put => 'PUT',
282             quit => 'QUIT',
283             remark => 'REMARK',
284             report => 'REPORT',
285             saturday => '_DOW',
286             schedule => 'SCHEDULE',
287             scode => 'SCODE',
288             'scode=' => 'SCHEDULE_SPEC',
289             search => 'SEARCH',
290             sec_id => 'SEC_ID',
291             'sec_id=' => 'EMPLOYEE_SPEC',
292             self => 'SELF',
293             september => '_MONTH',
294             session => 'SESSION',
295             set => 'SET',
296             shid => 'SHID',
297             'shid=' => 'SHISTORY_SPEC',
298             show => 'SHOW',
299             sid => 'SID',
300             'sid=' => 'SCHEDULE_SPEC',
301             site => 'SITE',
302             sunday => '_DOW',
303             summary => 'SUMMARY',
304             supervisor => 'SUPERVISOR',
305             team => 'TEAM',
306             text => 'TEXT',
307             thursday => '_DOW',
308             today => '_TIMESTAMP',
309             tomorrow => '_TIMESTAMP',
310             tuesday => '_DOW',
311             version => 'VERSION',
312             wednesday => '_DOW',
313             whoami => 'WHOAMI',
314             yesterday => '_TIMESTAMP',
315             };
316              
317             1;