Skip to content

Commit e4b947a

Browse files
author
Josh Durgin
committed
doc/script/gen_state_diagram.py: adapt for crimson BackfillMachine
Allow non-const events and abbreviating 'boost::statechart' as 'sc' Signed-off-by: Josh Durgin <[email protected]>
1 parent e9525ee commit e4b947a

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

doc/scripts/gen_state_diagram.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ def read_input(self, input_lines):
110110
previous_line = line
111111

112112
def get_context(self, line, previous_line):
113-
match = re.search(r"(\w+::)*::(?P<tag>\w+)::\w+\(const (?P<event>\w+)", line)
113+
match = re.search(r"(\w+::)*::(?P<tag>\w+)::\w+\((const )?(?P<event>\w+)", line)
114114
if match is None and previous_line is not None:
115115
# it is possible that we need to match on the previous line as well, so join
116116
# them to make them one line and try and get this matching
117117
joined_line = ' '.join([previous_line, line])
118-
match = re.search(r"(\w+::)*::(?P<tag>\w+)::\w+\(\s*const (?P<event>\w+)", joined_line)
118+
match = re.search(r"(\w+::)*::(?P<tag>\w+)::\w+\(\s*(const )?(?P<event>\w+)", joined_line)
119119
if match is not None:
120120
self.context.append((match.group('tag'), self.context_depth, match.group('event')))
121121
if '{' in line:
@@ -126,33 +126,33 @@ def get_context(self, line, previous_line):
126126
self.context.pop()
127127

128128
def get_state(self, line):
129-
if "boost::statechart::state_machine" in line:
129+
if "::state_machine" in line:
130130
tokens = re.search(
131-
r"boost::statechart::state_machine<\s*(\w*),\s*(\w*)\s*>",
131+
r"(sc|boost::statechart)::state_machine<\s*(\w*),\s*(\w*)\s*>",
132132
line)
133133
if tokens is None:
134134
raise Exception("Error: malformed state_machine line: " + line)
135-
self.machines[tokens.group(1)] = tokens.group(2)
135+
self.machines[tokens.group(2)] = tokens.group(3)
136136
self.context.append((tokens.group(1), self.context_depth, ""))
137137
return
138-
if "boost::statechart::state" in line:
138+
if "boost::statechart::state" in line or "sc::state" in line:
139139
tokens = re.search(
140-
r"boost::statechart::state<\s*(\w*),\s*(\w*)\s*,?\s*(\w*)\s*>",
140+
r"(sc|boost::statechart)::state<\s*(\w*),\s*(\w*)\s*,?\s*(\w*)\s*>",
141141
line)
142142
if tokens is None:
143143
raise Exception("Error: malformed state line: " + line)
144-
self.states[tokens.group(1)] = tokens.group(2)
145-
if tokens.group(2) not in self.state_contents.keys():
146-
self.state_contents[tokens.group(2)] = []
147-
self.state_contents[tokens.group(2)].append(tokens.group(1))
148-
if tokens.group(3):
149-
self.machines[tokens.group(1)] = tokens.group(3)
150-
self.context.append((tokens.group(1), self.context_depth, ""))
144+
self.states[tokens.group(2)] = tokens.group(3)
145+
if tokens.group(3) not in self.state_contents.keys():
146+
self.state_contents[tokens.group(3)] = []
147+
self.state_contents[tokens.group(3)].append(tokens.group(2))
148+
if tokens.group(4):
149+
self.machines[tokens.group(2)] = tokens.group(4)
150+
self.context.append((tokens.group(2), self.context_depth, ""))
151151
return
152152

153153
def get_event(self, line):
154-
if "boost::statechart::transition" in line:
155-
for i in re.finditer(r'boost::statechart::transition<\s*([\w:]*)\s*,\s*(\w*)\s*>',
154+
if "::transition" in line:
155+
for i in re.finditer(r'::transition<\s*([\w:]*)\s*,\s*(\w*)\s*>',
156156
line):
157157
if i.group(1) not in self.edges.keys():
158158
self.edges[i.group(1)] = []

0 commit comments

Comments
 (0)