public static bool IsDefinedCommand(this BFCommand command)
        {
            var definedTypes = ((BFCommandType[])Enum.GetValues(typeof(BFCommandType)))
                               .Where(x => !x.IsCommandTypeOf(BFCommandType.Undefined));

            return(definedTypes.Contains(command.CommandType));
        }
Exemple #2
0
        protected override IEnumerable <BFCommand> ParseByRow(string row)
        {
            BFCommand prevCommand = default;

            for (int currentPos = 0; currentPos < row.Length;)
            {
                if (this.TryGetNextCommand(row, currentPos, out var command) && !prevCommand.IsBeginComment())
                {
                    yield return(command);

                    prevCommand = command;
                    currentPos += command.Length;
                    continue;
                }
                else
                {
                    command = this.GetTrivia(row, currentPos, prevCommand.IsBeginComment());
                    yield return(command);

                    prevCommand = command;
                    currentPos += command.Length;
                    continue;
                }
            }
        }
Exemple #3
0
        private bool TryGetNextCommand(string row, int currentPos, out BFCommand command)
        {
            command = this._definedCommands
                      .FirstOrDefault(x => row.Substring(currentPos).StartsWith(x));

            if (command.IsDefinedCommand())
            {
                command = new BFCommand(command, this._currentRowPos, currentPos);

                return(true);
            }

            return(false);
        }
Exemple #4
0
        private static string BuildErrorMessage(BFCommand command, string message = "")
        {
            var builder = new StringBuilder();

            builder.Append($"BFRuntimeError at line:{command.RowPos + 1} index:{command.Pos + 1}.");

            if (message.HasMeaningfulValue())
            {
                builder.AppendLine($" {message}");
            }
            else
            {
                builder.AppendLine();
            }

            builder.AppendLine(command.ToString());

            return(builder.ToString());
        }
Exemple #5
0
 public BFRuntimeException(BFCommand command, string message, System.Exception innerException) : base(BuildErrorMessage(command, message), innerException)
 {
     this.Command = command;
 }
Exemple #6
0
 public BFRuntimeException(BFCommand command, string message) : base(BuildErrorMessage(command, message))
 {
     this.Command = command;
 }
 public static bool StartsWith(this string source, BFCommand command)
 {
     return(source.StartsWith(command.Command));
 }
 public static bool IsUndefined(this BFCommand command)
 {
     return(command.CommandType.IsCommandTypeOf(BFCommandType.Undefined));
 }
 public static bool IsExecutable(this BFCommand command)
 {
     return(!(command.IsUndefined() || command.IsTrivia() || command.IsBeginComment() || command.IsEndComment()));
 }
 public static bool IsWrite(this BFCommand command)
 {
     return(command.CommandType.IsCommandTypeOf(BFCommandType.Write));
 }
 public static bool IsEndComment(this BFCommand command)
 {
     return(command.CommandType.IsCommandTypeOf(BFCommandType.EndComment));
 }
 public static bool IsRead(this BFCommand command)
 {
     return(command.CommandType.IsCommandTypeOf(BFCommandType.Read));
 }
 public static bool IsLoopTail(this BFCommand command)
 {
     return(command.CommandType.IsCommandTypeOf(BFCommandType.LoopTail));
 }
 public static bool IsMoveLeft(this BFCommand command)
 {
     return(command.CommandType.IsCommandTypeOf(BFCommandType.MoveLeft));
 }
 public static bool IsDecrement(this BFCommand command)
 {
     return(command.CommandType.IsCommandTypeOf(BFCommandType.Decrement));
 }
 public static bool IsTrivia(this BFCommand command)
 {
     return(command.CommandType.IsCommandTypeOf(BFCommandType.Trivia));
 }