Beispiel #1
0
        public void ParseData(AbstractSectorDataFile data)
        {
            // Loop the lines to get the data out
            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count != 4)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid number of ACTIVE_RUNWAY segments", line)
                        );
                    return;
                }

                if (line.dataSegments[0] != "ACTIVE_RUNWAY")
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Active runway declarations must begin with ACTIVE_RUNWAY", line)
                        );
                    return;
                }

                if (!AirportValidator.IcaoValid(line.dataSegments[1]))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid airport ICAO for Active runway declaration", line)
                        );
                    return;
                }

                if (!RunwayValidator.RunwayValid(line.dataSegments[2]))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid runway designator for Active runway declaration", line)
                        );
                    return;
                }

                if (!int.TryParse(line.dataSegments[3], out int mode) || (mode != 0 && mode != 1))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid mode for Active runway declaration", line)
                        );
                    this.eventLogger.AddEvent(
                        new ParserSuggestion("Valid modes for Active runways are 0 and 1")
                        );
                    return;
                }

                this.elements.Add(
                    new ActiveRunway(
                        line.dataSegments[2],
                        line.dataSegments[1],
                        mode,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }
Beispiel #2
0
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count != 3)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Incorrect number of FIX segments", line)
                        );
                    continue;
                }

                // Parse the coordinate
                Coordinate parsedCoordinate = CoordinateParser.Parse(line.dataSegments[1], line.dataSegments[2]);
                if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid coordinate format: " + data.CurrentLine, line)
                        );
                    return;
                }

                this.elements.Add(
                    new Fix(line.dataSegments[0], parsedCoordinate, line.definition, line.docblock, line.inlineComment)
                    );
            }
        }
Beispiel #3
0
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count != 4)
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Incorrect number of Freetext segments", line)
                        );
                    return;
                }

                Coordinate parsedCoordinate = CoordinateParser.Parse(line.dataSegments[0], line.dataSegments[1]);
                if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid coordinate format: " + data.CurrentLine, line)
                        );
                    return;
                }


                this.sectorElements.Add(
                    new Freetext(
                        line.dataSegments[2],
                        line.dataSegments[3],
                        parsedCoordinate,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count != 5)
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Incorrect number of SIDSTAR segments", line)
                        );
                    continue;
                }

                if (line.dataSegments[0] != "SID" && line.dataSegments[0] != "STAR")
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Unknown SIDSTAR type " + line.dataSegments[0], line)
                        );
                    continue;
                }

                this.sectorElements.Add(
                    new SidStar(
                        line.dataSegments[0],
                        line.dataSegments[1],
                        line.dataSegments[2],
                        line.dataSegments[3],
                        line.dataSegments[4].Split(' ').Where(s => !string.IsNullOrEmpty(s)).ToList(),
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            List <HeaderLine> lines = new List <HeaderLine>();

            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count != 0)
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Cannot define data in file headers", line)
                        );
                    continue;
                }

                lines.Add(
                    new HeaderLine(
                        line.inlineComment,
                        line.definition
                        )
                    );
            }

            sectorElements.Add(
                new Header(
                    new Definition(data.FullPath, 0),
                    lines
                    )
                );
        }
Beispiel #6
0
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count != 3)
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid number of colour definition segments", line)
                        );
                    continue;
                }

                if (line.dataSegments[0] != "#define")
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Colour definitions must begin with #define", line)
                        );
                    continue;
                }

                if (!int.TryParse(line.dataSegments[2].Trim(), out int colourValue))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Defined colour values must be an integer", line)
                        );
                    continue;
                }

                sectorElements.Add(
                    new Colour(line.dataSegments[1], colourValue, line.definition, line.docblock, line.inlineComment)
                    );
            }
        }
