54
54
from __future__ import print_function
55
55
56
56
from _devbuild .gen .syntax_asdl import loc , loc_t , CompoundWord
57
- from _devbuild .gen .value_asdl import (value , value_e , value_t )
57
+ from _devbuild .gen .value_asdl import (value , value_t )
58
58
59
59
from core .error import e_usage
60
- #from frontend import match
61
60
from mycpp import mops
62
- from mycpp .mylib import log , tagswitch , iteritems
61
+ from mycpp .mylib import log , iteritems
63
62
64
63
_ = log
65
64
66
- from typing import (cast , Tuple , Optional , Dict , List , Any , TYPE_CHECKING )
65
+ from typing import (Tuple , Optional , Dict , List , TYPE_CHECKING )
67
66
if TYPE_CHECKING :
68
67
from frontend import flag_spec
69
68
OptChange = Tuple [str , bool ]
@@ -87,9 +86,18 @@ def __init__(self, defaults):
87
86
# New style
88
87
self .attrs = {} # type: Dict[str, value_t]
89
88
90
- self .opt_changes = [] # type: List[OptChange] # -o errexit +o nounset
91
- self .shopt_changes = [
92
- ] # type: List[OptChange] # -O nullglob +O nullglob
89
+ # -o errexit +o nounset
90
+ self .opt_changes = [] # type: List[OptChange]
91
+
92
+ # -O nullglob +O nullglob
93
+ self .shopt_changes = [] # type: List[OptChange]
94
+
95
+ # Special case for --eval and --eval-pure? For bin/osh. It seems OK
96
+ # to have one now. The pool tells us if it was pure or not.
97
+ # Note: MAIN_SPEC is different than SET_SPEC, so set --eval does
98
+ # nothing.
99
+ self .eval_flags = [] # type: List[Tuple[str, bool]]
100
+
93
101
self .show_options = False # 'set -o' without an argument
94
102
self .actions = [] # type: List[str] # for compgen -A
95
103
self .saw_double_dash = False # for set --
@@ -112,24 +120,6 @@ def Set(self, name, val):
112
120
113
121
self .attrs [name ] = val
114
122
115
- if 0 :
116
- # Backward compatibility!
117
- with tagswitch (val ) as case :
118
- if case (value_e .Undef ):
119
- py_val = None # type: Any
120
- elif case (value_e .Bool ):
121
- py_val = cast (value .Bool , val ).b
122
- elif case (value_e .Int ):
123
- py_val = cast (value .Int , val ).i
124
- elif case (value_e .Float ):
125
- py_val = cast (value .Float , val ).f
126
- elif case (value_e .Str ):
127
- py_val = cast (value .Str , val ).s
128
- else :
129
- raise AssertionError (val )
130
-
131
- setattr (self , name , py_val )
132
-
133
123
def __repr__ (self ):
134
124
# type: () -> str
135
125
return '<_Attributes %s>' % self .__dict__
@@ -266,6 +256,31 @@ def OnMatch(self, attached_arg, arg_r, out):
266
256
raise NotImplementedError ()
267
257
268
258
259
+ class AppendEvalFlag (_Action ):
260
+
261
+ def __init__ (self , name ):
262
+ # type: (str) -> None
263
+ _Action .__init__ (self )
264
+ self .name = name
265
+ self .is_pure = (name == 'eval-pure' )
266
+
267
+ def OnMatch (self , attached_arg , arg_r , out ):
268
+ # type: (Optional[str], Reader, _Attributes) -> bool
269
+ """Called when the flag matches."""
270
+
271
+ assert attached_arg is None , attached_arg
272
+
273
+ arg_r .Next ()
274
+ arg = arg_r .Peek ()
275
+ if arg is None :
276
+ e_usage ('expected argument to %r' % ('--' + self .name ),
277
+ arg_r .Location ())
278
+
279
+ # is_pure is True for --eval-pure
280
+ out .eval_flags .append ((arg , self .is_pure ))
281
+ return False
282
+
283
+
269
284
class _ArgAction (_Action ):
270
285
271
286
def __init__ (self , name , quit_parsing_flags , valid = None ):
0 commit comments