From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7EA1844177; Thu, 6 Jun 2024 20:53:03 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 69FFC410F6; Thu, 6 Jun 2024 20:53:03 +0200 (CEST) Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by mails.dpdk.org (Postfix) with ESMTP id 04955427D9 for ; Thu, 6 Jun 2024 20:53:01 +0200 (CEST) Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-6c9d747be82so1139842a12.3 for ; Thu, 06 Jun 2024 11:53:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iol.unh.edu; s=unh-iol; t=1717699981; x=1718304781; darn=dpdk.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VuZY1ZFaFuq6rpXewNrFHLDH1o3B+c1xMu/vwW8T0s8=; b=VeuuGKuxfwXT6egyJezbBcEhj/79x9yiwhXMDsg+d8q/ZEr+iFy7otU7i4Ra3A2U78 UxXK2Y+F1FctpxXQBtIPL/aPCyLQHDwUMEXp1UjQu9InGzmMZCmI9i4uJai4sB6IgNt8 FCGNXZVWB3PYXmqgSGoKeWVDbNBavFcg1b8rw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717699981; x=1718304781; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VuZY1ZFaFuq6rpXewNrFHLDH1o3B+c1xMu/vwW8T0s8=; b=Dlv/olKscOX1BhrNvRFbP7W7ISSiE7XQ2JLxaK5xz7Ix4XMnRsot+yluwXEboaZb3S aivH3HNFbVOBQKomV6U04551goqOS1hUg2H57Z3PwFgaDyQPB26x7QeEnhAaZAuwn8xY 12FE7jsuvtpi7NBTzZjDfP5rMtlPaO94BqH3Ms7dAx9uI+PjO/1czji6o54fCQx7w05O ITUT8vM540Uo7Np27l5ECqQeJOGWJFe85OKtOO6BaMgDp6L7vGDRcdhuZrZIaiRalqDF Ve5OO4QyySJEEtFP9P82xpLlL4qiIvjUrqZv7iL2NN/RYVBUW2CvbPQkmITgUPzCKPww nI3w== X-Gm-Message-State: AOJu0YxvzQWVDqD57fr9ajxeoHtBLV+a2C6uFCeky0WeHfc02pdxTipx nbN43jBS7dIR7OQoQSH609Z6pEPnbk5nLUsxHpSXyC8VnKNT7hPByHCd7iXDSNfE67uHeVPLKGA tLVrYYmQ1lINt29SK2aCTbdmWUJ0347GyO25awg== X-Google-Smtp-Source: AGHT+IGz1jUwTbMMBtgdGEopHgUJs94Nqq1A8daohVxwbIPVZf0RP6TAFjzJDlFKVZUdpLIEkEWWHxIvKuUYfocsqrA= X-Received: by 2002:a17:90a:cf91:b0:2c2:86c9:2079 with SMTP id 98e67ed59e1d1-2c2bcac2ef2mr424101a91.11.1717699981208; Thu, 06 Jun 2024 11:53:01 -0700 (PDT) MIME-Version: 1.0 References: <20240412111136.3470304-1-luca.vizzarro@arm.com> <20240606091718.151516-1-luca.vizzarro@arm.com> <20240606091718.151516-4-luca.vizzarro@arm.com> In-Reply-To: <20240606091718.151516-4-luca.vizzarro@arm.com> From: Jeremy Spewock Date: Thu, 6 Jun 2024 14:52:49 -0400 Message-ID: Subject: Re: [PATCH v4 3/5] dts: add parsing utility module To: Luca Vizzarro Cc: dev@dpdk.org, =?UTF-8?Q?Juraj_Linke=C5=A1?= , Paul Szczepanek Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Just a few very minor documentation catches, otherwise: Reviewed-by: Jeremy Spewock On Thu, Jun 6, 2024 at 5:17=E2=80=AFAM Luca Vizzarro wrote: > + @classmethod > + def from_str(cls, text: str): > + match text: > + case "black": > + return cls.BLACK > + case "white": > + return cls.WHITE > + case _: > + return None # unsupported colour > + > + @classmethod > + def make_parser(cls): > + # make a parser function that finds a match and > + # then makes it a Colour object through Colour.from_= str > + return TextParser.wrap(cls.from_str, TextParser.find= (r"is a (\w+)")) I think this example is backwards now that you changed the parameters to calling order isn't it? We need to call find first and then pass that into from_str. > + > + @dataclass > + class Animal(TextParser): > + kind: str =3D field(metadata=3DTextParser.find(r"is a \w= + (\w+)")) > + name: str =3D field(metadata=3DTextParser.find(r"^(\w+)"= )) > + colour: Colour =3D field(metadata=3DColour.make_parser()= ) > + age: int =3D field(metadata=3DTextParser.find_int(r"aged= (\d+)")) > + > + steph =3D Animal.parse("Stephanie is a white cat aged 10") > + print(steph) # Animal(kind=3D'cat', name=3D'Stephanie', colo= ur=3D, age=3D10) > + """ > + > + @staticmethod > + def find( > + pattern: str | re.Pattern[str], > + flags: re.RegexFlag =3D re.RegexFlag(0), > + named: bool =3D False, > + ) -> ParserFn: > + """Makes a parser function that finds a regular expression match= in the text. > + > + If the pattern has any capturing groups, it returns None if no m= atch was found, otherwise a > + tuple containing the values per each group is returned.. If the = pattern has only one It looks like there are two periods here by mistake. > + capturing group and a match was found, its value is returned. If= the pattern has no > + capturing groups then either True or False is returned if the pa= ttern had a match or not. > + > + Args: > + pattern: The regular expression pattern. > + flags: The regular expression flags. Ignored if the given pa= ttern is already compiled. > + named: If set to True only the named capturing groups will b= e returned, as a dictionary. > + > 2.34.1 >