﻿// <copyright file="NFANonDigitTransition.cs" company="None">
//    <para>
//    This program is free software: you can redistribute it and/or
//    modify it under the terms of the BSD license.</para>
//    <para>
//    This work is distributed in the hope that it will be useful, but
//    WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.</para>
//    <para>
//    See the LICENSE.txt file for more details.</para>
//    Original code as generated by Grammatica 1.6 Copyright (c) 
//    2003-2015 Per Cederberg. All rights reserved.
//    Updates Copyright (c) 2016 Jeremy Gibbons. All rights reserved
// </copyright>

namespace PerCederberg.Grammatica.Runtime.NFA
{
    /// <summary>
    /// The non-digit character set transition. This transition
    /// matches a single non-numeric character.
    /// </summary>
    internal class NFANonDigitTransition : NFATransition
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="NFANonDigitTransition"/> class
        /// </summary>
        /// <param name="state">The target state</param>
        public NFANonDigitTransition(NFAState state) : base(state)
        {
        }

        /// <summary>
        /// Gets a value indicating whether this transition only matches ASCII characters.
        /// I.e. characters with numeric values between 0 and 127.
        /// </summary>
        public override bool IsAscii
        {
            get
            {
                return false;
            }
        }

        /// <summary>
        /// Checks if the specified character matches the transition.
        /// </summary>
        /// <param name="ch">The character to check</param>
        /// <returns>True if the character matches, false if not</returns>
        public override bool Match(char ch)
        {
            return ch < '0' || ch > '9';
        }

        /// <summary>
        /// Creates a copy of this transition but with another target
        /// state.
        /// </summary>
        /// <param name="state">The new target state</param>
        /// <returns>An identical copy of this transition</returns>
        public override NFATransition Copy(NFAState state)
        {
            return new NFANonDigitTransition(state);
        }
    }
}
