#region COPYRIGHT
//
//     THIS IS GENERATED BY TEMPLATE
//     
//     AUTHOR  :     ROYE
//     DATE       :     2010
//
//     COPYRIGHT (C) 2010, TIANXIAHOTEL TECHNOLOGIES CO., LTD. ALL RIGHTS RESERVED.
//
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace System.Text.Template
{
    internal class TokenDefinition
    {
        private readonly TokenType _tokenType = TokenType.Term;
        private readonly OperatorAssociativity _associativity = OperatorAssociativity.Left;
        private readonly string _pattern;
        private readonly int _precedence;
        private readonly bool _isPartial;
        private TokenEvaluator _evaluator = null;
        private TokenDefinition _alternate = null;
        private TokenDefinition _root = null;

        public TokenDefinition(TokenType tokenType)
        {
            _tokenType = tokenType;
            _isPartial = (tokenType == TokenType.TernaryOperator1 || tokenType == TokenType.TernaryOperator2);
        }

        public TokenDefinition(TokenType tokenType, string pattern)
            : this(tokenType)
        {
            _pattern = pattern;
        }

        public TokenDefinition(TokenType tokenType, int precedence, string pattern)
            : this(tokenType)
        {
            _precedence = precedence;
            _pattern = pattern;
        }

        public TokenDefinition(TokenType tokenType, int precedence, OperatorAssociativity associativity, string pattern)
            : this(tokenType)
        {
            _precedence = precedence;
            _pattern = pattern;
            _associativity = associativity;
        }

        public TokenDefinition(TokenType tokenType, TokenEvaluator evaluator)
            : this(tokenType, (string)null)
        {
            _evaluator = evaluator;
        }

        public TokenDefinition(TokenType tokenType, int precedence, TokenEvaluator evaluator)
            : this(tokenType, precedence, (string)null)
        {
            _evaluator = evaluator;
        }

        /// <summary>
        /// 获取标记类型
        /// </summary>
        public TokenType Type
        {
            get { return _tokenType; }
        }

        /// <summary>
        /// 获取标记的模式
        /// </summary>
        public string Pattern
        {
            get { return _pattern; }
        }

        /// <summary>
        /// 获取标记的优先级
        /// </summary>
        public int Precedence
        {
            get { return _precedence; }
        }

        public OperatorAssociativity Associativity
        {
            get { return _associativity; }
        }

        public TokenEvaluator Evaluator
        {
            get { return _evaluator; }
            set { _evaluator = value; }
        }

        public bool IsPartial
        {
            get { return _isPartial; }
        }

        public TokenDefinition Alternate
        {
            get { return _alternate; }
            set { _alternate = value; }
        }

        public TokenDefinition Root
        {
            get { return _root; }
            set { _root = value; }
        }
    }
}
