我有这一行,它需要在不使用库的情况下进行解析,只使用 python 3 本身:
command s1 s2 (l1 l2) [lp 990] (l [li p]) "entity j [90 90]" <ping 90> *9 9* lol
需要获得:
['command', 's1', 's2', {'strings': ['l1', 'l2'], type: 'round_brackets'}, {'strings': ['lp', '990'], type: 'square_brackets'}, {'strings': ['l', {'strings': ['li', 'p'], type: 'square_brackets'}], type: 'round_brackets'}, {'strings': 'entity j [90 90]', type: 'quotes'}, {'strings': ['ping', '90'], type: 'command'}, {'integers': ['9', '9'], type: 'nums'}, 'lol']
解析规则:
- 括号和引号和星号可以嵌套
- 解析在引号中不起作用。
- 用星星代替字符串整数。
- 在结果数组中,其字典将包含内容本身和类型。
这就是您需要做的所有事情,请谁能做到:)。
而且我无法使用列表中的字典编写解析器。
1 个回答