Beispiel #7
0
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count != 4)
                {
                    eventLogger.AddEvent(new SyntaxError("Invalid number of runway centreline segments", line));
                    return;
                }

                if (!CoordinateParser.TryParse(line.dataSegments[0], line.dataSegments[1], out Coordinate firstCoordinate))
                {
                    eventLogger.AddEvent(new SyntaxError("Invalid first runway centreline coordinate", line));
                    return;
                }

                if (!CoordinateParser.TryParse(line.dataSegments[2], line.dataSegments[3], out Coordinate secondCoordinate))
                {
                    eventLogger.AddEvent(new SyntaxError("Invalid second runway centreline coordinate", line));
                    return;
                }

                // Create the segment once and share it to save memory
                RunwayCentrelineSegment segment = new(firstCoordinate, secondCoordinate);
                sectorElements.Add(new RunwayCentreline(segment, line.definition, line.docblock, line.inlineComment));
                sectorElements.Add(new FixedColourRunwayCentreline(segment, line.definition, line.docblock, line.inlineComment));
            }
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                // Check everything starts ok
                if (line.rawData.Count(c => c == '"') != 2)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Labels may contain exactly two double quotes", line)
                        );
                    continue;
                }

                if (line.rawData[0] != '"')
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Labels must start with a name encased in quotes", line)
                        );
                    continue;
                }

                // Get the name out and take the name segments off
                int    endOfNameIndex = this.GetEndOfNameIndex(line);
                string name           = string.Join(' ', line.dataSegments.GetRange(0, endOfNameIndex)).Trim('"');
                line.dataSegments.RemoveRange(0, endOfNameIndex);

                if (line.dataSegments.Count != 3)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid number of LABEL segments, expected 3", line)
                        );
                    continue;
                }

                // Parse the position coordinate
                Coordinate parsedCoordinate = CoordinateParser.Parse(line.dataSegments[0], line.dataSegments[1]);
                if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid label coordinate format: " + data.CurrentLine, line)
                        );
                    continue;
                }

                // Add to the sector elements
                sectorElements.Add(
                    new Label(
                        name,
                        parsedCoordinate,
                        line.dataSegments[2],
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }
 public ISectorDataParser GetParserForFile(AbstractSectorDataFile file)
 {
     return(file.DataType switch
     {
         InputDataType.SCT_COLOUR_DEFINITIONS => new ColourParser(sectorElements, logger),
         InputDataType.SCT_AIRPORT_BASIC => new AirportParser(sectorElements, logger),
         InputDataType.SCT_FIXES => new FixParser(sectorElements, logger),
         InputDataType.SCT_VORS => new VorParser(
             new FrequencyParser(108, 117, 50),
             sectorElements,
             logger
             ),
         InputDataType.SCT_NDBS => new NdbParser(new FrequencyParser(108, 950, 500), sectorElements, logger),
         InputDataType.SCT_ARTCC => new ArtccParser(ArtccType.REGULAR, sectorElements, logger),
         InputDataType.SCT_ARTCC_LOW => new ArtccParser(ArtccType.LOW, sectorElements, logger),
         InputDataType.SCT_ARTCC_HIGH => new ArtccParser(ArtccType.HIGH, sectorElements, logger),
         InputDataType.SCT_LOWER_AIRWAYS => new AirwayParser(AirwayType.LOW, sectorElements, logger),
         InputDataType.SCT_UPPER_AIRWAYS => new AirwayParser(AirwayType.HIGH, sectorElements, logger),
         InputDataType.SCT_SIDS => new SidStarRouteParser(sectorElements, logger, SidStarType.SID),
         InputDataType.SCT_STARS => new SidStarRouteParser(sectorElements, logger, SidStarType.STAR),
         InputDataType.SCT_GEO => new GeoParser(sectorElements, logger),
         InputDataType.SCT_LABELS => new LabelParser(sectorElements, logger),
         InputDataType.SCT_REGIONS => new RegionParser(sectorElements, logger),
         InputDataType.SCT_INFO => new InfoParser(sectorElements, logger),
         InputDataType.SCT_RUNWAYS => new RunwayParser(sectorElements, logger),
         InputDataType.SCT_RUNWAY_CENTRELINES => new RunwayCentrelineParser(sectorElements, logger),
         InputDataType.ESE_POSITIONS => new EsePositionParser(
             new VatsimRtfFrequencyParser(),
             sectorElements,
             logger,
             PositionOrder.CONTROLLER_POSITION
             ),
         InputDataType.ESE_POSITIONS_MENTOR => new EsePositionParser(
             new VatsimRtfFrequencyParser(),
             sectorElements,
             logger,
             PositionOrder.MENTOR_POSITION
             ),
         InputDataType.ESE_FREETEXT => new FreetextParser(sectorElements, logger),
         InputDataType.ESE_SIDS => new SidStarParser(sectorElements, logger),
         InputDataType.ESE_STARS => new SidStarParser(sectorElements, logger),
         InputDataType.ESE_SECTORLINES => new SectorlineParser(sectorElements, logger),
         InputDataType.ESE_AGREEMENTS => new CoordinationPointParser(sectorElements, logger),
         InputDataType.ESE_OWNERSHIP => new SectorParser(sectorElements, logger),
         InputDataType.RWY_ACTIVE_RUNWAY => new ActiveRunwayParser(sectorElements, logger),
         InputDataType.FILE_HEADERS => new HeaderParser(sectorElements, logger),
         InputDataType.ESE_PRE_POSITIONS => new EsePositionParser(
             new EuroscopeNoFrequencyParser(),
             sectorElements,
             logger,
             PositionOrder.PRE_POSITION
             ),
         InputDataType.ESE_VRPS => new VrpParser(sectorElements, logger),
         InputDataType.ESE_GROUND_NETWORK => new GroundNetworkParser(sectorElements, logger),
         _ => throw new NotImplementedException(
             $"Parser not not implemented for input data type {file.DataType.ToString()}")
     });
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count != 4)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Incorrect number of VOR segments", line)
                        );
                    continue;
                }

                // Check the identifier
                if (
                    line.dataSegments[0].Any(char.IsDigit) ||
                    (line.dataSegments[0].Length != 2 && line.dataSegments[0].Length != 3)
                    )
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid VOR identifier: " + line.dataSegments[1], line)
                        );
                    return;
                }

                // Parse the frequency
                if (this.frequencyParser.ParseFrequency(line.dataSegments[1]) == null)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid VOR frequency: " + line.dataSegments[1], line)
                        );
                    return;
                }

                // Parse the coordinate
                Coordinate parsedCoordinate = CoordinateParser.Parse(line.dataSegments[2], line.dataSegments[3]);
                if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid coordinate format: " + data.CurrentLine, line)
                        );
                    return;
                }

                this.elements.Add(
                    new Vor(
                        line.dataSegments[0],
                        line.dataSegments[1],
                        parsedCoordinate,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            List <SectorData> linesToProcess = new List <SectorData>();
            bool foundFirst = false;

            foreach (SectorData line in data)
            {
                // We haven't yet started a SID/STAR route, so make sure we have a new declaration
                if (
                    !foundFirst &&
                    (this.GetFirstPointIndex(line) == -1 ||
                     this.GetFirstPointIndex(line) == 0)
                    )
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid new SIDSTAR route declaration", line)
                        );
                    return;
                }
                else if (!foundFirst)
                {
                    linesToProcess.Add(line);
                    foundFirst = true;
                    continue;
                }

                // We've reached the end of the segment, time to make the thing and start over!
                int firstPointIndex = this.GetFirstPointIndex(line);
                if (firstPointIndex == -1)
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Unable to find first point in SID/STAR route", line)
                        );
                    this.errorLog.AddEvent(new ParserSuggestion("Have you provided valid coordinates?"));
                    return;
                }
                else if (firstPointIndex != 0)
                {
                    this.ProcessSidStar(linesToProcess);
                    linesToProcess.Clear();
                    linesToProcess.Add(line);
                    continue;
                }

                // It may be a standard route line with no identifier present (we validate it later)
                linesToProcess.Add(line);
            }

            // If we've got some lines left over, process them now
            if (linesToProcess.Count != 0)
            {
                this.ProcessSidStar(linesToProcess);
            }
        }
        private GroundNetworkRunwayExit ProcessExit(AbstractSectorDataFile file, List <SectorData> lines)
        {
            SectorData declarationLine = lines[0];

            if (declarationLine.dataSegments.Count != 5)
            {
                errorLog.AddEvent(
                    new SyntaxError("Invalid number of EXIT declaration segments", declarationLine)
                    );
                throw new ArgumentException();
            }

            if (!RunwayValidator.RunwayValid(declarationLine.dataSegments[1]))
            {
                errorLog.AddEvent(
                    new SyntaxError("Invalid runway in EXIT declaration", declarationLine)
                    );
                throw new ArgumentException();
            }

            if (declarationLine.dataSegments[3] != "LEFT" && declarationLine.dataSegments[3] != "RIGHT")
            {
                errorLog.AddEvent(
                    new SyntaxError(
                        "Invalid exit direction in EXIT declaration, must be LEFT or RIGHT",
                        declarationLine
                        )
                    );
                throw new ArgumentException();
            }

            if (
                !int.TryParse(declarationLine.dataSegments[4], out int maximumSpeed) ||
                maximumSpeed < 1
                )
            {
                errorLog.AddEvent(
                    new SyntaxError("Invalid maximum speed in EXIT declaration", declarationLine)
                    );
                throw new ArgumentException();
            }

            return(new GroundNetworkRunwayExit(
                       declarationLine.dataSegments[1],
                       declarationLine.dataSegments[2],
                       declarationLine.dataSegments[3],
                       maximumSpeed,
                       ProcessCoordinates(file, lines.GetRange(1, lines.Count - 1), ExitDeclaration),
                       declarationLine.definition,
                       declarationLine.docblock,
                       declarationLine.inlineComment
                       ));
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            bool doneFirstLine = false;
            List <SectorData>              lines    = new();
            List <GroundNetworkTaxiway>    taxiways = new();
            List <GroundNetworkRunwayExit> exits    = new();

            foreach (SectorData line in data)
            {
                if (!doneFirstLine)
                {
                    lines.Add(line);
                    doneFirstLine = true;
                }
                else if (IsNewDeclaration(line))
                {
                    try
                    {
                        ProcessLines(data, lines, taxiways, exits);
                    }
                    catch
                    {
                        return;
                    }
                    lines.Clear();
                    lines.Add(line);
                }
                else
                {
                    lines.Add(line);
                }
            }

            if (lines.Any())
            {
                try
                {
                    ProcessLines(data, lines, taxiways, exits);
                }
                catch
                {
                    return;
                }
            }

            sectorElements.Add(
                new GroundNetwork(
                    data.GetParentDirectoryName(),
                    taxiways,
                    exits
                    )
                );
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            List <SectorData> linesToProcess = new List <SectorData>();
            bool foundFirst = false;

            foreach (SectorData line in data)
            {
                if (
                    !foundFirst &&
                    !this.IsNewDeclaration(line)
                    )
                {
                    {
                        this.errorLog.AddEvent(
                            new SyntaxError("Invalid SECTORLINE declaration", line)
                            );
                        return;
                    }
                }

                if (!foundFirst)
                {
                    linesToProcess.Add(line);
                    foundFirst = true;
                    continue;
                }

                if (this.IsNewDeclaration(line))
                {
                    try
                    {
                        this.ProcessLines(ref linesToProcess);
                    } catch
                    {
                        // Logging done higher up
                        return;
                    }
                    linesToProcess.Clear();
                }

                linesToProcess.Add(line);
            }

            try
            {
                this.ProcessLines(ref linesToProcess);
            }
            catch
            {
                // Logging done higher up
            }
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count != 4)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Incorrect number of Airway segments", line)
                        );
                    continue;
                }

                // Parse the airway segment point
                Point startPoint = PointParser.Parse(line.dataSegments[0], line.dataSegments[1]);
                if (startPoint.Equals(PointParser.InvalidPoint))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid Airway start point format: " + data.CurrentLine, line)
                        );
                    return;
                }


                // Parse the segment endpoint
                Point endPoint = PointParser.Parse(line.dataSegments[2], line.dataSegments[3]);
                if (endPoint.Equals(PointParser.InvalidPoint))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid Airway end point format: " + data.CurrentLine, line)
                        );
                    return;
                }

                // Add it to the collection
                this.elements.Add(
                    new AirwaySegment(
                        data.GetFileName(),  // Each airway is in a file with its name
                        this.airwayType,
                        startPoint,
                        endPoint,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                if (line.dataSegments.Count < 5)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Incorrect number of ARTCC segments", line)
                        );
                    continue;
                }

                int count = line.dataSegments.Count;

                // The points are at the end, so work backwards
                Point endPoint = PointParser.Parse(line.dataSegments[count - 2], line.dataSegments[count - 1]);
                if (endPoint.Equals(PointParser.InvalidPoint))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid ARTCC end point format: " + data.CurrentLine, line)
                        );
                    return;
                }

                Point startPoint = PointParser.Parse(line.dataSegments[count - 4], line.dataSegments[count - 3]);
                if (startPoint.Equals(PointParser.InvalidPoint))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid ARTCC start point format: " + data.CurrentLine, line)
                        );
                    return;
                }

                // Add it
                this.elements.Add(
                    new ArtccSegment(
                        string.Join(" ", line.dataSegments.GetRange(0, count - 4)),
                        this.artccType,
                        startPoint,
                        endPoint,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }
        private void ProcessLines(
            AbstractSectorDataFile file,
            List <SectorData> lines,
            List <GroundNetworkTaxiway> taxiways,
            List <GroundNetworkRunwayExit> exits
            )
        {
            switch (lines[0].dataSegments[0])
            {
            case TaxiDeclaration:
                taxiways.Add(ProcessTaxiway(file, lines));
                break;

            case ExitDeclaration:
                exits.Add(ProcessExit(file, lines));
                break;

            default:
                errorLog.AddEvent(new SyntaxError("Unknown ground network declaration type", lines[0]));
                throw new ArgumentException();
            }
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            // Get all the lines out up-front
            List <SectorData> lines = new List <SectorData>();

            foreach (SectorData line in data)
            {
                lines.Add(line);
            }

            if (lines.Count != 9)
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid number of INFO lines", data.FullPath)
                    );
                return;
            }

            try
            {
                this.elements.Add(
                    new Info(
                        this.GetName(lines[0]),
                        this.GetCallsign(lines[1]),
                        this.GetAirport(lines[2]),
                        this.GetLatitude(lines[3], lines[4]),
                        this.GetLongitude(lines[3], lines[4]),
                        this.GetMilesPerDegreeLatitude(lines[5]),
                        this.GetInfoMilesPerDegreeLongitude(lines[6]),
                        this.GetMagneticVariation(lines[7]),
                        this.GetScale(lines[8])
                        )
                    );
            } catch
            {
                // Exceptions dealt with in handler functions
            }
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            // Validate the folder name
            if (!AirportValidator.ValidEuroscopeAirport(data.GetParentDirectoryName()))
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid airport ICAO", data.FullPath)
                    );
                return;
            }

            int linesParsed = 0;

            SectorData nameLine       = new SectorData();
            SectorData coordinateLine = new SectorData();
            SectorData frequencyLine  = new SectorData();


            // Loop the lines to get the data out
            foreach (SectorData line in data)
            {
                if (linesParsed == 0)
                {
                    nameLine = line;
                    linesParsed++;
                    continue;
                }
                else if (linesParsed == 1)
                {
                    coordinateLine = line;
                    linesParsed++;
                    continue;
                }
                else if (linesParsed == 2)
                {
                    frequencyLine = line;
                    linesParsed++;
                    continue;
                }

                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid number of airport lines", line)
                    );
                return;
            }

            // Check the syntax
            if (linesParsed != 3)
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid number of airport lines", data.FullPath)
                    );
                return;
            }

            // Parse the coordinate
            if (coordinateLine.dataSegments.Count != 2)
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid coordinate format for airport: " + coordinateLine.rawData, coordinateLine)
                    );
                return;
            }

            Coordinate parsedCoordinate = CoordinateParser.Parse(coordinateLine.dataSegments[0], coordinateLine.dataSegments[1]);

            if (parsedCoordinate.Equals(CoordinateParser.InvalidCoordinate))
            {
                this.eventLogger.AddEvent(
                    new SyntaxError("Invalid coordinate format for airport: " + coordinateLine.rawData, coordinateLine)
                    );
                return;
            }

            this.elements.Add(
                new Airport(
                    nameLine.rawData,
                    data.GetParentDirectoryName(),
                    parsedCoordinate,
                    frequencyLine.rawData,
                    nameLine.definition,
                    nameLine.docblock,
                    nameLine.inlineComment
                    )
                );
        }
