in c/tools/codec-generator/generate.py [0:0]
def parse_item(format: str) -> Tuple[ASTNode, str]:
if len(format) == 0:
return EmptyNode(), ''
if format.startswith('DL['):
l, rest = parse_list(format[3:])
b, rest = expect_char(rest, ']')
if not b:
raise ParseError(format)
return DescListNode(l), rest
elif format.startswith('D.['):
l, rest = parse_list(format[3:])
b, rest = expect_char(rest, ']')
if not b:
raise ParseError(format)
return DescListIgnoreTypeNode(l), rest
elif format.startswith('['):
l, rest = parse_list(format[1:])
b, rest = expect_char(rest, ']')
if not b:
raise ParseError(format)
return ListNode('list', l, []), rest
elif format.startswith('D?LR'):
return ASTNode('described_maybe_type_raw', ['bool', 'uint64_t', 'pn_bytes_t'], consume_types=['bool*', 'uint64_t*', 'pn_bytes_t*']), format[4:]
elif format.startswith('D?L?.'):
return ASTNode('described_maybe_type_maybe_anything', ['bool', 'uint64_t', 'bool'], consume_types=['bool*', 'uint64_t*', 'bool*']), format[4:]
elif format.startswith('DLC'):
return ASTNode('described_type_copy', ['uint64_t', 'pn_data_t*'], consume_types=['uint64_t*', 'pn_data_t*']), format[3:]
elif format.startswith('DLR'):
return ASTNode('described_type_raw', ['uint64_t', 'pn_bytes_t'], consume_types=['uint64_t*', 'pn_bytes_t*']), format[3:]
elif format.startswith('DL.'):
return ASTNode('described_type_anything', ['uint64_t']), format[3:]
elif format.startswith('D?L.'):
return ASTNode('described_maybe_type_anything', ['bool', 'uint64_t']), format[3:]
elif format.startswith('D..'):
return NullNode('described_anything'), format[3:]
elif format.startswith('D.C'):
return ASTNode('described_copy', ['pn_data_t*'], consume_types=['pn_data_t*']), format[3:]
elif format.startswith('D.R'):
return ASTNode('described_raw', ['pn_bytes_t'], consume_types=['pn_bytes_t*']), format[3:]
elif format.startswith('@T['):
l, rest = parse_list(format[3:])
b, rest = expect_char(rest, ']')
if not b:
raise ParseError(format)
return ArrayNode(l), rest
elif format.startswith('?'):
i, rest = parse_item(format[1:])
return OptionNode(i), rest
elif format.startswith('*s'):
return ASTNode('counted_symbols', ['size_t', 'char**']), format[2:]
elif format.startswith('.'):
return NullNode('anything'), format[1:]
elif format.startswith('s'):
return ASTNode('symbol', ['pn_bytes_t'], consume_types=['pn_bytes_t*']), format[1:]
elif format.startswith('S'):
return ASTNode('string', ['pn_bytes_t'], consume_types=['pn_bytes_t*']), format[1:]
elif format.startswith('c'):
return ASTNode('condition', ['pn_condition_t*'], consume_types=['pn_condition_t*']), format[1:]
elif format.startswith('d'):
return ASTNode('disposition', ['pn_disposition_t*'], consume_types=['pn_disposition_t*']), format[1:]
elif format.startswith('I'):
return ASTNode('uint', ['uint32_t']), format[1:]
elif format.startswith('H'):
return ASTNode('ushort', ['uint16_t']), format[1:]
elif format.startswith('n'):
return NullNode('null'), format[1:]
elif format.startswith('R'):
return ASTNode('raw', ['pn_bytes_t'], consume_types=['pn_bytes_t*']), format[1:]
elif format.startswith('a'):
return ASTNode('atom', ['pn_atom_t*'], consume_types=['pn_atom_t*']), format[1:]
elif format.startswith('M'):
return ASTNode('multiple', ['pn_bytes_t']), format[1:]
elif format.startswith('o'):
return ASTNode('bool', ['bool']), format[1:]
elif format.startswith('B'):
return ASTNode('ubyte', ['uint8_t']), format[1:]
elif format.startswith('L'):
return ASTNode('ulong', ['uint64_t']), format[1:]
elif format.startswith('t'):
return ASTNode('timestamp', ['pn_timestamp_t']), format[1:]
elif format.startswith('z'):
return ASTNode('binaryornull', ['size_t', 'const char*'], consume_types=['pn_bytes_t*']), format[1:]
elif format.startswith('Z'):
return ASTNode('binarynonull', ['size_t', 'const char*'], consume_types=['pn_bytes_t*']), format[1:]
else:
raise ParseError(format)