summaryrefslogtreecommitdiff
path: root/cmd2/parsing.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-09-25 01:23:51 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-09-25 01:23:51 -0400
commitdc39dcbb82b0dff2e170deb9df903793c8d3526e (patch)
tree5f7c8d60f81ba39334501460824712da41c3308a /cmd2/parsing.py
parentec1f4f1b577dd179980ca993aceb38001e5a3e45 (diff)
downloadcmd2-git-dc39dcbb82b0dff2e170deb9df903793c8d3526e.tar.gz
Added macro delete
Diffstat (limited to 'cmd2/parsing.py')
-rw-r--r--cmd2/parsing.py37
1 files changed, 19 insertions, 18 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py
index 4d17d07e..7a2af64b 100644
--- a/cmd2/parsing.py
+++ b/cmd2/parsing.py
@@ -14,35 +14,36 @@ from . import utils
# Pattern used to find normal argument
# Match strings like: {5}, {{{{{4}, {2}}}}}
-normal_arg_pattern = re.compile(r'(?<!\{)\{\d+\}|\{\d+\}(?!\})')
+macro_normal_arg_pattern = re.compile(r'(?<!\{)\{\d+\}|\{\d+\}(?!\})')
# Pattern used to find escaped arguments (2 or more braces on each side of digit)
# Match strings like: {{5}}, {{{{{4}}, {{2}}}}}, {{{4}}}
-escaped_arg_pattern = re.compile(r'\{{2}\d+\}{2}')
+macro_escaped_arg_pattern = re.compile(r'\{{2}\d+\}{2}')
# Finds a string of digits
digit_pattern = re.compile(r'\d+')
@attr.s(frozen=True)
-class Macro:
- """Defines a cmd2 macro"""
+class MacroArgInfo:
+ """
+ Information used to replace or unescape arguments in a macro value when the macro is resolved
+ Normal argument syntax : {5}
+ Escaped argument syntax: {{5}}
+ """
+ # The starting index of this argument in the macro value
+ start_index = attr.ib(validator=attr.validators.instance_of(int), type=int)
- @attr.s(frozen=True)
- class ArgInfo:
- """
- Information used to replace or unescape arguments in a macro value when the macro is resolved
- Normal argument syntax : {5}
- Escaped argument syntax: {{5}}
- """
- # The starting index of this argument in the macro value
- start_index = attr.ib(validator=attr.validators.instance_of(int), type=int)
+ # The number that appears between the braces
+ number = attr.ib(validator=attr.validators.instance_of(int), type=int)
+
+ # Tells if this argument is escaped and therefore needs to be unescaped
+ is_escaped = attr.ib(validator=attr.validators.instance_of(bool), type=bool)
- # The number that appears between the braces
- number = attr.ib(validator=attr.validators.instance_of(int), type=int)
- # Tells if this argument is escaped and therefore needs to be unescaped
- is_escaped = attr.ib(validator=attr.validators.instance_of(bool), type=bool)
+@attr.s(frozen=True)
+class Macro:
+ """Defines a cmd2 macro"""
# Name of the macro
name = attr.ib(validator=attr.validators.instance_of(str), type=str)
@@ -54,7 +55,7 @@ class Macro:
min_arg_count = attr.ib(validator=attr.validators.instance_of(int), type=int)
# Used to fill in argument placeholders in the macro
- arg_info_list = attr.ib(factory=list, validator=attr.validators.instance_of(list), type=List[ArgInfo])
+ arg_info_list = attr.ib(factory=list, validator=attr.validators.instance_of(list), type=List[MacroArgInfo])
@attr.s(frozen=True)