-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.py
More file actions
50 lines (43 loc) · 1.13 KB
/
parser.py
File metadata and controls
50 lines (43 loc) · 1.13 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
#---------------------
# Talwar v 0.2
# Parser v.1
#---------------------
#Internal Imports
from cmdparse import validate_token
#Default Tokens
default_tokens= ['start','end','also','then','->','target']
#Variable
global error_count
error_count=0
#Starting Parser
def start_parser(pipeline):
global error_count
error_count=0
tokens=pipeline.split()
if tokens.count('start') != 1 or tokens.count('end') != 1:
print '[!]start and end keywords should only be used onces.'
return False,0
else:
if tokens[0] == 'start' and tokens[len(tokens)-1] == 'end':
for token in tokens:
validate(token)
if error_count !=0:
return False,0
else:
return True,tokens
else:
print '[!] Pipeline should start with end with \'start\' and \'end\' keywords respectivily'
return False,0
#Validate each token
def validate(token):
global error_count
if token not in default_tokens:
if token == 'target.each':
print '[!]Error: \'target.each\' target don\'t have each option'
error_count +=1
elif validate_token(token):
print 'valid'
else:
print '[!]Error:'+token+' invalid'
error_count +=1