Browse Source

replace !(...) and ![...] with ?(...) and ?[...]

adam j hartz 1 year ago
parent
commit
b67f8a31a9
5 changed files with 26 additions and 21 deletions
  1. 1
    1
      takoshell/completers/python.py
  2. 5
    2
      takoshell/lexer.py
  3. 13
    12
      takoshell/parsers/base.py
  4. 6
    5
      takoshell/tokenize.py
  5. 1
    1
      takoshell/tools.py

+ 1
- 1
takoshell/completers/python.py View File

@@ -42,7 +42,7 @@ TAKO_TOKENS = {
42 42
     '/', '//', '%', '**', '|', '&', '~', '^', '>>', '<<', '<', '<=', '>', '>=',
43 43
     '==', '!=', '->', '=', '+=', '-=', '*=', '/=', '%=', '**=', '>>=', '<<=',
44 44
     '&=', '^=', '|=', '//=', ',', ';', ':', '?', '??', '$(', '${', '$[', '..',
45
-    '...', '![', '!(', '@(', '@$(', '@'
45
+    '...', '![', '!(', '@(', '@$(', '@', '?(', '?[',
46 46
 }
47 47
 
48 48
 

+ 5
- 2
takoshell/lexer.py View File

@@ -60,8 +60,7 @@ _op_map = {
60 60
     '&=': 'AMPERSANDEQUAL', '^=': 'XOREQUAL', '|=': 'PIPEEQUAL',
61 61
     '//=': 'DOUBLEDIVEQUAL',
62 62
     # extra tako operators
63
-    '?': 'QUESTION', '??': 'DOUBLE_QUESTION', '@$': 'ATDOLLAR',
64
-    '&': 'AMPERSAND',
63
+    '@$': 'ATDOLLAR', '&': 'AMPERSAND',
65 64
 }
66 65
 for (op, type) in _op_map.items():
67 66
     token_map[(tokenize.OP, op)] = type
@@ -223,6 +222,8 @@ _make_matcher_handler('{', 'LBRACE', True, '}')
223 222
 _make_matcher_handler('$(', 'DOLLAR_LPAREN', False, ')')
224 223
 _make_matcher_handler('$[', 'DOLLAR_LBRACKET', False, ']')
225 224
 _make_matcher_handler('${', 'DOLLAR_LBRACE', True, '}')
225
+_make_matcher_handler('?(', 'QUESTION_LPAREN', False, ')')
226
+_make_matcher_handler('?[', 'QUESTION_LBRACKET', False, ']')
226 227
 _make_matcher_handler('!(', 'BANG_LPAREN', False, ')')
227 228
 _make_matcher_handler('![', 'BANG_LBRACKET', False, ']')
228 229
 _make_matcher_handler('@(', 'AT_LPAREN', True, ')')
@@ -359,6 +360,8 @@ class Lexer(object):
359 360
         'LBRACKET', 'RBRACKET',  # [ ]
360 361
         'LBRACE', 'RBRACE',      # { }
361 362
         'AT_LPAREN',             # @(
363
+        'QUESTION_LPAREN',       # ?(
364
+        'QUESTION_LBRACKET',     # ?[
362 365
         'BANG_LPAREN',           # !(
363 366
         'BANG_LBRACKET',         # ![
364 367
         'DOLLAR_LPAREN',         # $(

+ 13
- 12
takoshell/parsers/base.py View File

@@ -252,7 +252,8 @@ class BaseParser(object):
252 252
                      'for', 'colon', 'import', 'except', 'nonlocal', 'global',
253 253
                      'yield', 'from', 'raise', 'with', 'dollar_lparen',
254 254
                      'dollar_lbrace', 'dollar_lbracket', 'try',
255
-                     'bang_lparen', 'bang_lbracket']
255
+                     'bang_lparen', 'bang_lbracket', 'question_lparen',
256
+                     'question_lbracket']
256 257
         for rule in tok_rules:
257 258
             self._tok_rule(rule)
258 259
 
@@ -279,9 +280,9 @@ class BaseParser(object):
279 280
                  'LSHIFT', 'RSHIFT', 'IOREDIRECT', 'SEARCHPATH', 'INDENT',
280 281
                  'DEDENT', 'LPAREN', 'RPAREN', 'LBRACE', 'RBRACE',
281 282
                  'LBRACKET', 'RBRACKET', 'AT_LPAREN', 'BANG_LPAREN',
282
-                 'BANG_LBRACKET', 'DOLLAR_LPAREN', 'DOLLAR_LBRACE',
283
-                 'DOLLAR_LBRACKET', 'ATDOLLAR_LPAREN', 'AMPERSAND', 'DOLLAR',
284
-                 'DOLLAR_NAME'}
283
+                 'BANG_LBRACKET', 'QUESTION_LPAREN', 'QUESTION_LBRACKET',
284
+                 'DOLLAR_LPAREN', 'DOLLAR_LBRACE', 'DOLLAR_LBRACKET',
285
+                 'ATDOLLAR_LPAREN', 'AMPERSAND', 'DOLLAR', 'DOLLAR_NAME'}
285 286
         ts = '\n                 | '.join(sorted(toks))
286 287
         doc = 'subproc_arg_part : ' + ts + '\n'
287 288
         self.p_subproc_arg_part.__func__.__doc__ = doc
@@ -1792,8 +1793,14 @@ class BaseParser(object):
1792 1793
                 | dollar_lparen_tok subproc RPAREN
