From 75160df8caaa71ff5f4cfeccfd9d36cf04237923 Mon Sep 17 00:00:00 2001 From: windyboy Date: Sat, 20 Jul 2024 01:17:58 +0800 Subject: [PATCH] feat: Update regex patterns for flight plan parsing The regex patterns used for parsing flight plans have been updated in the `config.go` file. The changes include adding named capture groups for each segment of the flight plan string, allowing for easier extraction of specific information. This update improves the accuracy and flexibility of the flight plan parsing functionality. --- internal/config/config.go | 47 +++++++++++++++++++++++++++++++- internal/parsers/pattern_test.go | 3 -- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index a46fd19..d849d7c 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -45,10 +45,55 @@ type PatternConfig struct { Expression *regexp.Regexp } -// Define the regex patterns as constants const ( + // arrPatternString represents the regular expression pattern used to match arrival patterns. + // The pattern matches strings in the format: "(TYPE-NUMBER-SSR-DEPARTURE-ARRIVAL)". + // The pattern captures the following named groups: + // - type: the three-letter type code + // - number: the alphanumeric flight number + // - ssr: the alphanumeric SSR code + // - departure: the four-letter departure airport code + // - arrival: the four-letter arrival airport code arrPatternString = `^\((?P[A-Z]{3})-(?P[A-Z0-9]+)-(?P[A-Z0-9]+)-(?P[A-Z]{4})-(?P[A-Z]{4})\)$` + + // depPatternString represents the regular expression pattern used to match departure patterns. + // The pattern matches strings in the format: "(TYPE-NUMBER-SSR-DEPARTURE-DEPARTURE_TIME-ARRIVAL)". + // The pattern captures the following named groups: + // - type: the three-letter type code + // - number: the alphanumeric flight number + // - ssr: the alphanumeric SSR code + // - departure: the four-letter departure airport code + // - departure_time: the four-digit departure time + // - arrival: the four-letter arrival airport code depPatternString = `^\((?P[A-Z]{3})-(?P[A-Z0-9]+)-(?P[A-Z0-9]+)-(?P[A-Z]{4})-(?P\d{4})-(?P[A-Z]{4})\)$` + + // fplPatternString is a regular expression designed to parse and extract detailed information from formatted flight plan strings. + // The flight plan string is expected to follow a specific format, encapsulated by parentheses and containing various segments separated by hyphens. + // Each segment captures a different aspect of the flight plan, as detailed below: + // + // - type: Matches a three-letter flight type code. + // - number: Matches the flight number, consisting of letters followed by digits. + // - indicator: Matches a two-letter indicator. + // - aircraft: Matches the aircraft registration or type, which may include a slash and an optional letter. + // - surve: Matches surveillance equipment information, capturing any characters in this segment. + // - departure: Matches the four-letter code of the departure airport. + // - departure_time: Matches the four-digit departure time. + // - speed: Matches the speed, consisting of letters followed by digits. + // - level: Matches the flight level, which can include letters and digits. + // - route: Matches the flight route, capturing any characters in this segment. + // - destination: Matches the four-letter code of the destination airport. + // - estt: Matches the four-digit estimated time of arrival. + // - alter: Matches the four-letter code of an alternate airport. + // - pbn: Matches performance-based navigation equipment information. + // - nav: Matches navigation equipment information. + // - reg: Matches the aircraft registration. + // - eet: Matches the estimated elapsed time, including the four-letter code and four-digit time. + // - sel: Matches the SELCAL code. + // - performance: Matches a single letter indicating the aircraft's performance category. + // - rif: Matches reroute information, including any characters in this segment. + // - remark: Matches remarks, capturing any characters in this segment. + // + // The regular expression uses named capture groups for each segment, allowing for easy extraction of specific information from a matched flight plan string. fplPatternString = `^\((?P[A-Z]{3})\-(?P[A-Z]+\d+)\-(?P[A-Z]{2})(?:.*\s*)?\-(?P[A-Z]+\d+\/?[A-Z]?)\s*\-(?P.*)\s*\-(?P[A-Z]{4})(?P\d{4})\s*\-(?P[A-Z]+\d+)(?P[A-Z0-9]+)\s(?P.*)\s*\-(?P[A-Z]{4})(?P\d{4})\s(?P[A-Z]{4})\s*\-(?PPBN\/[A-Z0-9]+)\s(?P