MCPcopy Create free account
hub / github.com/DexterInd/GoPiGo3 / set_regex_string

Function set_regex_string

Software/Scratch/GoPiGo3Scratch.py:263–329  ·  view source on GitHub ↗

Sets up the regex string, and the test_msgs for asserting refer to https://regex101.com/ to make sense of it all regex explanation: 1. Forward/Backward [x cm|inches|degrees|rotations|seconds 2. [turn] Left/Right [x degrees]

()

Source from the content-addressed store, hash-verified

261
262
263def set_regex_string():
264 '''
265 Sets up the regex string, and the test_msgs for asserting
266 refer to https://regex101.com/ to make sense of it all
267
268 regex explanation:
269 1. Forward/Backward [x cm|inches|degrees|rotations|seconds
270 2. [turn] Left/Right [x degrees]
271 '''
272 regex_seconds = "(s(?:e[c|g]?(?:[o|u]n(?:d)?)?(?:s)?)?)"
273 regex_degrees = "(d(?:[e|a][c|g]+(?:re(?:e)?)?(?:s)?)?)"
274 regex_right = "((?:w)?ri(?:[gh]*t(?:e)?))"
275 regex_left = "(lef(?:t)?)"
276 regex_rotations = "(rot(?:at(?:i)?on)?(?:s)?)"
277 regex_inches = "(in(?:ches|ch)?)"
278
279 # drive forward or backward
280 # first group is direction
281 # Must start with either F or B,
282 # be followed by either o (for forward) or a for backward
283 # or be followed by w (for fwd, or bwd)
284 # must end with a D
285 # must only contain letters
286 # second group is optional and is numeric only (may be float)
287 # third group is unit
288 # supported units are cm,
289 # in, inches, i,
290 # deg, degree(s), d,
291 # rot, rotation(s), r,
292 # s[econd],s[egund]
293 # the unit is optional. If not there cm will be assumed
294 regex_drive = "((F[o|w][A-Z]*D)|(B[a|w][a-z]*D))\s*(([0-9.]*)\s*((cm)|"+regex_inches+"|"+regex_degrees+"|"+regex_rotations+"|"+regex_seconds+")+)?"
295
296 regex_stop = "(STOP)"
297
298 regex_speed = "(SPE(?:E)?D)\s*([0-9.]+)\s*(%)?"
299
300 # second one:
301 # (turn) left/right (x degrees/seconds)
302 regex_turn = "(?:t(?:urn)?)?\s*("+regex_left+"|"+regex_right+")\s*(([0-9.]+)\s*("+regex_degrees+"|"+regex_rotations+"|"+regex_seconds+")?)*"
303
304 # third one:
305 # open/close left/right/both eye(s)
306 regex_eyes = "(((open)|(close))\s*(("+regex_left+"|"+regex_right+"|both)?\s*eye[s]??))"
307
308 regex_eyes_color = "(("+regex_left+"|"+regex_right+"|both)\s*eye[s]?\s*(([0-9]{1,3})(?:,|\s)+([0-9]{1,3})(?:,|\s)+([0-9]{1,3})|(#[0-9A-F]{6})|("+regex_accepted_colors+")))"
309
310 # fourth one:
311 # left/right/both blinker(s) on/off
312 regex_blinkers = "(("+regex_left+"|"+regex_right+"|both)?\s*(blinker[s]?|LEDL|LEDR)\s*(on|255|off|0))"
313
314 regex_reset = "(RESET)"
315
316 regex_encoders = "((("+regex_left+"|"+regex_right+"|both)?encoder[s]?("+regex_left+"|"+regex_right+"|both)?)\s*((reset)|(read)|([0-9.]*)))"
317
318 full_regex = ("^"+regex_drive + "$|" +
319 regex_turn + "$|^" +
320 regex_stop + "$|^" +

Callers 1

GoPiGo3Scratch.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected