我正在使用云雀,但不知道如何匹配所有玩家的名字,因为他们可能对云雀规则很复杂?
示例模式是"Seat {number}: {player} ({chips} in chips)"
,我也想要每一行的所有值。
from lark import Lark, lexer
gram = r"""
start: seats+
seats: "Seat " seat_position player table_chips is_sitting_out? SPACE? NL
seat_position: NUMBER
is_sitting_out: " is sitting out"
table_chips: "(" chips " in chips" (", " chips " bounty")? ")"
player: STRING_INNER
chips: "$"? (DECIMAL | NUMBERS)
NUMBERS: /[0-9]/+
NUMBER: /[0-9]/
DECIMAL: NUMBERS "." NUMBERS
SPACE: " "+
STRING_INNER: ": " /.*?/ " "
CR : /\r/
LF : /\n/
NL: (CR? LF)+
"""
data = r"""Seat 1: Ruzzka(Rus) (1200 in chips)
Seat 1: Dladik Rzs38 (1200 in chips)
Seat 1: slum ^o_o^ (1200 in chips)
Seat 1: é=mc² (1200 in chips)
Seat 1: {’O_0`}/(nh) (1200 in chips)
Seat 1: °ÆND0c42Z4y° (1200 in chips)
Seat 1: $ salesovish (1200 in chips)
"""
parser = Lark(gram)
tree = parser.parse(data)
print(tree.pretty())