forked from has2k1/gnuplot_kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatement.py
More file actions
97 lines (83 loc) · 1.82 KB
/
statement.py
File metadata and controls
97 lines (83 loc) · 1.82 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
"""
Recognising gnuplot statements
"""
import re
# name of the command i.e first token
CMD_RE = re.compile(
r'^\s*'
r'(?P<cmd>'
r'\w+' # The command
r')'
r'\s?'
)
# plot statements
PLOT_RE = re.compile(
r'^\s*'
r'(?P<plot_cmd>'
r'plot|plo|pl|p|'
r'splot|splo|spl|sp|'
r'replot|replo|repl|rep'
r')'
r'\s?'
)
# "set multiplot" and abbreviated variants
SET_MULTIPLE_RE = re.compile(
r'\s*'
r'set'
r'\s+'
r'multip(?:lot|lo|l)?\b'
r'\b'
)
# "unset multiplot" and abbreviated variants
UNSET_MULTIPLE_RE = re.compile(
r'\s*'
r'(?:unset|unse|uns)'
r'\s+'
r'multip(?:lot|lo|l)?\b'
r'\b'
)
# "set output" and abbreviated variants
SET_OUTPUT_RE = re.compile(
r'\s*'
r'set'
r'\s+'
r'(?:output|outpu|outp|out|ou|o)'
r'(?:\s+|$)'
)
# "unset output" and abbreviated variants
UNSET_OUTPUT_RE = re.compile(
r'\s*'
r'(?:unset|unse|uns)'
r'\s+'
r'(?:output|outpu|outp|out|ou|o)'
r'(?:\s+|$)'
)
class STMT(str):
"""
A gnuplot statement
"""
def is_set_output(self):
"""
Return True if stmt is a 'set output' statement
"""
return bool(SET_OUTPUT_RE.match(self))
def is_unset_output(self):
"""
Return True if stmt is an 'unset output' statement
"""
return bool(UNSET_OUTPUT_RE.match(self))
def is_set_multiplot(self):
"""
Return True if stmt is a "set multiplot" statement
"""
return bool(SET_MULTIPLE_RE.match(self))
def is_unset_multiplot(self):
"""
Return True if stmt is a "unset multiplot" statement
"""
return bool(UNSET_MULTIPLE_RE.match(self))
def is_plot(self):
"""
Return True if stmt is a plot statement
"""
return bool(PLOT_RE.match(self))