示例#1
0
        private void NextItem(TokenProcessedEventArgs e)
        {
            // If we're on a name, and we're in a named ABSave, get the name and place it into "CurrentName".
            if (!OnValue && ABSaveType == ABSaveType.WithNames)
            {
                SetCurrentName(e.Trailing);
            }

            // Otherwise, if we were on a name, we're now on a value.
            else
            {
                // We want to remember what index the item is at (particually when named) to save performance.
                var index = (ABSaveType == ABSaveType.WithNames) ? CurrentObjects.Last().ObjectItems.FindIndex(CurrentName) : CurrentItem.Last();

                // Parse the value, and get the result - we'll only "manuallyParse" for errors because if it was a different type, it would have an "EXIT OBJECT" at the end - not a "NEXT ITEM".
                var result = ABSaveDeserializer.Deserialize(e.Trailing, CurrentObjects.Last().ObjectItems.Items[index].Info.FieldType, Settings, out ABSavePrimitiveType determinedType, out bool manuallyParse, CurrentLocation);

                //// If it determined it as an object, we'll take that and add it as a new object.
                //if (determinedType == ABSavePrimitiveType.Object)
                //{
                //    // If the result is null - that means it couldn't get a valid type, so there's a problem.
                //    if (result == null)

                //}

                // So, if needs to be manually parsed - and it isn't an object, there's a problem.
                if (manuallyParse && determinedType != ABSavePrimitiveType.Object)
                {
                    Settings.ErrorHandler.InvalidValueInABSaveWhenParsing(CurrentLocation, "The ABSave string '" + e.Leading + "' is not valid for the type '" + CurrentObjects.Last().Type.ToString() + "'.");
                }

                // Now, set the value, at the correct location.
                SetCurrentValue(index, result);
            }
        }
示例#2
0
        /// <summary>
        /// Figures out the header.
        /// </summary>
        /// <param name="e"></param>
        public void EstablishHeader(TokenProcessedEventArgs e)
        {
            // If the token ISN'T a "Next Item" token, the header is obviously incorrect.
            if (e.Token.Name != nameof(ABSaveTokens.NextItem))
            {
                Settings.ErrorHandler.InvalidHeaderWhenParsing("The header does not appear to follow the basic layout of the ABSave header, which is optionally followed by a number.");
                return;
            }

            // First of all, if there isn't a leading, there is no header!
            if (string.IsNullOrEmpty(e.Leading))
            {
                // Because there's no header, the ABSaveType won't be found out... So, if it's set to "infer" then obviously the type given is invalid and can't be worked out.
                if (ABSaveType == ABSaveType.Infer)
                {
                    Settings.ErrorHandler.InvalidHeaderWhenParsing("This parser was given the ABSaveType of 'infer'... However, there is no header so it can't infer anything.");
                }

                // Now, there's nothing more to do here.
                return;
            }

            // Lowercase the leading to make comparing easier.
            var leading = e.Leading.ToLower();

            // Get the ABSave info from the header.
            GetTypeFromHeader(leading);

            // Now, if there's more to the header - the rest should all be the version number.
            if (leading.Length > 1)
            {
                // Attempt to parse the version number.
                bool passed = int.TryParse(leading.Substring(2, leading.Length - 2), out int version);

                // If it failed, throw an error.
                if (!passed)
                {
                    Settings.ErrorHandler.InvalidHeaderWhenParsing("The version number following the type and show types identifiers is not valid - remember it should only be an integer.");
                    return;
                }

                // Otherwise, set the final version number.
                Version = version;
            }

            // If we made it here, we've established the header.
            EstablishedHeader = true;
        }
        protected override void OnTokenProcessed(TokenProcessedEventArgs e)
        {
            base.OnTokenProcessed(e);
            Result += e.Leading;
            switch (e.Token.Name)
            {
            case nameof(BashScriptBlockParserTokens.NewLine):
                Result += " ; ";
                break;

            case nameof(BashScriptBlockParserTokens.PROJPATH):
                Result += Path.GetDirectoryName(Backend.MainAppViewModel.ProjectPath).Replace('\\', '/');
                break;

            case nameof(BashScriptBlockParserTokens.PROJFILE):
                Result += Backend.MainAppViewModel.ProjectPath.Replace('\\', '/');
                break;

            case nameof(BashScriptBlockParserTokens.FINALOUT):
                Result += Project.FinalOutput.Replace('\\', '/');
                break;

            case nameof(BashScriptBlockParserTokens.LINKFILE):
                Result += Project.LinkFile.Replace('\\', '/');
                break;

            case nameof(BashScriptBlockParserTokens.PROJNAME):
                Result += Project.ProjectName;
                break;

            case nameof(BashScriptBlockParserTokens.FILETITLE):

                if (File != null)
                {
                    Result += File.FileTitle;
                }

                break;

            case nameof(BashScriptBlockParserTokens.FILEIN):

                if (File != null)
                {
                    Result += File.InputFilePath.Replace('\\', '/');
                }

                break;

            case nameof(BashScriptBlockParserTokens.FILEOUT):

                if (File != null)
                {
                    Result += File.OutputFilePath.Replace('\\', '/');
                }

                break;

            case nameof(BashScriptBlockParserTokens.ASMFILESIN):

                // Go through each assembly file and add their inputs.
                for (int i = 0; i < Project.Files.AssemblyFiles.Count; i++)
                {
                    Result += Project.Files.AssemblyFiles[i].InputFilePath.Replace('\\', '/') + " ";
                }

                break;

            case nameof(BashScriptBlockParserTokens.ASMFILESOUT):

                // Go through each assembly file and add their outputs.
                for (int i = 0; i < Project.Files.AssemblyFiles.Count; i++)
                {
                    Result += Project.Files.AssemblyFiles[i].OutputFilePath.Replace('\\', '/') + " ";
                }

                break;

            case nameof(BashScriptBlockParserTokens.CFILESIN):

                // Go through each c file and add their inputs.
                for (int i = 0; i < Project.Files.CFiles.Count; i++)
                {
                    Result += Project.Files.CFiles[i].InputFilePath.Replace('\\', '/') + " ";
                }

                break;

            case nameof(BashScriptBlockParserTokens.CFILESOUT):

                // Go through each c file and add their outputs.
                for (int i = 0; i < Project.Files.CFiles.Count; i++)
                {
                    Result += Project.Files.CFiles[i].OutputFilePath.Replace('\\', '/') + " ";
                }

                break;
            }
            if (e.NextToken == null)
            {
                Result += e.Trailing;
            }
        }