Beispiel #20
0
        protected void RunParserOnLines(List <string> lines)
        {
            AbstractSectorDataFile file = GetInputFile(lines);

            new DataParserFactory(sectorElementCollection, logger.Object).GetParserForFile(file).ParseData(file);
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            bool foundFirst = false;

            // Set up some variables for the first declaration line
            string     name = "";
            Point      initialFirstPoint  = new Point("");
            Point      initialSecondPoint = new Point("");
            string     initialColour      = "0";
            Definition initialDefinition  = new Definition("", 1);
            Comment    initialComment     = new Comment("");
            Docblock   initialDocblock    = new Docblock();

            List <GeoSegment> segments = new List <GeoSegment>();

            foreach (SectorData line in data)
            {
                // If not found the first item, we should check it's a name.
                if (!foundFirst)
                {
                    if (!this.IsNameSegment(line))
                    {
                        this.eventLogger.AddEvent(
                            new SyntaxError("Invalid start to geo segment, expected a name", line)
                            );
                        return;
                    }

                    foundFirst = true;

                    // Set up the segment
                    int nameEndIndex = this.GetEndOfNameIndex(line);
                    name = string.Join(' ', line.dataSegments.GetRange(0, nameEndIndex));
                    line.dataSegments.RemoveRange(0, nameEndIndex);

                    try
                    {
                        GeoSegment firstSegment = this.ParseGeoSegment(line);
                        initialFirstPoint  = firstSegment.FirstPoint;
                        initialSecondPoint = firstSegment.SecondPoint;
                        initialColour      = firstSegment.Colour;
                        initialDefinition  = firstSegment.GetDefinition();
                        initialDocblock    = firstSegment.Docblock;
                        initialComment     = firstSegment.InlineComment;
                    }
                    catch (ArgumentException)
                    {
                        // Syntax errors dealt with in segment parsing method
                        return;
                    }

                    continue;
                }

                // If it's a name segment, we should save our progress and start afresh
                if (this.IsNameSegment(line))
                {
                    // Add the full geo element
                    this.elements.Add(
                        new Geo(
                            name,
                            initialFirstPoint,
                            initialSecondPoint,
                            initialColour,
                            segments,
                            initialDefinition,
                            initialDocblock,
                            initialComment
                            )
                        );

                    // Reset the segments array
                    segments = new List <GeoSegment>();

                    // Set up the segment
                    int nameEndIndex = this.GetEndOfNameIndex(line);
                    name = string.Join(' ', line.dataSegments.GetRange(0, nameEndIndex));
                    line.dataSegments.RemoveRange(0, nameEndIndex);

                    try
                    {
                        GeoSegment firstSegment = this.ParseGeoSegment(line);
                        initialFirstPoint  = firstSegment.FirstPoint;
                        initialSecondPoint = firstSegment.SecondPoint;
                        initialColour      = firstSegment.Colour;
                        initialDefinition  = firstSegment.GetDefinition();
                        initialDocblock    = firstSegment.Docblock;
                        initialComment     = firstSegment.InlineComment;
                    }
                    catch (ArgumentException)
                    {
                        // Syntax errors dealt with in segment parsing method
                        return;
                    }

                    continue;
                }

                // Otherwise, process the segment
                try
                {
                    segments.Add(this.ParseGeoSegment(line));
                }
                catch
                {
                    // Syntax errors dealt with in segment parsing method
                    return;
                }
            }

            // Add final geo element
            this.elements.Add(
                new Geo(
                    name,
                    initialFirstPoint,
                    initialSecondPoint,
                    initialColour,
                    segments,
                    initialDefinition,
                    initialDocblock,
                    initialComment
                    )
                );
        }
        private List <GroundNetworkCoordinate> ProcessCoordinates(
            AbstractSectorDataFile file,
            List <SectorData> lines,
            string parentElementType
            )
        {
            if (lines.Count == 0)
            {
                errorLog.AddEvent(
                    new SyntaxError(
                        $"All ground network {parentElementType} declarations must have at least one coordinate",
                        file.GetFileName()
                        )
                    );
                throw new ArgumentException();
            }

            List <GroundNetworkCoordinate> coordinates = new();

            for (int i = 0; i < lines.Count; i++)
            {
                SectorData line = lines[i];
                if (line.dataSegments.Count != 3)
                {
                    errorLog.AddEvent(
                        new SyntaxError($"Invalid number of {parentElementType} COORD segments", lines[i])
                        );
                    throw new ArgumentException();
                }

                if (line.dataSegments[0] != "COORD")
                {
                    errorLog.AddEvent(
                        new SyntaxError($"Invalid COORD in {parentElementType} declaration", lines[i])
                        );
                    throw new ArgumentException();
                }

                if (
                    !CoordinateParser.TryParse(
                        line.dataSegments[1],
                        line.dataSegments[2],
                        out Coordinate parsedCoordinate
                        )
                    )
                {
                    errorLog.AddEvent(
                        new SyntaxError($"Invalid coordinate in {parentElementType} declaration", lines[i])
                        );
                    throw new ArgumentException();
                }

                coordinates.Add(
                    new GroundNetworkCoordinate(
                        parsedCoordinate,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }

            return(coordinates);
        }
        public void ProcessLines(ref List <SectorData> lines, AbstractSectorDataFile file)
        {
            if (lines.Count == 0)
            {
                return;
            }

            SectorData declarationLine = lines[0];

            int minimumAltitude;
            int maximumAltitude;

            if (declarationLine.dataSegments[0] != "SECTOR")
            {
                this.errorLog.AddEvent(
                    new SyntaxError("Invalid SECTOR declaration", declarationLine)
                    );
                return;
            }

            // Check the minimum and maximum altitudes
            if (!int.TryParse(declarationLine.dataSegments[2], out minimumAltitude))
            {
                this.errorLog.AddEvent(
                    new SyntaxError("SECTOR minimum altitude must be an integer", declarationLine)
                    );
                return;
            }

            if (!int.TryParse(declarationLine.dataSegments[3], out maximumAltitude))
            {
                this.errorLog.AddEvent(
                    new SyntaxError("SECTOR maximum altitude must be an integer", declarationLine)
                    );
                return;
            }

            SectorOwnerHierarchy ownerHierarchy              = null;
            List <SectorAlternateOwnerHierarchy> altOwners   = new List <SectorAlternateOwnerHierarchy>();
            List <SectorBorder>            borders           = new List <SectorBorder>();
            List <SectorActive>            actives           = new List <SectorActive>();
            List <SectorGuest>             guests            = new List <SectorGuest>();
            List <SectorDepartureAirports> departureAirports = new List <SectorDepartureAirports>();
            List <SectorArrivalAirports>   arrivalAirports   = new List <SectorArrivalAirports>();

            for (int i = 1; i < lines.Count; i++)
            {
                try
                {
                    switch (lines[i].dataSegments[0])
                    {
                    case "OWNER":
                        ownerHierarchy = this.ParseOwnerHierarchy(lines[i]);
                        break;

                    case "ALTOWNER":
                        altOwners.Add(this.ParseAlternateOwnerHierarchy(lines[i]));
                        break;

                    case "BORDER":
                        borders.Add(this.ParseBorder(lines[i]));
                        break;

                    case "ACTIVE":
                        actives.Add(this.ParseActive(lines[i]));
                        break;

                    case "GUEST":
                        guests.Add(this.ParseGuest(lines[i]));
                        break;

                    case "DEPAPT":
                        departureAirports.Add(this.ParseDepartureAirport(lines[i]));
                        break;

                    case "ARRAPT":
                        arrivalAirports.Add(this.ParseArrivalAirport(lines[i]));
                        break;

                    default:
                        this.errorLog.AddEvent(
                            new SyntaxError("Unknown SECTOR line type", lines[i])
                            );
                        return;
                    }
                }
                catch (ArgumentException exception)
                {
                    this.errorLog.AddEvent(
                        new SyntaxError(exception.Message, lines[i])
                        );
                    return;
                }
            }

            if (ownerHierarchy == null)
            {
                this.errorLog.AddEvent(
                    new SyntaxError("Every SECTOR must have an owner", declarationLine)
                    );
                this.errorLog.AddEvent(
                    new ParserSuggestion("Have you added an OWNER declaration?")
                    );
                return;
            }

            this.sectorElements.Add(
                new Sector(
                    declarationLine.dataSegments[1],
                    minimumAltitude,
                    maximumAltitude,
                    ownerHierarchy,
                    altOwners,
                    actives,
                    guests,
                    borders,
                    arrivalAirports,
                    departureAirports,
                    declarationLine.definition,
                    declarationLine.docblock,
                    declarationLine.inlineComment
                    )
                );
        }
        public void ParseData(AbstractSectorDataFile data)
        {
            List <RegionPoint> points                = new List <RegionPoint>();
            bool       foundFirst                    = false;
            string     regionName                    = "";
            bool       expectingColourDefinition     = false;
            bool       expectingRegionNameDefinition = true;
            SectorData declarationLine               = new SectorData();

            foreach (SectorData line in data)
            {
                // Check for the first REGIONNAME
                if (expectingRegionNameDefinition && (line.dataSegments.Count < 2 || !line.rawData.StartsWith(RegionParser.RegionNameDeclaration)))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid first line of region " + data.CurrentLine, line)
                        );
                    return;
                }

                if (expectingColourDefinition && line.dataSegments.Count != 3)
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Unexpected colour definition " + data.CurrentLine, line)
                        );
                    return;
                }

                // We've found our first region name if we get here for the first time, so we don't demand another in this file
                expectingRegionNameDefinition = false;

                // Expecting a colour definition for the region
                if (expectingColourDefinition)
                {
                    if (line.dataSegments.Count != 3)
                    {
                        this.eventLogger.AddEvent(
                            new SyntaxError("All regions must have a colour " + data.CurrentLine, line)
                            );
                        return;
                    }

                    // Setup a new segment
                    Point parsedNewPoint = PointParser.Parse(line.dataSegments[1], line.dataSegments[2]);
                    if (parsedNewPoint.Equals(PointParser.InvalidPoint))
                    {
                        this.eventLogger.AddEvent(
                            new SyntaxError("Invalid region point format: " + data.CurrentLine, line)
                            );
                        return;
                    }

                    points.Add(
                        new RegionPoint(
                            parsedNewPoint,
                            line.definition,
                            line.docblock,
                            line.inlineComment,
                            line.dataSegments[0]
                            )
                        );
                    expectingColourDefinition = false;
                    continue;
                }


                /*
                 * We've found a new REGIONNAME declaration, so must be the start of a new region.
                 */
                if (line.rawData.StartsWith(RegionParser.RegionNameDeclaration))
                {
                    // If it's not the first in the data stream, then it's a new declaration, save the previous
                    if (foundFirst)
                    {
                        if (points.Count == 0)
                        {
                            this.eventLogger.AddEvent(
                                new SyntaxError("Cannot have region with no points" + data.CurrentLine, line)
                                );
                            return;
                        }

                        this.elements.Add(
                            new Region(
                                regionName,
                                points,
                                declarationLine.definition,
                                declarationLine.docblock,
                                declarationLine.inlineComment
                                )
                            );

                        // Clear the segments array
                        points = new List <RegionPoint>();
                    }
                    else
                    {
                        foundFirst = true;
                    }

                    // Save the new declaration line
                    declarationLine = line;
                    regionName      = string.Join(" ", line.dataSegments.Skip(1));

                    // Immediately after REGIONNAME, we should expect a colour definition
                    expectingColourDefinition = true;
                    continue;
                }

                Point parsedPoint = PointParser.Parse(line.dataSegments[0], line.dataSegments[1]);
                if (Equals(parsedPoint, PointParser.InvalidPoint))
                {
                    this.eventLogger.AddEvent(
                        new SyntaxError("Invalid region point format: " + data.CurrentLine, line)
                        );
                    return;
                }

                points.Add(
                    new RegionPoint(
                        parsedPoint,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }

            // We shouldn't end without a fully defined region
            if (expectingColourDefinition)
            {
                this.eventLogger.AddEvent(
                    new SyntaxError(
                        "Incomplete region at end of file",
                        data.FullPath
                        )
                    );
                return;
            }

            // Add the last element
            this.elements.Regions.Add(
                new Region(
                    regionName,
                    points,
                    declarationLine.definition,
                    declarationLine.docblock,
                    declarationLine.inlineComment
                    )
                );
        }
