Ejemplo n.º 1
0
        public bool LastFinished(Token token, bool knowLast = false)
        {
            if (this.Count() == 0)
            {
                return(true);
            }
            var last = this.Last;

            if (FieldSegment.GetType(last.Keyname) != Field.Type.NONE)
            {
                return(true);
            }
            if (last.Data == "")
            {
                return(false);
            }
            if (knowLast)
            {
                if (token.CannotCloseWith())
                {
                    return(false);
                }
            }
            var lastsym = last.Data[last.Data.Length - 1];

            if (BracketProcessor.IsValidEnd(lastsym) && BracketProcessor.BracketCheck(last.Data) != BracketProcessor.ERRORTYPE.UNCLOSED)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 2
0
 public void Freeze()
 {
     if (BracketProcessor.BracketCheck(Data) != BracketProcessor.ERRORTYPE.OK)
     {
         throw new ParsingException("Invalid brackets in `" + Data + "`");
     }
     frozen = true;
     if (string.IsNullOrEmpty(Data))
     {
         this.type = PostTokenType.VOID;
     }
     else if (Data.Contains("="))
     {
         this.type = PostTokenType.EQUALITY;
     }
     else
     {
         this.type = PostTokenType.EXPRESSION;
     }
 }
        public static ERRORTYPE BracketCheck(string s)
        {
            string stack = "()";

            foreach (var c in s)
            {
                if (BracketProcessor.IsBracket(c))
                {
                    stack += c.ToString();
                    char c1 = stack[stack.Length - 2];
                    char c2 = stack[stack.Length - 1];
                    if (IsOpen(c1) && IsClose(c2) && Type(c1) != Type(c2))
                    {
                        return(ERRORTYPE.CLOSED_TOO_EARLY);
                    }
                    if (IsOpen(c1) && IsClose(c2) && Type(c1) == Type(c2))
                    {
                        stack = stack.Substring(0, stack.Length - 2);
                    }
                }
            }
            return(stack.Length == 2 ? ERRORTYPE.OK : ERRORTYPE.UNCLOSED);
        }