1793 1794
                 | bang_lparen_tok subproc RPAREN
1794 1795
                 | bang_lbracket_tok subproc RBRACKET
1796
+                | question_lparen_tok subproc RPAREN
1797
+                | question_lbracket_tok subproc RBRACKET
1795 1798
                 | dollar_lbracket_tok subproc RBRACKET
1796 1799
         """
1800
+        if p[1].value.startswith('!'):
1801
+            print('WARNING: !(...) and ![...] are deprecated (to be removed '
1802
+                  'in a later version).  Use ?(...) and ?[...] instead.',
1803
+                  file=sys.stderr)
1797 1804
         p[0] = self._dollar_rules(p)
1798 1805
 
1799 1806
     def p_string_literal(self, p):
@@ -1879,12 +1886,6 @@ class BaseParser(object):
1879 1886
         """
1880 1887
         p[0] = [p[2]]
1881 1888
 
1882
-    def p_trailer_quest(self, p):
1883
-        """trailer : DOUBLE_QUESTION
1884
-                   | QUESTION
1885
-        """
1886
-        p[0] = [p[1]]
1887
-
1888 1889
     def p_subscriptlist(self, p):
1889 1890
         """subscriptlist : subscript comma_subscript_list_opt comma_opt"""
1890 1891
         p1, p2 = p[1], p[2]
@@ -2142,10 +2143,10 @@ class BaseParser(object):
2142 2143
         elif p1 == '$(':
2143 2144
             p0 = tako_call('__tako_subproc_captured_stdout__', p2,
2144 2145
                             lineno=lineno, col=col)
2145
-        elif p1 == '!(':
2146
+        elif p1 == '!(' or p1 == '?(':
2146 2147
             p0 = tako_call('__tako_subproc_captured_object__', p2,
2147 2148
                             lineno=lineno, col=col)
2148
-        elif p1 == '![':
2149
+        elif p1 == '![' or p1 == '?[':
2149 2150
             p0 = tako_call('__tako_subproc_captured_hiddenobject__', p2,
2150 2151
                             lineno=lineno, col=col)
2151 2152
         elif p1 == '$[':

+ 6
- 5
takoshell/tokenize.py View File

@@ -92,22 +92,22 @@ ATEQUAL = N_TOKENS
92 92
 tok_name[N_TOKENS] = 'ATEQUAL'
93 93
 N_TOKENS += 1
94 94
 _tako_tokens = {
95
-    '?':   'QUESTION',
96 95
     '@=':  'ATEQUAL',
97 96
     '@$':  'ATDOLLAR',
98 97
     '||':  'DOUBLEPIPE',
99 98
     '&&':  'DOUBLEAMPER',
100 99
     '@(':  'ATLPAREN',
100
+    '?(':  'QUESTIONLPAREN',
101
+    '?[':  'QUESTIONLBRACKET',
101 102
     '!(':  'BANGLPAREN',
102 103
     '![':  'BANGLBRACKET',
103 104
     '$(':  'DOLLARLPAREN',
104 105
     '$[':  'DOLLARLBRACKET',
105 106
     '${':  'DOLLARLBRACE',
106
-    '??':  'DOUBLEQUESTION',
107 107
     '@$(': 'ATDOLLARLPAREN',
108 108
 }
109 109
 
110
-additional_parenlevs = frozenset({'@(', '!(', '![', '$(', '$[', '${', '@$('})
110
+additional_parenlevs = frozenset({'@(', '!(', '![', '$(', '$[', '${', '@$(', '?(', '?['})
111 111
 
112 112
 for k, v in _tako_tokens.items():
113 113
     exec('%s = N_TOKENS' % v)
@@ -251,8 +251,9 @@ _redir_check = {'{}>'.format(i) for i in _redir_names}.union(_redir_check)
251 251
 _redir_check = {'{}>>'.format(i) for i in _redir_names}.union(_redir_check)
252 252
 _redir_check = frozenset(_redir_check)
253 253
 Operator = group(r"\*\*=?", r">>=?", r"<<=?", r"!=", r"//=?", r"->",
254
-                 r"@\$\(?", r'\|\|', '&&', r'@\(', r'!\(', r'!\[', r'\$\(',
255
-                 r'\$\[', '\${', r'\?\?', r'\?', AUGASSIGN_OPS, r"~")
254
+                 r"@\$\(?", r'\|\|', '&&', r'@\(', r'!\(', r'!\[', r'\?\(',
255
+                 r'\?\[', r'\$\(', r'\$\[', '\${',
256
+                 AUGASSIGN_OPS, r"~")
256 257
 
257 258
 Bracket = '[][(){}]'
258 259
 Special = group(r'\r?\n', r'\.\.\.', r'[:;.,@]')

+ 1
- 1
takoshell/tools.py View File

@@ -296,7 +296,7 @@ def subproc_toks(line, mincol=-1, maxcol=None, lexer=None, returnline=False):
296 296
         return  # handle comment lines
297 297
     beg, end = toks[0].lexpos, (toks[-1].lexpos + end_offset)
298 298
     end = len(line[:end].rstrip())
299
-    rtn = '![' + line[beg:end] + ']'
299
+    rtn = '?[' + line[beg:end] + ']'
300 300
     if returnline:
301 301
         rtn = line[:beg] + rtn + line[end:]
302 302
     return rtn

Loading…
Cancel
Save