Example #1
0
        // Tests an invalid script
        private static void AssertIsInvalid(string script, int position, SyntaxError error)
        {
            SyntaxValidationResult result = Brainf_ckParser.ValidateSyntax(script);

            Assert.IsFalse(result.IsSuccess);
            Assert.AreEqual(result.ErrorOffset, position);
            Assert.AreEqual(result.ErrorType, error);
        }
Example #2
0
        // Tests a valid script
        private static void AssertIsValid(string script)
        {
            SyntaxValidationResult result = Brainf_ckParser.ValidateSyntax(script);

            Assert.IsTrue(result.IsSuccess);
            Assert.AreEqual(result.ErrorOffset, -1);
            Assert.AreEqual(result.ErrorType, SyntaxError.None);
        }
Example #3
0
            public static MemoryOwner <Brainf_ckOperator>?TryParse(ReadOnlySpan <char> source, out SyntaxValidationResult validationResult)
            {
                // Check the syntax of the input source code
                validationResult = ValidateSyntax(source);

                if (!validationResult.IsSuccess)
                {
                    return(null);
                }

                // Allocate the buffer of binary items with the input operators
                MemoryOwner <Brainf_ckOperator> operators = MemoryOwner <Brainf_ckOperator> .Allocate(validationResult.OperatorsCount);

                ref char sourceRef = ref source.DangerousGetReference();
Example #4
0
        public static string Convert(SyntaxValidationResult result)
        {
            string message = ResourceLoader.GetString($"{nameof(SyntaxError)}/{result.ErrorType}");

            return($"{message}, {Operator} {result.ErrorOffset}");
        }
Example #5
0
 /// <summary>
 /// Creates a new <see cref="TextChangedEventArgs"/> instance with the specified parameters
 /// </summary>
 /// <param name="plainText">The currently displayed plain text</param>
 /// <param name="validationResult">The <see cref="SyntaxValidationResult"/> instance for the currently displayed text</param>
 internal TextChangedEventArgs(string plainText, SyntaxValidationResult validationResult)
 {
     PlainText        = plainText;
     ValidationResult = validationResult;
 }
 /// <summary>
 /// Creates a new <see cref="ConsoleSyntaxError"/> instance with the specified parameters
 /// </summary>
 /// <param name="result">The <see cref="SyntaxValidationResult"/> instance for the executed command</param>
 public ConsoleSyntaxError(SyntaxValidationResult result) => Result = result;
Example #7
0
 /// <summary>
 /// Creates a new <see cref="Option{T}"/> instance for a script parsed successfully
 /// </summary>
 /// <param name="validationResult">The <see cref="SyntaxValidationResult"/> instance that indicates the parsing result for the input script</param>
 /// <param name="value">The <typeparamref name="T"/> result for the current execution</param>
 /// <returns>An <see cref="Option{T}"/> instance for a script parsed successfully</returns>
 internal static Option <T> From(SyntaxValidationResult validationResult, T value)
 {
     return(new Option <T>(validationResult, value));
 }
Example #8
0
 /// <summary>
 /// Creates a new <see cref="Option{T}"/> instance for an invalid script
 /// </summary>
 /// <param name="validationResult">The <see cref="SyntaxValidationResult"/> instance that indicates the parsing result for the input script</param>
 /// <returns>An <see cref="Option{T}"/> instance for a script not parsed successfully</returns>
 internal static Option <T> From(SyntaxValidationResult validationResult)
 {
     return(new Option <T>(validationResult, null));
 }
Example #9
0
 /// <summary>
 /// Creates a new <see cref="Option{T}"/> instance with the specified parameters
 /// </summary>
 /// <param name="validationResult">The <see cref="SyntaxValidationResult"/> instance that indicates the parsing result for the input script</param>
 /// <param name="value">The <typeparamref name="T"/> result for the current execution, if available</param>
 private Option(SyntaxValidationResult validationResult, T?value)
 {
     ValidationResult = validationResult;
     Value            = value;
 }
            public static MemoryOwner<Brainf_ckOperation>? TryParse(ReadOnlySpan<char> source, out SyntaxValidationResult validationResult)
            {
                // Check the syntax of the input source code
                validationResult = ValidateSyntax(source);

                if (!validationResult.IsSuccess) return null;

                // Allocate the buffer of binary items with the input operations
                using SpanOwner<Brainf_ckOperation> buffer = SpanOwner<Brainf_ckOperation>.Allocate(validationResult.OperatorsCount);
                ref Brainf_ckOperation bufferRef = ref buffer.DangerousGetReference();