Parse and generate a Macro that can be run as often as you want. Parameters ---------- macro "repeat(3, key(a).wait(10))" "repeat(2, key(a).key(KEY_A)).key(b)" "wait(1000).modify(Shift_L, repeat(2, k(a))).wait(10, 20).key(b)" conte
(macro: str, context=None, mapping=None, verbose: bool = True)
| 445 | |
| 446 | @staticmethod |
| 447 | def parse(macro: str, context=None, mapping=None, verbose: bool = True) -> Macro: |
| 448 | """Parse and generate a Macro that can be run as often as you want. |
| 449 | |
| 450 | Parameters |
| 451 | ---------- |
| 452 | macro |
| 453 | "repeat(3, key(a).wait(10))" |
| 454 | "repeat(2, key(a).key(KEY_A)).key(b)" |
| 455 | "wait(1000).modify(Shift_L, repeat(2, k(a))).wait(10, 20).key(b)" |
| 456 | context : Context, or None for use in Frontend |
| 457 | mapping |
| 458 | the mapping for the macro, or None for use in Frontend |
| 459 | verbose |
| 460 | log the parsing True by default |
| 461 | """ |
| 462 | # TODO pass mapping in frontend and do the target check for keys? |
| 463 | logger.debug("parsing macro %s", macro.replace("\n", "")) |
| 464 | macro = Parser.clean(macro) |
| 465 | macro = Parser.handle_plus_syntax(macro) |
| 466 | |
| 467 | macro_obj = Parser._parse_recurse( |
| 468 | macro, |
| 469 | context, |
| 470 | mapping, |
| 471 | verbose, |
| 472 | ).value |
| 473 | if not isinstance(macro_obj, Macro): |
| 474 | raise MacroError(macro, "The provided code was not a macro") |
| 475 | |
| 476 | return macro_obj |