Next / Previous / Contents / Shipman's homepage

22.2. SpTail.__scanSci()

nomcompile3
# - - -   S p T a i l . _ _ s c a n S c i

    def __scanSci ( self, scan ):
        '''Scan the "Genus (Subgenus) species" part of the line.

          [ scan is a Scan instance ->
              if scan starts with a valid scientific name group ->
                scan  :=  scan advanced past that group and
                          any trailing whitespace
                self.genus  :=  genus name from that group
                self.subgenus  :=  subgenus name from that group
                                   or None if missing
                self.species  :=  species name from that group
              else ->
                scan  :=  scan advanced no further than end of line
                Log()  +:=  error message(s)
                raise SyntaxError ]
        '''

All the pattern matching is done in one large regular expression: see Section 6.25, “GENUS_SPECIES_RE. If the beginning of scan matches, the resulting MatchObject will contain three named groups: GENUS_CODE for the genus name, SUBGENUS_FIELD for the subgenus name (which is optional and will return None if omitted), and SPECIES_CODE for the species name.

nomcompile3
        #-- 1 --
        # [ if the line in scan starts with a pattern that matches
        #   GENUS_SPECIES_RE ->
        #     scan  :=  scan advanced past that pattern
        #     self.genus  :=  genus part of the match
        #     self.subgenus  :=  subgenus part of the match, or
        #         None if omitted
        #     self.species  :=  species part of the match
        #   else ->
        #     scan  :=  scan advanced no further than end of line
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        m = scan.tabReMatch ( GENUS_SPECIES_RE )
        if m is None:
            scan.syntax ( "Expecting 'Genus species' or "
                "'Genus (Subgenus) species'." )
        self.genus = m.group ( GENUS_CODE )
        self.subgenus = m.group ( SUBGENUS_FIELD )
        self.species = m.group ( SPECIES_CODE )

        #-- 2 --
        # [ scan  :=  scan advanced past any leading whitespace ]
        scan.deblankLine()