/// <summary>
        /// Gets the al element type's precedence.
        /// </summary>
        /// <param name="type">The lexical element type.</param>
        /// <returns>The type's precedence.</returns>
        /// <remarks>
        /// The given precedence are of arbitrary values.
        /// The important point is what types have the same precedences,
        /// and what types have lower or higher precedence than others.
        /// </remarks>
        public static int GetPrecedence(this LexicalElementType type)
        {
            switch (type)
            {
            case LexicalElementType.Term:
                return(0);

            case LexicalElementType.Or:
                return(2);

            case LexicalElementType.And:
            case LexicalElementType.Not:
                return(3);

            case LexicalElementType.OrderedNear:
                return(4);

            case LexicalElementType.Near:
                return(5);

            case LexicalElementType.LeftParenthesis:
            case LexicalElementType.RightParenthesis:
                return(13);

            default:
                throw new NotImplementedException("Unknown lexical element type.");
            }
        }
        /// <summary>
        /// Get the lexical element type's associativity.
        /// </summary>
        /// <param name="type">The lexical element type.</param>
        /// <returns>The type's associativity.</returns>
        public static OperatorAssociativity GetAssociativity(this LexicalElementType type)
        {
            switch (type)
            {
            case LexicalElementType.Term:
            case LexicalElementType.And:
            case LexicalElementType.Not:
            case LexicalElementType.Or:
            case LexicalElementType.Near:
            case LexicalElementType.OrderedNear:
            case LexicalElementType.LeftParenthesis:
            case LexicalElementType.RightParenthesis:
                return(OperatorAssociativity.Left);

            default:
                throw new NotImplementedException("Unknown lexical element type.");
            }
        }
        /// <summary>
        /// Indicates whether the lexical element type is an operator.
        /// </summary>
        /// <param name="type">The lexical element type.</param>
        /// <returns>true if the type is an operator; false otherwise.</returns>
        public static bool IsOperator(this LexicalElementType type)
        {
            switch (type)
            {
            case LexicalElementType.And:
            case LexicalElementType.Not:
            case LexicalElementType.Or:
            case LexicalElementType.Near:
            case LexicalElementType.OrderedNear:
                return(true);

            case LexicalElementType.Term:
            case LexicalElementType.LeftParenthesis:
            case LexicalElementType.RightParenthesis:
                return(false);

            default:
                throw new NotImplementedException("Unknown lexical element type.");
            }
        }
        /// <summary>
        /// Gets the operator's operand count.
        /// </summary>
        /// <param name="type">The lexical element type.</param>
        /// <returns>The operand count needed by the operator.</returns>
        public static int GetOperandCount(this LexicalElementType type)
        {
            switch (type)
            {
            case LexicalElementType.And:
            case LexicalElementType.Not:
            case LexicalElementType.Or:
            case LexicalElementType.Near:
            case LexicalElementType.OrderedNear:
                return(2);

            case LexicalElementType.Term:
            case LexicalElementType.LeftParenthesis:
            case LexicalElementType.RightParenthesis:
                throw new NotSupportedException($"The lexical element type {type} is not an operator type.");

            default:
                throw new NotImplementedException("Unknown lexical element type.");
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the SimpleLexicalElement class.
 /// </summary>
 /// <param name="document">The parent document.</param>
 /// <param name="lexicalElementType">The lexical element type.</param>
 /// <param name="location">The location of the lexical element within the code document.</param>
 /// <param name="generated">True if the lexical element is inside of a block of generated code.</param>
 internal SimpleLexicalElement(CsDocument document, LexicalElementType lexicalElementType, CodeLocation location, bool generated)
     : this(document, (int)lexicalElementType, location, generated)
 {
     Param.Ignore(document, lexicalElementType, location, generated);
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the SimpleLexicalElement class.
 /// </summary>
 /// <param name="document">The parent document.</param>
 /// <param name="lexicalElementType">The lexical element type.</param>
 internal SimpleLexicalElement(CsDocument document, LexicalElementType lexicalElementType)
     : this(document, (int)lexicalElementType)
 {
     Param.Ignore(document, lexicalElementType);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="LexicalElement"/> class.
 /// </summary>
 /// <param name="type">The lexical element type.</param>
 /// <param name="text">The lexical element text.</param>
 /// <param name="position">The lexical element start position.</param>
 public LexicalElement(LexicalElementType type, string text, int position)
 {
     Type     = type;
     Text     = text;
     Position = position;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the SimpleLexicalElement class.
 /// </summary>
 /// <param name="document">The parent document.</param>
 /// <param name="lexicalElementType">The lexical element type.</param>
 /// <param name="location">The location of the lexical element within the code document.</param>
 /// <param name="generated">True if the lexical element is inside of a block of generated code.</param>
 internal SimpleLexicalElement(CsDocument document, LexicalElementType lexicalElementType, CodeLocation location, bool generated)
     : this(document, (int)lexicalElementType, location, generated)
 {
     Param.Ignore(document, lexicalElementType, location, generated);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Initializes a new instance of the SimpleLexicalElement class.
 /// </summary>
 /// <param name="document">The parent document.</param>
 /// <param name="lexicalElementType">The lexical element type.</param>
 internal SimpleLexicalElement(CsDocument document, LexicalElementType lexicalElementType)
     : this(document, (int)lexicalElementType)
 {
     Param.Ignore(document, lexicalElementType);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Initializes a new instance of the LexicalElement class.
 /// </summary>
 /// <param name="proxy">The proxy for the element.</param>
 /// <param name="lexicalElementType">The lexical element type.</param>
 /// <param name="location">The location of the element.</param>
 internal LexicalElement(CodeUnitProxy proxy, LexicalElementType lexicalElementType, CodeLocation location)
     : this(proxy, (int)lexicalElementType, location)
 {
     Param.Ignore(proxy, lexicalElementType, location);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Initializes a new instance of the LexicalElement class.
 /// </summary>
 /// <param name="proxy">The proxy for the element.</param>
 /// <param name="lexicalElementType">The lexical element type.</param>
 /// <param name="location">The location of the element.</param>
 internal LexicalElement(CodeUnitProxy proxy, LexicalElementType lexicalElementType, CodeLocation location)
     : this(proxy, (int)lexicalElementType, location)
 {
     Param.Ignore(proxy, lexicalElementType, location);
 }