miaowware / ctyparser

A CTY.DAT parser for modern amateur radio programs
https://ctyparser.miaow.io/
MIT License
4 stars 2 forks source link

regex_dat: the order of the overrides is not specified in the spec #19

Open 0x5c opened 4 years ago

0x5c commented 4 years ago

It isn't specified in neither the country-files page or the CT9 manual.

0x5c commented 4 years ago

Can be fixed "simply" if we ignore repeat overrides (ie: 3G7[16][15], where we just consider the last one).

Original regex

r"""=?(?P<prefix>[a-zA-Z0-9/]+)
      (?:\((?P<cq>\d+)\))?
      (?:\[(?P<itu>\d+)\])?
      (?P<latlong>
          <(?P<lat>[+-]?\d+(?:\.\d+)?)
          \/
          (?P<long>[+-]?\d+(?:.\d+)?)>
      )?
      (?:\{(?P<continent>\w+)\})?
      (?:~(?P<tz>[+-]?\d+(?:\.\d+)?)~)?"""

Railroad diagram

Fixed(?) regex

r"""=?(?P<prefix>[a-zA-Z0-9/]+)
      (?:
        (?:\((?P<cq>\d+)\))
        | (?:\[(?P<itu>\d+)\])
        | (?P<latlong>
            <(?P<lat>[+-]?\d+(?:\.\d+)?)
            \/
            (?P<long>[+-]?\d+(?:.\d+)?)>
        )
        | (?:\{(?P<continent>\w+)\})
        | (?:~(?P<tz>[+-]?\d+(?:\.\d+)?)~)
      )*"""

iRailroad diagram

The main problem is that the regex complexity then jumps upwards dramatically

classabbyamp commented 4 years ago

oof damn. good catch

0x5c commented 4 years ago

We need to choose how we approach this.

Note on the "fixed" regex: it's unclear how it would handle a case where multiple overrides of the same types are present for a since call/prefix.

0x5c commented 4 years ago

Other question: Do we decide of that before or after release of 2.0.0?

classabbyamp commented 4 years ago

I think decide later