Module ammcore.nick
¶
Utilities for parsing component nicks.
Nick format¶
Nicks are parsed similar to how bash parses program’s arguments. They can have
positional and named parameters, separated by spaces. Named parameters
have format name=value
, and positional parameters have format value
.
Values can’t have spaces in them. However, you can escape spaces using double-quoted strings. To escape a quote inside of a string, put it twice.
For example, the following nick
positional "positional=with=eq" name1=value name2="value "" with quote"
has two positional parameters (positional
and positional=with=eq
),
and two named parameters (name1
is value
, and
name2
is value " with quote
).
Index¶
Function
Parse key-value pairs from object's nick. |
Class
Result of parsing component's nick. |
Function¶
-
ammcore.nick.parse(nick:
string
) parsed:ammcore.nick.ParsedNick
| {[string
]:string
[], [integer
]:string
} ¶ Parse key-value pairs from object’s nick.
- Parameters:
nick (
string
) – nick to parse.- Returns:
parsed (
ammcore.nick.ParsedNick
| {[string
]:string
[], [integer
]:string
}) – parsing result.
Class¶
-
class ammcore.nick.ParsedNick :
ammcore.class.Base
, {[string
]:string
[], [integer
]:string
}¶ Result of parsing component’s nick.
-
classmethod New(self: <T:
ammcore.class.Base
>) <T:ammcore.class.Base
> ¶ Constructor.
-
getOne(self:
ammcore.nick.ParsedNick
| {[string
]:string
[], [integer
]:string
}, name:string
, ty: fun(s:string
): <T
>) value?: <T
> ¶ Return the first value for parameter
name
, parsed by functionty
.- Parameters:
name (
string
) – name of the parameter to get.ty (fun(s:
string
): <T
>) – function to parse a raw string; should returnnil
if parsing fails.
- Returns:
value? (<
T
>) – parsed value ornil
if parsing failed or parameter was not found.
-
getAll(self:
ammcore.nick.ParsedNick
| {[string
]:string
[], [integer
]:string
}, name:string
, ty: fun(s:string
): <T
>) parsed: <T
>[] ¶ Return all values for parameter
name
, parsed by functionty
.- Parameters:
name (
string
) – name of the parameter to get.ty (fun(s:
string
): <T
>) – function to parse a raw string; should returnnil
if parsing fails.
- Returns:
parsed (<
T
>[]) – values.
-
getPos(self:
ammcore.nick.ParsedNick
| {[string
]:string
[], [integer
]:string
}, pos:integer
, ty: fun(s:string
): <T
>) value?: <T
> ¶ Return a value for positional parameter
pos
, parsed by functionty
.- Parameters:
pos (
integer
) – name of the parameter to get.ty (fun(s:
string
): <T
>) – function to parse a raw string; should returnnil
if parsing fails.
- Returns:
value? (<
T
>) – parsed value ornil
if parsing failed or parameter was not found.
-
classmethod New(self: <T: