-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogical_operators.py
More file actions
36 lines (30 loc) · 885 Bytes
/
logical_operators.py
File metadata and controls
36 lines (30 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
def is_boolean_command(command):
if command == 'false':
os.environ['?'] = '1'
elif command == 'true':
os.environ['?'] = '0'
else:
return True
return False
def is_skip_command(operator):
if not operator:
return True
if operator == '&&':
return os.environ['?'] == '0'
return os.environ['?'] != '0'
def parse_command_operator(args):
'''
Tasks:
- Split command and logical operator into list of tuple
- Inside tuple is command + args and next logical operators after command
- Return list of step need to do logical operators
'''
steps = []
commands = args + [" "]
start = 0
for i, com in enumerate(commands):
if com == '||' or com == "&&" or com == ' ':
steps.append((commands[start: i], commands[i]))
start = i + 1
return steps