diff options
| author | 2020-01-25 21:17:35 +0000 | |
|---|---|---|
| committer | 2020-01-25 21:17:35 +0000 | |
| commit | 478223f88c3ba9ce5cc2f580d52fb5eac5c06dea (patch) | |
| tree | f62bcd089029dc3208f50ba701c49f5fda1cf99b /src/utils/parse.py | |
| parent | change command specs to be compiled at runtime by a decorator (diff) | |
| signature | ||
support type names of spec arguments
Diffstat (limited to 'src/utils/parse.py')
| -rw-r--r-- | src/utils/parse.py | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/utils/parse.py b/src/utils/parse.py index 258b97dc..aa7a9ee1 100644 --- a/src/utils/parse.py +++ b/src/utils/parse.py @@ -157,7 +157,8 @@ def format_token_replace(s: str, vars: typing.Dict[str, str], return s class ArgumentSpecType(object): - def __init__(self, name: str, exported: str): + def __init__(self, type_name: str, name: str, exported: str): + self.type = type_name self.name = name self.exported = exported @@ -168,17 +169,23 @@ class ArgumentSpec(object): def argument_spec(spec: str) -> typing.List[ArgumentSpec]: out: typing.List[ArgumentSpec] = [] - for type_names_str in spec.split(" "): - optional = type_names_str[0] == "?" - type_names_str = type_names_str[1:] + for spec_argument in spec.split(" "): + optional = spec_argument[0] == "?" - spec_types: typing.List[ArgumentSpecType] = [] - for type_name in type_names_str.split("|"): - exported_name = "" - if "~" in type_name: - exported_name = type_name - type_name = type_name.replace("~", "", 1) + argument_types: typing.List[ArgumentSpecType] = [] + for argument_type in spec_argument[1:].split("|"): + exported = "" + if "~" in argument_type: + exported = argument_type.split("~", 1)[1] + argument_type = argument_type.replace("~", "", 1) - spec_types.append(ArgumentSpecType(type_name, exported_name)) - out.append(ArgumentSpec(optional, spec_types)) + argument_type_name = argument_type + name_end = argument_type.find(">") + if argument_type[0] == "<" and name_end > 0: + argument_type_name = argument_type[1:name_end] + argument_type = argument_type[name_end+1:] + + argument_types.append(ArgumentSpecType(argument_type, + argument_type_name, exported)) + out.append(ArgumentSpec(optional, argument_types)) return out |
