Ejemplo n.º 1
0
        public static string Close(this BracketsType type)
        {
            switch (type)
            {
            case BracketsType.Round:
                return(")");

            case BracketsType.Square:
                return("]");

            case BracketsType.Curly:
                return("}");

            case BracketsType.Angle:
                return(">");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
        public static string Open(this BracketsType type)
        {
            switch (type)
            {
            case BracketsType.Round:
                return("(");

            case BracketsType.Square:
                return("[");

            case BracketsType.Curly:
                return("{");

            case BracketsType.Angle:
                return("<");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 3
0
        public static bool ContainsIndependentBracketsPairs(List <Token> tokens, BracketsType type)
        {
            TokenType open  = TokenType.BracketOn;
            TokenType close = TokenType.BracketOff;

            switch (type)
            {
            case BracketsType.Curly:
                open  = TokenType.CurlyBracketOn;
                close = TokenType.CurlyBracketOff;
                break;

            case BracketsType.Square:
                open  = TokenType.SquareBracketOn;
                close = TokenType.SquareBracketOff;
                break;
            }

            int level = 0;

            for (int i = 0; i < tokens.Count; i++)
            {
                if (tokens[i].GetTokenType().Equals(open))
                {
                    level++;
                }
                if (tokens[i].GetTokenType().Equals(close))
                {
                    level--;
                }
                if (level == 0 && i != tokens.Count - 1 && i != 0)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
        private static bool AreCorrect(List <Token> tokens, BracketsType type)
        {
            TokenType open  = TokenType.BracketOn;
            TokenType close = TokenType.BracketOff;
            int       level = 0;

            switch (type)
            {
            case BracketsType.Curly:
                open  = TokenType.CurlyBracketOn;
                close = TokenType.CurlyBracketOff;
                break;

            case BracketsType.Square:
                open  = TokenType.SquareBracketOn;
                close = TokenType.SquareBracketOff;
                break;
            }

            foreach (Token token in tokens)
            {
                if (token.GetTokenType().Equals(open))
                {
                    level++;
                }
                if (token.GetTokenType().Equals(close))
                {
                    level--;
                }
                if (level < 0)
                {
                    return(false);
                }
            }
            return(level == 0 ? true : false);
        }
Ejemplo n.º 5
0
 public Brackets(BracketsType type)
 {
     Type = type;
     Priority = 1;
 }
 public BalancedBracketsRule(string name, string errorMessage, BracketsType bracketsType)
 {
     BracketsType = bracketsType;
     Name         = name;
     ErrorMessage = errorMessage;
 }