MCPcopy Index your code
hub / github.com/sezanzeb/input-remapper / parse

Method parse

inputremapper/injection/macros/parse.py:447–476  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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

Callers 15

test_add_versionMethod · 0.80
test_update_versionMethod · 0.80
setUpMethod · 0.80
test_1Method · 0.80
test_2Method · 0.80
test_not_an_intMethod · 0.80
test_raises_errorMethod · 0.80
test_1Method · 0.80
test_named_parameterMethod · 0.80
test_2Method · 0.80
test_key_down_upMethod · 0.80
test_raises_errorMethod · 0.80

Calls 5

MacroErrorClass · 0.90
debugMethod · 0.80
cleanMethod · 0.80
handle_plus_syntaxMethod · 0.80
_parse_recurseMethod · 0.80

Tested by 15

test_add_versionMethod · 0.64
test_update_versionMethod · 0.64
setUpMethod · 0.64
test_1Method · 0.64
test_2Method · 0.64
test_not_an_intMethod · 0.64
test_raises_errorMethod · 0.64
test_1Method · 0.64
test_named_parameterMethod · 0.64
test_2Method · 0.64
test_key_down_upMethod · 0.64
test_raises_errorMethod · 0.64