示例#4
0
        /// <summary>
        /// Runs when a token is processed.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnTokenProcessed(TokenProcessedEventArgs e)
        {
            // Run all the default code to allow ABParser to run.
            base.OnTokenProcessed(e);

            // If we haven't established the header, this is probably the "Next Item" token which follows it, so, figure out the header based on the leading (the rest of this method uses the trailing, so we can use this token twice).
            if (!EstablishedHeader)
            {
                EstablishHeader(e);
            }

            // Run the correct code based on what the token is.
            switch (e.Token.Name)
            {
            // NULL ITEM
            case nameof(ABSaveTokens.Null):

                //// If we're on the VALUE and there's a NULL character, this isn't valid.
                //if (!OnValue)
                //    ErrorHandler.UnexpectedTokenWhenParsing(CurrentLocation, "A NULL character was found on a name.");

                // Now, we're probably on the name, since if you think about it, the name would be followed by \u0002 if the value is null (e.g. Hello\u0002 would set "Hello" to null).
                // Meaning, the value is not valid.
                if (OnValue)
                {
                    Settings.ErrorHandler.UnexpectedTokenWhenParsing(CurrentLocation, "A NULL character was found after a \u0001 token, which is not valid ABSave.");
                }

                // So, since the value is already null in our outline (CurrentObjects) - we don't need to do ANYTHING except move forward one!
                CurrentItem[CurrentItem.Count - 1]++;
                break;

            // NEXT ITEM
            case nameof(ABSaveTokens.NextItem):

                // Go onto the next item.
                NextItem(e);
                break;

            // START OBJECT
            case nameof(ABSaveTokens.StartObject):

                // If we were on a name, and we came across this, there's a problem, because, it's technically AFTER the value (which is the type) that this token is found.
                // But, it's alright if we aren't showing types.
                if (!OnValue && ABSaveType == ABSaveType.WithNames && HasTypes)
                {
                    Settings.ErrorHandler.UnexpectedTokenWhenParsing(CurrentLocation, "The character for starting an object was found where a name should have been placed.");
                }

                // Also, if we haven't finished on deciding

                break;

            // EXIT OBJECT
            case nameof(ABSaveTokens.ExitObject):

                // This will finish up with the current object and actually turn it into an instance!
                FinishObject();

                // Also, go onto the next item - if we're in unnamed.
                CurrentItem[CurrentItem.Count - 1]++;

                break;
            }
        }