(self, nugget)
return None
match the string `nugget` to a format specifier.
match the string `nugget` to a format specifier.
match the string nugget to a format specifier .
def _match_spec(self, nugget):
        """
        match the string `nugget` to a format specifier.
        """
        # TODO: handle positional modifiers and other similar format string tricks.
        all_spec = self._all_spec

        # iterate through nugget throwing away anything which is an int
        # TODO store this in a size variable

        original_nugget = nugget
        length_str = [ ]
        length_spec = None
        length_spec_str_len = 0
        pad_chr = " "

        if nugget.startswith(b".*"):
            # ".*": precision is specified as an argument
            nugget = nugget[2:]
            length_spec = b".*"
            length_spec_str_len = 2
        elif nugget.startswith(b"0"):
            pad_chr = "0"
        elif nugget.startswith(b"."):
            pad_chr = "0"
            nugget = nugget[1:]

        for j, c in enumerate(nugget):
            if c in ascii_digits:
                length_str.append(c)
            else:
                nugget = nugget[j:]
                if length_spec is None:
                    length_spec = None if len(length_str) == 0 else int(bytes(length_str))
                break

        # we need the length of the format's length specifier to extract the format and nothing else
        if length_spec_str_len == 0 and length_str:
            length_spec_str_len = len(length_str)
        # is it an actual format?
        for spec in all_spec:
            if nugget.startswith(spec):
                # this is gross coz sim_type is gross..
                nugget = nugget[:len(spec)]
                original_nugget = original_nugget[:(length_spec_str_len + len(spec))]
                nugtype: 'SimType' = all_spec[nugget]
                try:
                    typeobj = nugtype.with_arch(self.state.arch if self.state is not None else self.project.arch)
                except Exception:
                    raise SimProcedureError("format specifier uses unknown type '%s'" % repr(nugtype))
                return FormatSpecifier(original_nugget, length_spec, pad_chr, typeobj.size // 8, typeobj.signed)

        return None
def _match_spec ( self , nugget ) : # TODO: handle positional modifiers and other similar format string tricks. all_spec = self . _all_spec # iterate through nugget throwing away anything which is an int # TODO store this in a size variable original_nugget = nugget length_str = [ ] length_spec = None length_spec_str_len = 0 pad_chr = " " if nugget . startswith ( b".*" ) : # ".*": precision is specified as an argument nugget = nugget [ 2 : ] length_spec = b".*" length_spec_str_len = 2 elif nugget . startswith ( b"0" ) : pad_chr = "0" elif nugget . startswith ( b"." ) : pad_chr = "0" nugget = nugget [ 1 : ] for j , c in enumerate ( nugget ) : if c in ascii_digits : length_str . append ( c ) else : nugget = nugget [ j : ] if length_spec is None : length_spec = None if len ( length_str ) == 0 else int ( bytes ( length_str ) ) break # we need the length of the format's length specifier to extract the format and nothing else if length_spec_str_len == 0 and length_str : length_spec_str_len = len ( length_str ) # is it an actual format? for spec in all_spec : if nugget . startswith ( spec ) : # this is gross coz sim_type is gross.. nugget = nugget [ : len ( spec ) ] original_nugget = original_nugget [ : ( length_spec_str_len + len ( spec ) ) ] nugtype : 'SimType' = all_spec [ nugget ] try : typeobj = nugtype . with_arch ( self . state . arch if self . state is not None else self . project . arch ) except Exception : raise SimProcedureError ( "format specifier uses unknown type '%s'" % repr ( nugtype ) ) return FormatSpecifier ( original_nugget , length_spec , pad_chr , typeobj . size // 8 , typeobj . signed ) return None