Beispiel #25
0
        public void ParseData(AbstractSectorDataFile data)
        {
            foreach (SectorData line in data)
            {
                // Runways are weird and have double spaces randomly, so handle it.
                if (line.dataSegments.Count < 8)
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Too few RUNWAY segments", line)
                        );
                    continue;
                }

                // Check the two identifiers
                if (!RunwayValidator.RunwayValidIncludingAdjacent(line.dataSegments[0]))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid runway designator " + line.dataSegments[0], line)
                        );
                    continue;
                }

                if (!RunwayValidator.RunwayValidIncludingAdjacent(line.dataSegments[1]))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid runway designator " + line.dataSegments[1], line)
                        );
                    continue;
                }

                // Check the two headings
                if (!this.HeadingIsValid(line.dataSegments[2]))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid runway heading " + line.dataSegments[2], line)
                        );
                    continue;
                }

                if (!this.HeadingIsValid(line.dataSegments[3]))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid runway heading " + line.dataSegments[3], line)
                        );
                    continue;
                }

                // Check the two coordinates
                Coordinate firstThreshold = CoordinateParser.Parse(line.dataSegments[4], line.dataSegments[5]);
                if (firstThreshold.Equals(CoordinateParser.InvalidCoordinate))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid runway first threshold ", line)
                        );
                    continue;
                }

                Coordinate reverseThreshold = CoordinateParser.Parse(line.dataSegments[6], line.dataSegments[7]);
                if (reverseThreshold.Equals(CoordinateParser.InvalidCoordinate))
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid runway reverse threshold ", line)
                        );
                    continue;
                }

                // Compile together the airfield description
                if (line.dataSegments.Count > 8)
                {
                    string.Join(
                        " ",
                        line.dataSegments
                        .Skip(8)
                        .Take(line.dataSegments.Count - 8)
                        .ToList()
                        );
                }


                // Add the element
                this.sectorElements.Add(
                    new Runway(
                        data.GetParentDirectoryName(),
                        line.dataSegments[0],
                        int.Parse(line.dataSegments[2]),
                        firstThreshold,
                        line.dataSegments[1],
                        int.Parse(line.dataSegments[3]),
                        reverseThreshold,
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }
 public InputFileListTest()
 {
     this.file1    = SectorDataFileFactoryFactory.Make(new List <string>()).Create("test.txt", InputDataType.ESE_AGREEMENTS);
     this.file2    = SectorDataFileFactoryFactory.Make(new List <string>()).Create("test2.txt", InputDataType.ESE_AGREEMENTS);
     this.fileList = new InputFileList();
 }
        private GroundNetworkTaxiway ProcessTaxiway(AbstractSectorDataFile file, List <SectorData> lines)
        {
            SectorData declarationLine = lines[0];

            if (declarationLine.dataSegments.Count < 3 || declarationLine.dataSegments.Count > 5)
            {
                errorLog.AddEvent(
                    new SyntaxError("Invalid number of TAXI declaration segments", declarationLine)
                    );
                throw new ArgumentException();
            }

            if (
                !int.TryParse(declarationLine.dataSegments[2], out int maximumSpeed) ||
                maximumSpeed < 1
                )
            {
                errorLog.AddEvent(
                    new SyntaxError("Invalid maximum speed in TAXI declaration", declarationLine)
                    );
                throw new ArgumentException();
            }


            int?usageFlag = null;

            if (
                declarationLine.dataSegments.Count >= 4 &&
                declarationLine.dataSegments[3] != ""
                )
            {
                if (
                    !int.TryParse(declarationLine.dataSegments[3], out int parsedUsageFlag) ||
                    parsedUsageFlag < 1 ||
                    parsedUsageFlag > 3
                    )
                {
                    errorLog.AddEvent(
                        new SyntaxError("Invalid usage flag in TAXI declaration", declarationLine)
                        );
                    throw new ArgumentException();
                }

                usageFlag = parsedUsageFlag;
            }

            string gateName = declarationLine.dataSegments.Count == 5
                ? (declarationLine.dataSegments[4] == "" ? null : declarationLine.dataSegments[4])
                : null;

            return(new GroundNetworkTaxiway(
                       declarationLine.dataSegments[1],
                       maximumSpeed,
                       usageFlag,
                       gateName,
                       ProcessCoordinates(file, lines.GetRange(1, lines.Count - 1), TaxiDeclaration),
                       declarationLine.definition,
                       declarationLine.docblock,
                       declarationLine.inlineComment
                       ));
        }
Beispiel #28
0
        public void ParseData(AbstractSectorDataFile file)
        {
            foreach (SectorData line in file)
            {
                if (line.dataSegments.Count != 11)
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Incorrect number of Coordination Point segments", line)
                        );
                    return;
                }

                if (
                    line.dataSegments[0] != CoordinationPoint.PointTypeFir &&
                    line.dataSegments[0] != CoordinationPoint.PointTypeInternal
                    )
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Unknown Coordination point type " + line.dataSegments[0], line)
                        );
                    return;
                }

                if (
                    line.dataSegments[1].Length != 4 &&
                    line.dataSegments[2] != "*"
                    )
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Cannot specify a runway without a departure airport " + line.dataSegments[0], line)
                        );
                    return;
                }

                if (
                    line.dataSegments[4].Length != 4 &&
                    line.dataSegments[5] != "*"
                    )
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Cannot specify a runway without an arrival airport " + line.dataSegments[0], line)
                        );
                    return;
                }

                if (
                    line.dataSegments[8] != CoordinationPoint.DataNotSpecified &&
                    line.dataSegments[9] != CoordinationPoint.DataNotSpecified
                    )
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Cannot set both descend and climb level " + line.dataSegments[0], line)
                        );
                    return;
                }

                if (
                    line.dataSegments[8] != CoordinationPoint.DataNotSpecified &&
                    (!int.TryParse(line.dataSegments[8], out int climbLevel) ||
                     climbLevel < 0)
                    )
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid coordination point climb level " + line.dataSegments[0], line)
                        );
                    return;
                }

                if (
                    line.dataSegments[9] != CoordinationPoint.DataNotSpecified &&
                    (!int.TryParse(line.dataSegments[9], out int descendLevel) ||
                     descendLevel < 0)
                    )
                {
                    this.errorLog.AddEvent(
                        new SyntaxError("Invalid coordination point descend level " + line.dataSegments[0], line)
                        );
                    return;
                }

                this.sectorElements.Add(
                    new CoordinationPoint(
                        line.dataSegments[0] == CoordinationPoint.PointTypeFir,
                        line.dataSegments[1],
                        line.dataSegments[2],
                        line.dataSegments[3],
                        line.dataSegments[4],
                        line.dataSegments[5],
                        line.dataSegments[6],
                        line.dataSegments[7],
                        line.dataSegments[8],
                        line.dataSegments[9],
                        line.dataSegments[10],
                        line.definition,
                        line.docblock,
                        line.inlineComment
                        )
                    );
            }
        }