private static void checkSequenceValid(string inputString)
 {
     System.Collections.Generic.Stack<char> brackets = new System.Collections.Generic.Stack<char>();
     for (int i = 0; i < inputString.Length; i++)
     {
         if (inputString[i] == '(')
         {
             brackets.Push(inputString[i]);
         }
         else if (inputString[i] == ')')
         {
             if (brackets.Count <= 0)
             {
                 return;
             }
             brackets.Pop();
         }
     }
     if (brackets.Count == 0)
     {
         numberOfSequence++;
     }
 }
Exemplo n.º 2
0
        private void switchBaseMapLayer(TiledMapServiceLayer baseMapLayer, Envelope newExtent, List<Layer> oldBasemapLayers)
        {
            if (Map == null)
                return;

            // 1. Save the operational layers (We assume a single base layer)
            System.Collections.Generic.Stack<Layer> layers = new System.Collections.Generic.Stack<Layer>();
            for (int i = Map.Layers.Count - 1; i >= 0; i--)
            {
                Layer l = Map.Layers[i];
                if (oldBasemapLayers.Contains(l))
                    continue;

                Map.Layers.RemoveAt(i);
                layers.Push(l);
            }

            // 2. Clear the layers collection
            Map.Layers.Clear();

            // 3. Set the extent
            bool spatialReferenceUnchanged = Map.SpatialReference.Equals(newExtent.SpatialReference);
            Map.Extent = newExtent;

            // 4a. Set layer id if this is not set
            if (string.IsNullOrEmpty(baseMapLayer.ID) || (!string.IsNullOrEmpty(baseMapLayer.ID) && Map.Layers[baseMapLayer.ID] != null))
                baseMapLayer.ID = Guid.NewGuid().ToString("N");

            // 4. Add the new base map
            Map.Layers.Add(baseMapLayer);

            // 5. Re-add the operational layers         
            while (layers.Count > 0)
            {
                Layer layer = layers.Pop();
                if (!spatialReferenceUnchanged)
                {
                    //reproject graphics layers that are not feature layers 
                    // Feature layers support reprojection
                    if (layer is GraphicsLayer && !(layer is FeatureLayer))
                    {
                        GraphicsLayer graphicsLayer = layer as GraphicsLayer;
                        if (graphicsLayer.Graphics.Count > 0)
                        {
                            GeometryServiceOperationHelper helper = new GeometryServiceOperationHelper(
                                                                                                        new ConfigurationStoreHelper().GetGeometryServiceUrl(ConfigurationStore));
                            helper.ProjectGraphicsCompleted += (o, e) =>
                            {
                                GraphicsLayer targetLayer = e.UserState as GraphicsLayer;
                                if (targetLayer != null)
                                {
                                    targetLayer.Graphics.Clear();
                                    foreach (Graphic graphic in e.Graphics)
                                        targetLayer.Graphics.Add(graphic);
                                }
                            };
                            helper.ProjectGraphics(graphicsLayer.Graphics, newExtent.SpatialReference, graphicsLayer);
                        }

                        // update the map spatial reference on custom layers
                        ICustomGraphicsLayer customGraphicsLayer = layer as ICustomGraphicsLayer;
                        if (customGraphicsLayer != null)
                            customGraphicsLayer.MapSpatialReference = Map.SpatialReference;
                        else
                        {
                            HeatMapLayerBase heatMapLayer = layer as HeatMapLayerBase;
                            if (heatMapLayer != null)
                                heatMapLayer.MapSpatialReference = Map.SpatialReference;
                        }
                    }
                    else
                    {
                        HeatMapLayerBase heatMapLayer = layer as HeatMapLayerBase;
                        if (heatMapLayer != null && heatMapLayer.HeatMapPoints.Count > 0)
                        {
                            GeometryServiceOperationHelper helper = new GeometryServiceOperationHelper(new ConfigurationStoreHelper().GetGeometryServiceUrl(ConfigurationStore));
                            helper.ProjectPointsCompleted += (o, e) =>
                            {
                                PointCollection points = new PointCollection();

                                foreach (MapPoint item in e.Points)
                                {
                                    if (item != null)
                                        points.Add(item);
                                }

                                heatMapLayer.HeatMapPoints = points;
                                heatMapLayer.MapSpatialReference = points[0].SpatialReference;
                                heatMapLayer.Refresh();
                            };
                            helper.ProjectPoints(heatMapLayer.HeatMapPoints, newExtent.SpatialReference);
                        }
                    }
                }
                Map.Layers.Add(layer);
            }
        }
Exemplo n.º 3
0
        private int? DoSmartIndent(ITextSnapshotLine line) {
            if (line.LineNumber == 0) {
                return null;
            }
            int? indentation = GetLeadingWhiteSpace(line.GetText());
            var classifications = EnumerateClassificationsInReverse(
                _classifier,
                line.Snapshot.GetLineFromLineNumber(line.LineNumber - 1).End
            );

            if (classifications.MoveNext()) {
                var starting = classifications.Current;

                // first check to see if we're in an unterminated multiline token
                if (starting != null) {
                    if (starting.Tag.ClassificationType.Classification == "comment" &&
                        starting.Span.GetText().StartsWith("/*") &&
                        (!starting.Span.GetText().EndsWith("*/") || starting.Span.End.GetContainingLine() == line)) {
                        // smart indent in comment, dont indent
                        return null;
                    } else if (starting.Tag.ClassificationType.Classification == "string") {
                        var text = starting.Span.GetText();
                        if (!text.EndsWith("\"") && !text.EndsWith("'")) {
                            // smart indent in multiline string, no indent
                            return null;
                        }
                    }
                }

                // walk backwards and collect all of the possible tokens that could
                // be useful here...
                var tokenStack = new System.Collections.Generic.Stack<ITagSpan<ClassificationTag>>();
                tokenStack.Push(null);  // end with an implicit newline
                bool endAtNextNull = false;

                do {
                    var token = classifications.Current;
                    tokenStack.Push(token);
                    if (token == null && endAtNextNull) {
                        break;
                    } else if (token != null &&
                        token.Span.GetText() == "{") {
                        endAtNextNull = true;
                    }
                } while (classifications.MoveNext());

                var indentStack = new System.Collections.Generic.Stack<LineInfo>();
                var current = LineInfo.Empty;

                while (tokenStack.Count > 0) {
                    var token = tokenStack.Pop();
                    bool didDedent = false;
                    if (token == null) {
                        current.NeedsUpdate = true;
                    } else if (IsOpenGrouping(token)) {
                        if (current.WasIndentKeyword && token.Span.GetText() == "{") {
                            // the indentation statement is followed by braces, go ahead
                            // and remove the level of indentation now
                            current.WasIndentKeyword = false;
                            current.Indentation -= _editorOptions.GetTabSize();
                        }
                        indentStack.Push(current);
                        var start = token.Span.Start;
                        current = new LineInfo {
                            Indentation = GetLeadingWhiteSpace(start.GetContainingLine().GetText()) + _editorOptions.GetTabSize()
                        };
                    } else if (_indentKeywords.Contains(token.Span.GetText()) && !current.WasDoKeyword) {
                        // if (foo) 
                        //      console.log('hi')
                        // We should indent here
                        var start = token.Span.Start;
                        int dedentTo = GetLeadingWhiteSpace(start.GetContainingLine().GetText());
                        if (current.DedentTo != null && token.Span.GetText() != "if") {
                            // https://nodejstools.codeplex.com/workitem/1176
                            // if (true)
                            //     while (true)
                            //         ;
                            //
                            // We should dedent to the if (true)
                            // But for:
                            // if (true)
                            //     if (true)
                            //          ;
                            // We still want to dedent to our current level for the else
                            dedentTo = current.DedentTo.Value;
                        }
                        current = new LineInfo {
                            Indentation = GetLeadingWhiteSpace(start.GetContainingLine().GetText()) + _editorOptions.GetTabSize(),
                            DedentTo = dedentTo,
                            WasIndentKeyword = true,
                            WasDoKeyword = token.Span.GetText() == "do"
                        };
                    } else if (IsCloseGrouping(token)) {
                        if (indentStack.Count > 0) {
                            current = indentStack.Pop();
                        } else {
                            current = new LineInfo {
                                Indentation = GetLeadingWhiteSpace(token.Span.Start.GetContainingLine().GetText())
                            };
                        }
                    } else if (IsMultilineStringOrComment(token)) {
                        while (token != null && tokenStack.Count > 0) {
                            token = tokenStack.Pop();
                        }
                    } else if (current.WasIndentKeyword) {
                        // we've encountered a token after the opening of the indented
                        // statement, go ahead and decrement our indentation level now.
                        current = new LineInfo {
                            Indentation = current.DedentTo,
                            DedentTo = current.DedentTo - _editorOptions.GetTabSize(),
                            WasDoKeyword = current.WasDoKeyword
                        };
                        didDedent = true;
                    } else if (current.NeedsUpdate) {
                        var line2 = token.Span.Start.GetContainingLine();
                        current = new LineInfo {
                            Indentation = GetLeadingWhiteSpace(line2.GetText())
                        };
                    }

                    if (!didDedent && token != null && _dedentKeywords.Contains(token.Span.GetText())) {     // dedent after some statements
                        current.ShouldDedentAfter = true;
                    }
                }

                return current.Indentation -
                    (current.ShouldDedentAfter ? _editorOptions.GetTabSize() : 0);
            }

            return null;
        }
Exemplo n.º 4
0
        public override void Visit(ConditionalBranchNode node)
        {
            // AddCommand( new PushState() );

            node.ConditionalBranchCondition.Accept(this);

            RelativeJumpIfFalse falseConditionJump = new RelativeJumpIfFalse(0);
            AddCommand(falseConditionJump);
            jumpStack.Push(falseConditionJump);

            // IfCore
            node.ConditionalBranchCore.Accept(this);

            // This will jump to the end of the IfStatement
            RelativeJump toEndJump = new RelativeJump(0);
            AddCommand(toEndJump);

            // Pop all Break command from the jumpStack
            System.Collections.Generic.Stack<Jump> tempBreakStack = new System.Collections.Generic.Stack<Jump>();

            while (jumpStack.Count != 0 && jumpStack.Peek().GetType() == (new Break()).GetType() )
                tempBreakStack.Push(jumpStack.Pop());

            SetUpTopJumpInJumpStack(0);

            // Push all Break back to the jumpStack
            while (tempBreakStack.Count != 0) jumpStack.Push(tempBreakStack.Pop());

            // Push the falseConditionJump to set up PC later
            jumpStack.Push(toEndJump);
            conditionCount++;

            // AddCommand( new PopState() );
        }
Exemplo n.º 5
0
        /// <summary>
        /// ������ʽ��ֵ
        /// </summary>
        /// <param name="expression">�ı����ʽ</param>
        /// <returns>������</returns>
        public static double Calculate(string expression)
        {
            // Ԥ�����׺���ʽ
            List<IOperatorOrOperand> postfix = Expressions.ConvertInfixToPostfix(expression);
            // ������ջ
            System.Collections.Generic.Stack<double> data = new System.Collections.Generic.Stack<double>();

            // ����
            foreach (IOperatorOrOperand item in postfix)
            {
                if (item.IsOperator)
                {
                    // �����
                    OperatorBase opr = item as OperatorBase;

                    // �Ӳ�����ջ��ȡ��������
                    if (data.Count < opr.OperandCount)
                    {
                        throw new InvalidCastException("��Ч�ı��ʽ��ȱ�����������ֶ���IJ�������");
                    }
                    double[] operands = new double[opr.OperandCount];
                    for (int i = opr.OperandCount - 1; i >= 0; i--)
                    {
                        operands[i] = data.Pop();
                    }

                    // ���㲢�����ѹ��ջ��
                    data.Push(opr.Calculate(operands));
                }
                else
                {
                    // ������
                    // ѹ�������ջ
                    data.Push(((OperandInfo)item).Value);
                }
            }

            // ȡ�����
            if (data.Count != 1)
            {
                throw new InvalidCastException("��Ч�ı��ʽ��ȱ�����������ֶ���IJ�������");
            }
            return data.Pop();
        }
Exemplo n.º 6
0
        /// <summary>
        /// �����ʽת��Ϊ��׺���ʽ
        /// </summary>
        /// <param name="expression">�ı����ʽ</param>
        /// <returns>ת����ĺ�׺���ʽ</returns>
        internal static List<IOperatorOrOperand> ConvertInfixToPostfix(string expression)
        {
            // Ԥ������׺���ʽ
            List<IOperatorOrOperand> infix = SplitExpression(expression);
            // �����ջ
            System.Collections.Generic.Stack<OperatorBase> opr = new System.Collections.Generic.Stack<OperatorBase>();
            // ��׺���ʽ���
            List<IOperatorOrOperand> output = new List<IOperatorOrOperand>();

            // ����
            foreach (IOperatorOrOperand item in infix)
            {
                if (item.IsOperator)
                {
                    // �������
                    if (item.GetType() == typeof(OperatorCloseBracket))
                    {
                        // ������

                        // �����������ֱ������������Ϊֹ
                        while (opr.Peek().GetType() != typeof(OperatorOpenBracket))
                        {
                            output.Add(opr.Pop());
                            if (opr.Count == 0)
                            {
                                // ���Ų����
                                throw new InvalidCastException("�������Ų�ƥ�䡣");
                            }
                        }

                        // ����������
                        opr.Pop();
                    }
                    else
                    {
                        // ���������
                        OperatorBase thisopr = item as OperatorBase;

                        // �������ȼ��߻���ȵ������
                        int thisPriority = thisopr.Priority;
                        while (opr.Count > 0)
                        {
                            OperatorBase topopr = opr.Peek();
                            if(topopr.GetType() != typeof(OperatorOpenBracket))
                            {
                                // ���ջ���������Ϊ������
                                if (topopr.Priority > thisopr.Priority)
                                {
                                    // ���ջ���е���������ȼ����ڵ�ǰ������������������ջ
                                    output.Add(opr.Pop());
                                }
                                else if (topopr.Priority == thisopr.Priority)
                                {
                                    // ���ջ���е���������ȼ��뵱ǰ��������
                                    if (topopr.Direction == OperatingDirection.LeftToRight)
                                    {
                                        // ���ջ�����������Է���Ϊ�������ң������������ջ
                                        output.Add(opr.Pop());
                                    }
                                    else
                                    {
                                        // ����Ǵ���������ֹ��ջ
                                        break;
                                    }
                                }
                                else
                                {
                                    // ��ֹ��ջ
                                    break;
                                }
                            }
                            else
                            {
                                // ��ֹ��ջ
                                break;
                            }
                        }

                        // ����ǰ�����ѹ��ջ��
                        opr.Push(thisopr);
                    }
                }
                else
                {
                    // �Dz�����
                    // ֱ�����
                    output.Add(item);
                }
            }

            // �������������ջ��ȫ��ʣ��
            while (opr.Count > 0)
            {
                output.Add(opr.Pop());
            }

            return output;
        }
Exemplo n.º 7
0
        private SelectionCriterion _ParseCriterion(String s)
        {
            if (s == null) return null;

            // shorthand for filename glob
            if (s.IndexOf(" ") == -1)
                s = "name = " + s;

            // inject spaces after open paren and before close paren
            string[] prPairs = { @"\((\S)", "( $1", @"(\S)\)", "$1 )", };
            for (int i = 0; i + 1 < prPairs.Length; i += 2)
            {
                Regex rgx = new Regex(prPairs[i]);
                s = rgx.Replace(s, prPairs[i + 1]);
            }

            // split the expression into tokens
            string[] tokens = s.Trim().Split(' ', '\t');

            if (tokens.Length < 3) throw new ArgumentException(s);

            SelectionCriterion current = null;

            LogicalConjunction pendingConjunction = LogicalConjunction.NONE;

            ParseState state;
            var stateStack = new System.Collections.Generic.Stack<ParseState>();
            var critStack = new System.Collections.Generic.Stack<SelectionCriterion>();
            stateStack.Push(ParseState.Start);

            for (int i = 0; i < tokens.Length; i++)
            {
                switch (tokens[i].ToLower())
                {
                    case "and":
                    case "xor":
                    case "or":
                        state = stateStack.Peek();
                        if (state != ParseState.CriterionDone)
                            throw new ArgumentException(String.Join(" ", tokens, i, tokens.Length - i));

                        if (tokens.Length <= i + 3)
                            throw new ArgumentException(String.Join(" ", tokens, i, tokens.Length - i));

                        pendingConjunction = (LogicalConjunction)Enum.Parse(typeof(LogicalConjunction), tokens[i].ToUpper());
                        current = new CompoundCriterion { Left = current, Right = null, Conjunction = pendingConjunction };
                        stateStack.Push(state);
                        stateStack.Push(ParseState.ConjunctionPending);
                        critStack.Push(current);
                        break;

                    case "(":
                        state = stateStack.Peek();
                        if (state != ParseState.Start && state != ParseState.ConjunctionPending && state != ParseState.OpenParen)
                            throw new ArgumentException(String.Join(" ", tokens, i, tokens.Length - i));

                        if (tokens.Length <= i + 4)
                            throw new ArgumentException(String.Join(" ", tokens, i, tokens.Length - i));

                        stateStack.Push(ParseState.OpenParen);
                        break;

                    case ")":
                        state = stateStack.Pop();
                        if (stateStack.Peek() != ParseState.OpenParen)
                            throw new ArgumentException(String.Join(" ", tokens, i, tokens.Length - i));

                        stateStack.Pop();
                        stateStack.Push(ParseState.CriterionDone);
                        break;

                    case "atime":
                    case "ctime":
                    case "mtime":
                        if (tokens.Length <= i + 2)
                            throw new ArgumentException(String.Join(" ", tokens, i, tokens.Length - i));

                        DateTime t;
                        try
                        {
                            t = DateTime.ParseExact(tokens[i + 2], "yyyy-MM-dd-HH:mm:ss", null);
                        }
                        catch
                        {
                            t = DateTime.ParseExact(tokens[i + 2], "yyyy-MM-dd", null);
                        }
                        current = new TimeCriterion
                        {
                            Which = (WhichTime)Enum.Parse(typeof(WhichTime), tokens[i]),
                            Operator = (ComparisonOperator)EnumUtil.Parse(typeof(ComparisonOperator), tokens[i + 1]),
                            Time = t
                        };
                        i += 2;
                        stateStack.Push(ParseState.CriterionDone);
                        break;

                    case "length":
                    case "size":
                        if (tokens.Length <= i + 2)
                            throw new ArgumentException(String.Join(" ", tokens, i, tokens.Length - i));

                        Int64 sz = 0;
                        string v = tokens[i + 2];
                        if (v.ToUpper().EndsWith("K"))
                            sz = Int64.Parse(v.Substring(0, v.Length - 1)) * 1024;
                        else if (v.ToUpper().EndsWith("KB"))
                            sz = Int64.Parse(v.Substring(0, v.Length - 2)) * 1024;
                        else if (v.ToUpper().EndsWith("M"))
                            sz = Int64.Parse(v.Substring(0, v.Length - 1)) * 1024 * 1024;
                        else if (v.ToUpper().EndsWith("MB"))
                            sz = Int64.Parse(v.Substring(0, v.Length - 2)) * 1024 * 1024;
                        else if (v.ToUpper().EndsWith("G"))
                            sz = Int64.Parse(v.Substring(0, v.Length - 1)) * 1024 * 1024 * 1024;
                        else if (v.ToUpper().EndsWith("GB"))
                            sz = Int64.Parse(v.Substring(0, v.Length - 2)) * 1024 * 1024 * 1024;
                        else sz = Int64.Parse(tokens[i + 2]);

                        current = new SizeCriterion
                        {
                            Size = sz,
                            Operator = (ComparisonOperator)EnumUtil.Parse(typeof(ComparisonOperator), tokens[i + 1])
                        };
                        i += 2;
                        stateStack.Push(ParseState.CriterionDone);
                        break;

                    case "filename":
                    case "name":
                        {
                            if (tokens.Length <= i + 2)
                                throw new ArgumentException(String.Join(" ", tokens, i, tokens.Length - i));

                            ComparisonOperator c =
                                (ComparisonOperator)EnumUtil.Parse(typeof(ComparisonOperator), tokens[i + 1]);

                            if (c != ComparisonOperator.NotEqualTo && c != ComparisonOperator.EqualTo)
                                throw new ArgumentException(String.Join(" ", tokens, i, tokens.Length - i));

                            string m = tokens[i + 2];
                            // handle single-quoted filespecs (used to include spaces in filename patterns)
                            if (m.StartsWith("'"))
                            {
                                int ix = i;
                                if (!m.EndsWith("'"))
                                {
                                    do
                                    {
                                        i++;
                                        if (tokens.Length <= i + 2)
                                            throw new ArgumentException(String.Join(" ", tokens, ix, tokens.Length - ix));
                                        m += " " + tokens[i + 2];
                                    } while (!tokens[i + 2].EndsWith("'"));
                                }
                                // trim off leading and trailing single quotes
                                m = m.Substring(1, m.Length - 2);
                            }

                            current = new NameCriterion
                            {
                                MatchingFileSpec = m,
                                Operator = c
                            };
                            i += 2;
                            stateStack.Push(ParseState.CriterionDone);
                        }
                        break;

                    case "attributes":
                        {
                            if (tokens.Length <= i + 2)
                                throw new ArgumentException(String.Join(" ", tokens, i, tokens.Length - i));

                            ComparisonOperator c =
                                (ComparisonOperator)EnumUtil.Parse(typeof(ComparisonOperator), tokens[i + 1]);

                            if (c != ComparisonOperator.NotEqualTo && c != ComparisonOperator.EqualTo)
                                throw new ArgumentException(String.Join(" ", tokens, i, tokens.Length - i));

                            current = new AttributesCriterion
                            {
                                AttributeString = tokens[i + 2],
                                Operator = c
                            };
                            i += 2;
                            stateStack.Push(ParseState.CriterionDone);
                        }
                        break;

                    case "":
                        // NOP
                        stateStack.Push(ParseState.Whitespace);
                        break;

                    default:
                        throw new ArgumentException("'" + tokens[i] + "'");
                }

                state = stateStack.Peek();
                if (state == ParseState.CriterionDone)
                {
                    stateStack.Pop();
                    if (stateStack.Peek() == ParseState.ConjunctionPending)
                    {
                        while (stateStack.Peek() == ParseState.ConjunctionPending)
                        {
                            var cc = critStack.Pop() as CompoundCriterion;
                            cc.Right = current;
                            current = cc; // mark the parent as current (walk up the tree)
                            stateStack.Pop();   // the conjunction is no longer pending

                            state = stateStack.Pop();
                            if (state != ParseState.CriterionDone)
                                throw new ArgumentException();
                        }
                    }
                    else stateStack.Push(ParseState.CriterionDone);  // not sure?
                }

                if (state == ParseState.Whitespace)
                    stateStack.Pop();
            }

            return current;
        }
Exemplo n.º 8
0
        public void Format(string input, TextWriter output, HtmlFormatterOptions options)
        {
            bool makeXhtml = options.MakeXhtml;
            int maxLineLength = options.MaxLineLength;
            string indentString = new string(options.IndentChar, options.IndentSize);
            char[] chars = input.ToCharArray();
            System.Collections.Generic.Stack<FormatInfo> formatInfoStack = new System.Collections.Generic.Stack<FormatInfo>();
            System.Collections.Generic.Stack<HtmlWriter> writerStack = new System.Collections.Generic.Stack<HtmlWriter>();
            FormatInfo curTagFormatInfo = null;
            FormatInfo prevTokenFormatInfo = null;
            string s = string.Empty;
            bool flag2 = false;
            bool hasNoEndTag = false;
            bool flag4 = false;
            HtmlWriter writer = new HtmlWriter(output, indentString, maxLineLength);
            writerStack.Push(writer);
            Token curToken = HtmlTokenizer.GetFirstToken(chars);
            Token prevToken = curToken;
            while (curToken != null)
            {
                string text;
                string tagName;
                TagInfo tagInfo;
                writer = (HtmlWriter) writerStack.Peek();
                switch (curToken.Type)
                {
                    case Token.Whitespace:
                        if (curToken.Text.Length > 0)
                        {
                            writer.Write(' ');
                        }
                        goto Label_Get_Next_Token;

                    case Token.TagName:
                    case Token.Comment:
                    case Token.InlineServerScript:
                        hasNoEndTag = false;
                        if (curToken.Type != Token.Comment)
                        {
                            goto Label_Token_TagName_Or_InlineServerScript;
                        }

                        tagName = curToken.Text;
                        tagInfo = new TagInfo(curToken.Text, commentTag);
                        goto Label_Process_Comment;

                    case Token.AttrName:
                        if (!makeXhtml)
                        {
                            goto Label_0164;
                        }
                        text = string.Empty;
                        if (curTagFormatInfo.tagInfo.IsXml)
                        {
                            break;
                        }
                        text = curToken.Text.ToLower();
                        goto Label_0127;

                    case Token.AttrVal:
                        if ((!makeXhtml || (prevToken.Type == 13)) || (prevToken.Type == 14))
                        {
                            goto Label_0227;
                        }
                        writer.Write('"');
                        writer.Write(curToken.Text.Replace("\"", "&quot;"));
                        writer.Write('"');
                        goto Label_Get_Next_Token;

                    case Token.TextToken:
                    case Token.ClientScriptBlock:
                    case Token.Style:
                    case Token.ServerScriptBlock:
                        s = s + curToken.Text;
                        goto Label_Get_Next_Token;

                    case Token.SelfTerminating:
                        curTagFormatInfo.isEndTag = true;
                        if (!curTagFormatInfo.tagInfo.NoEndTag)
                        {
                            formatInfoStack.Pop();
                            if (curTagFormatInfo.tagInfo.IsXml)
                            {
                                HtmlWriter writer2 = (HtmlWriter) writerStack.Pop();
                                writer = (HtmlWriter) writerStack.Peek();
                                writer.Write(writer2.Content);
                            }
                        }
                        if ((prevToken.Type == Token.Whitespace) && (prevToken.Text.Length > 0))
                        {
                            writer.Write("/>");
                        }
                        else
                        {
                            writer.Write(" />");
                        }
                        goto Label_Get_Next_Token;

                    case Token.Error:
                        if (prevToken.Type == Token.OpenBracket)
                        {
                            writer.Write('<');
                        }
                        writer.Write(curToken.Text);
                        goto Label_Get_Next_Token;

                    case Token.CloseBracket:
                        if (!makeXhtml)
                        {
                            goto Label_027A;
                        }
                        if (!flag4)
                        {
                            goto Label_Process_CloseBracket; // proc CloseBracket
                        }
                        flag4 = false;
                        goto Label_Get_Next_Token;

                    case Token.DoubleQuote:
                        writer.Write('"');
                        goto Label_Get_Next_Token;

                    case Token.SingleQuote:
                        writer.Write('\'');
                        goto Label_Get_Next_Token;

                    case Token.EqualsChar:
                        writer.Write('=');
                        goto Label_Get_Next_Token;

                    case Token.XmlDirective:
                        writer.WriteLineIfNotOnNewLine();
                        writer.Write('<');
                        writer.Write(curToken.Text);
                        writer.Write('>');
                        writer.WriteLineIfNotOnNewLine();
                        curTagFormatInfo = new FormatInfo(directiveTag, false);
                        flag4 = true;
                        goto Label_Get_Next_Token;

                    default:
                        goto Label_Get_Next_Token;
                }

                text = curToken.Text;

            Label_0127:
                writer.Write(text);
                if (HtmlTokenizer.GetNextToken(curToken).Type != 15)
                {
                    writer.Write("=\"" + text + "\"");
                }
                goto Label_Get_Next_Token;

            Label_0164:
                if (!curTagFormatInfo.tagInfo.IsXml)
                {
                    if (options.AttributeCasing == HtmlFormatterCase.UpperCase)
                    {
                        writer.Write(curToken.Text.ToUpper());
                    }
                    else if (options.AttributeCasing == HtmlFormatterCase.LowerCase)
                    {
                        writer.Write(curToken.Text.ToLower());
                    }
                    else
                    {
                        writer.Write(curToken.Text);
                    }
                }
                else
                {
                    writer.Write(curToken.Text);
                }
                goto Label_Get_Next_Token;

            Label_0227:
                writer.Write(curToken.Text);
                goto Label_Get_Next_Token;

            Label_Process_CloseBracket: // write closebucket
                if (hasNoEndTag && !curTagFormatInfo.tagInfo.IsComment) // flag3 = NoEndTag
                {
                    writer.Write(" />");
                }
                else
                {
                    writer.Write('>');
                }
                goto Label_Get_Next_Token;

            Label_027A:
                writer.Write('>');
                goto Label_Get_Next_Token;

            Label_Token_TagName_Or_InlineServerScript:
                if (curToken.Type == Token.InlineServerScript)
                {
                    string newTagName = curToken.Text.Trim().Substring(1);
                    tagName = newTagName;
                    if (newTagName.StartsWith("%@"))
                    {
                        tagInfo = new TagInfo(newTagName, directiveTag);
                    }
                    else
                    {
                        tagInfo = new TagInfo(newTagName, otherServerSideScriptTag);
                    }
                }
                else
                {
                    tagName = curToken.Text;
                    tagInfo = tagTable[tagName] as TagInfo;
                    if (tagInfo == null)
                    {
                        if (tagName.IndexOf(':') > -1)
                        {
                            tagInfo = new TagInfo(tagName, unknownXmlTag);
                        }
                        else if (writer is XmlWriter)
                        {
                            tagInfo = new TagInfo(tagName, nestedXmlTag);
                        }
                        else
                        {
                            tagInfo = new TagInfo(tagName, unknownHtmlTag);
                        }
                    }
                    else if ((options.ElementCasing == HtmlFormatterCase.LowerCase) || makeXhtml)
                    {
                        tagName = tagInfo.TagName;
                    }
                    else if (options.ElementCasing == HtmlFormatterCase.UpperCase)
                    {
                        tagName = tagInfo.TagName.ToUpper();
                    }
                }

            Label_Process_Comment:
                if (curTagFormatInfo == null)
                {
                    curTagFormatInfo = new FormatInfo(tagInfo, false);
                    curTagFormatInfo.indent = 0;
                    formatInfoStack.Push(curTagFormatInfo);
                    writer.Write(s);
                    if (tagInfo.IsXml)
                    {
                        HtmlWriter writer3 = new XmlWriter(writer.Indent, tagInfo.TagName, indentString, maxLineLength);
                        writerStack.Push(writer3);
                        writer = writer3;
                    }
                    if (prevToken.Type == Token.ForwardSlash)
                    {
                        writer.Write("</");
                    }
                    else
                    {
                        writer.Write('<');
                    }
                    writer.Write(tagName);
                    s = string.Empty;
                }
                else
                {
                    WhiteSpaceType followingWhiteSpaceType;
                    prevTokenFormatInfo = new FormatInfo(tagInfo, prevToken.Type == Token.ForwardSlash);
                    followingWhiteSpaceType = curTagFormatInfo.isEndTag ? curTagFormatInfo.tagInfo.FollowingWhiteSpaceType : curTagFormatInfo.tagInfo.InnerWhiteSpaceType;
                    bool isInline = curTagFormatInfo.tagInfo.IsInline;
                    bool flag6 = false;
                    bool flag7 = false;
                    if (writer is XmlWriter)
                    {
                        XmlWriter writer4 = (XmlWriter) writer;
                        if (writer4.IsUnknownXml)
                        {
                            flag7 = ((curTagFormatInfo.isBeginTag && (curTagFormatInfo.tagInfo.TagName.ToLower() == writer4.TagName.ToLower())) || (prevTokenFormatInfo.isEndTag && (prevTokenFormatInfo.tagInfo.TagName.ToLower() == writer4.TagName.ToLower()))) && !FormattedTextWriter.IsWhiteSpace(s);
                        }
                        if (curTagFormatInfo.isBeginTag)
                        {
                            if (FormattedTextWriter.IsWhiteSpace(s))
                            {
                                if ((writer4.IsUnknownXml && prevTokenFormatInfo.isEndTag) && (curTagFormatInfo.tagInfo.TagName.ToLower() == prevTokenFormatInfo.tagInfo.TagName.ToLower()))
                                {
                                    isInline = true;
                                    flag6 = true;
                                    s = "";
                                }
                            }
                            else if (!writer4.IsUnknownXml)
                            {
                                writer4.ContainsText = true;
                            }
                        }
                    }
                    bool frontWhiteSpace = true;
                    if (curTagFormatInfo.isBeginTag && curTagFormatInfo.tagInfo.PreserveContent)
                    {
                        writer.Write(s);
                    }
                    else
                    {
                        switch (followingWhiteSpaceType)
                        {
                            case WhiteSpaceType.NotSignificant:
                                if (!isInline && !flag7)
                                {
                                    writer.WriteLineIfNotOnNewLine();
                                    frontWhiteSpace = false;
                                }
                                break;

                            case WhiteSpaceType.Significant:
                                if ((FormattedTextWriter.HasFrontWhiteSpace(s) && !isInline) && !flag7)
                                {
                                    writer.WriteLineIfNotOnNewLine();
                                    frontWhiteSpace = false;
                                }
                                break;

                            default:
                                if (((followingWhiteSpaceType == WhiteSpaceType.CarryThrough) && (flag2 || FormattedTextWriter.HasFrontWhiteSpace(s))) && (!isInline && !flag7))
                                {
                                    writer.WriteLineIfNotOnNewLine();
                                    frontWhiteSpace = false;
                                }
                                break;
                        }
                        if ((curTagFormatInfo.isBeginTag && !curTagFormatInfo.tagInfo.NoIndent) && !isInline)
                        {
                            writer.Indent++;
                        }
                        if (flag7)
                        {
                            writer.Write(s);
                        }
                        else
                        {
                            writer.WriteLiteral(s, frontWhiteSpace);
                        }
                    }
                    if (prevTokenFormatInfo.isEndTag)
                    {
                        if (!prevTokenFormatInfo.tagInfo.NoEndTag)
                        {
                            //ArrayList list = new ArrayList();
                            List<FormatInfo> formatInfoList = new List<FormatInfo>();
                            FormatInfo info4 = null;
                            bool flag9 = false;
                            bool flag10 = false;
                            if ((prevTokenFormatInfo.tagInfo.Flags & FormattingFlags.AllowPartialTags) != FormattingFlags.None)
                            {
                                flag10 = true;
                            }
                            if (formatInfoStack.Count > 0)
                            {
                                info4 = (FormatInfo) formatInfoStack.Pop();
                                formatInfoList.Add(info4);
                                while ((formatInfoStack.Count > 0) && (info4.tagInfo.TagName.ToLower() != prevTokenFormatInfo.tagInfo.TagName.ToLower()))
                                {
                                    if ((info4.tagInfo.Flags & FormattingFlags.AllowPartialTags) != FormattingFlags.None)
                                    {
                                        flag10 = true;
                                        break;
                                    }
                                    info4 = (FormatInfo) formatInfoStack.Pop();
                                    formatInfoList.Add(info4);
                                }
                                if (info4.tagInfo.TagName.ToLower() != prevTokenFormatInfo.tagInfo.TagName.ToLower())
                                {
                                    for (int i = formatInfoList.Count - 1; i >= 0; i--)
                                    {
                                        formatInfoStack.Push(formatInfoList[i]);
                                    }
                                }
                                else
                                {
                                    flag9 = true;
                                    for (int j = 0; j < (formatInfoList.Count - 1); j++)
                                    {
                                        FormatInfo info5 = (FormatInfo) formatInfoList[j];
                                        if (info5.tagInfo.IsXml && (writerStack.Count > 1))
                                        {
                                            HtmlWriter writer5 = (HtmlWriter) writerStack.Pop();
                                            writer = (HtmlWriter) writerStack.Peek();
                                            writer.Write(writer5.Content);
                                        }
                                        if (!info5.tagInfo.NoEndTag)
                                        {
                                            writer.WriteLineIfNotOnNewLine();
                                            writer.Indent = info5.indent;
                                            if (makeXhtml && !flag10)
                                            {
                                                writer.Write("</" + info5.tagInfo.TagName + ">");
                                            }
                                        }
                                    }
                                    writer.Indent = info4.indent;
                                }
                            }
                            if (flag9 || flag10)
                            {
                                if ((((!flag6 && !flag7) && (!prevTokenFormatInfo.tagInfo.IsInline && !prevTokenFormatInfo.tagInfo.PreserveContent)) && ((FormattedTextWriter.IsWhiteSpace(s) || FormattedTextWriter.HasBackWhiteSpace(s)) || (prevTokenFormatInfo.tagInfo.FollowingWhiteSpaceType == WhiteSpaceType.NotSignificant))) && (!(prevTokenFormatInfo.tagInfo is TDTagInfo) || FormattedTextWriter.HasBackWhiteSpace(s)))
                                {
                                    writer.WriteLineIfNotOnNewLine();
                                }
                                writer.Write("</");
                                writer.Write(tagName);
                            }
                            else
                            {
                                flag4 = true;
                            }
                            if (prevTokenFormatInfo.tagInfo.IsXml && (writerStack.Count > 1))
                            {
                                HtmlWriter writer6 = (HtmlWriter) writerStack.Pop();
                                writer = (HtmlWriter) writerStack.Peek();
                                writer.Write(writer6.Content);
                            }
                        }
                        else
                        {
                            flag4 = true;
                        }
                    }
                    // prevTokenFormatInfo.isEndTag == false
                    else
                    {
                        bool flag11 = false;
                        while (!flag11 && (formatInfoStack.Count > 0))
                        {
                            FormatInfo info6 = (FormatInfo) formatInfoStack.Peek();
                            if (!info6.tagInfo.CanContainTag(prevTokenFormatInfo.tagInfo))
                            {
                                formatInfoStack.Pop();
                                writer.Indent = info6.indent;
                                if (makeXhtml)
                                {
                                    if (!info6.tagInfo.IsInline)
                                    {
                                        writer.WriteLineIfNotOnNewLine();
                                    }
                                    writer.Write("</" + info6.tagInfo.TagName + ">");
                                }
                            }
                            flag11 = true;
                        }
                        prevTokenFormatInfo.indent = writer.Indent;
                        if (((!flag7 && !prevTokenFormatInfo.tagInfo.IsInline) && !prevTokenFormatInfo.tagInfo.PreserveContent) && ((FormattedTextWriter.IsWhiteSpace(s) || FormattedTextWriter.HasBackWhiteSpace(s)) || ((s.Length == 0) && ((curTagFormatInfo.isBeginTag && (curTagFormatInfo.tagInfo.InnerWhiteSpaceType == WhiteSpaceType.NotSignificant)) || (curTagFormatInfo.isEndTag && (curTagFormatInfo.tagInfo.FollowingWhiteSpaceType == WhiteSpaceType.NotSignificant))))))
                        {
                            writer.WriteLineIfNotOnNewLine();
                        }
                        if (!prevTokenFormatInfo.tagInfo.NoEndTag)
                        {
                            formatInfoStack.Push(prevTokenFormatInfo);
                        }
                        else
                        {
                            hasNoEndTag = true;
                        }
                        if (prevTokenFormatInfo.tagInfo.IsXml)
                        {
                            HtmlWriter writer7 = new XmlWriter(writer.Indent, prevTokenFormatInfo.tagInfo.TagName, indentString, maxLineLength);
                            writerStack.Push(writer7);
                            writer = writer7;
                        }
                        writer.Write('<');
                        writer.Write(tagName);
                    }
                    flag2 = FormattedTextWriter.HasBackWhiteSpace(s);
                    s = string.Empty;
                    curTagFormatInfo = prevTokenFormatInfo;
                }

            Label_Get_Next_Token:
                prevToken = curToken;
                curToken = HtmlTokenizer.GetNextToken(curToken);
            }
            if (s.Length > 0)
            {
                writer.Write(s);
            }
            while (writerStack.Count > 1)
            {
                HtmlWriter writer8 = (HtmlWriter) writerStack.Pop();
                writer = (HtmlWriter) writerStack.Peek();
                writer.Write(writer8.Content);
            }
            writer.Flush();
        }
Exemplo n.º 9
0
 public void PopContext() => context.Pop();
Exemplo n.º 10
0
            internal ListNode MergeTwoLists(ListNode l1, ListNode l2)
            {
                System.Collections.Generic.Stack <ListNode> nodestack = new System.Collections.Generic.Stack <ListNode>();

                while (l1 != null || l2 != null)
                {
                    int?firstValue  = null;
                    int?secondValue = null;

                    if (l1 != null)
                    {
                        firstValue = l1.val;
                        Console.WriteLine($"{firstValue}");
                    }

                    if (l2 != null)
                    {
                        secondValue = l2.val;
                        Console.WriteLine($"{secondValue}");
                    }

                    ListNode newnode = null;
                    if (firstValue.HasValue && secondValue.HasValue)
                    {
                        if (firstValue.Value > secondValue.Value)
                        {
                            newnode = new ListNode(secondValue.Value);

                            if (l2.next != null)
                            {
                                l2 = l2.next;
                            }
                            else
                            {
                                l2 = null;
                            }
                        }
                        else if (firstValue.Value < secondValue.Value)
                        {
                            newnode = new ListNode(firstValue.Value);

                            if (l1.next != null)
                            {
                                l1 = l1.next;
                            }
                            else
                            {
                                l1 = null;
                            }
                        }
                        else
                        {
                            newnode = new ListNode(firstValue.Value);

                            if (nodestack.Count == 0)
                            {
                                nodestack.Push(newnode);
                                Console.WriteLine($"Empty Stack: Node with value: {newnode.val} is added in the Stack");
                            }
                            else
                            {
                                nodestack.Peek().next = newnode;
                                nodestack.Push(newnode);
                                Console.WriteLine($"Node with value: {newnode.val} is added in the Stack");
                            }

                            newnode = new ListNode(secondValue.Value);

                            if (l1.next != null)
                            {
                                l1 = l1.next;
                            }
                            else
                            {
                                l1 = null;
                            }

                            if (l2.next != null)
                            {
                                l2 = l2.next;
                            }
                            else
                            {
                                l2 = null;
                            }
                        }
                    }
                    else if (firstValue.HasValue && !secondValue.HasValue)
                    {
                        newnode = new ListNode(firstValue.Value);
                        if (l1.next != null)
                        {
                            l1 = l1.next;
                        }
                        else
                        {
                            l1 = null;
                        }
                    }
                    else if (!firstValue.HasValue && secondValue.HasValue)
                    {
                        newnode = new ListNode(secondValue.Value);
                        if (l2.next != null)
                        {
                            l2 = l2.next;
                        }
                        else
                        {
                            l2 = null;
                        }
                    }

                    if (nodestack.Count == 0)
                    {
                        nodestack.Push(newnode);
                        Console.WriteLine($"Empty Stack: Node with value: {newnode.val} is added in the Stack");
                    }
                    else
                    {
                        nodestack.Peek().next = newnode;
                        nodestack.Push(newnode);
                        Console.WriteLine($"Node with value: {newnode.val} is added in the Stack");
                    }
                }
                Console.WriteLine($"Stack count: {nodestack.Count}");

                if (nodestack.Count > 0)
                {
                    while (nodestack.Count != 1)
                    {
                        nodestack.Pop();
                    }
                }

                if (nodestack.Count == 1)
                {
                    return(nodestack.Pop());
                }
                else
                {
                    return(null);
                }
            }
Exemplo n.º 11
0
 public void PopScenario() => scenario.Pop();
Exemplo n.º 12
0
 public void PopDescription() => description.Pop();
Exemplo n.º 13
0
        //parsing function
        static int parseString(string[,] parseTable, Grammar grammar, string str, string[,] parseInputTable)
        {
            //parseInputTable= new string[30,4];
            Stack <int>    stack       = new System.Collections.Generic.Stack <int>();
            Stack <string> symbol      = new System.Collections.Generic.Stack <string>();
            int            inp_pointer = 0;

            Console.WriteLine();
            stack.Push(0);
            Production[] x     = grammar.PrecedenceGroups[0].Productions;
            string[]     token = grammar.Tokens;
            Console.WriteLine("InputParsing");
            Console.WriteLine("Stack tt Symbol tt Input tt Action end");
            parseInputTable[0, 0] = "Stack";
            parseInputTable[0, 1] = "Symbol";
            parseInputTable[0, 2] = "Input";
            parseInputTable[0, 3] = "Action";
            int l = 0;

            while (true)
            {
                // Console.WriteLine(++l);
                //input parsing
                l++;
                if (stack.Count != 0)
                {
                    string temp;
                    temp = print(stack);
                    if (stack.Count > 2)
                    {
                        temp += stack.Peek();
                        Console.Write(stack.Peek());
                    }
                    parseInputTable[l, 0] = temp;
                }
                else
                {
                    Console.Write("");
                }
                Console.Write("tt");
                if (symbol.Count != 0)
                {
                    string temp;
                    temp = print(symbol);
                    if (symbol.Count > 2)
                    {
                        Console.Write(symbol.Peek());
                        temp += symbol.Peek();
                    }
                    parseInputTable[l, 1] = temp;
                }
                else
                {
                    Console.Write("");
                }
                Console.Write("tt");
                Console.Write(str.Substring(inp_pointer, str.Length - inp_pointer));
                parseInputTable[l, 2] = str.Substring(inp_pointer, str.Length - inp_pointer);

                string value = parseTable[stack.Peek() + 1, getIndex(token, str, inp_pointer)];
                if (stack.Peek() == 0 && symbol.Count != 0 && symbol.Peek() == "S" && str[inp_pointer] == '$')
                {
                    Console.WriteLine("\n Input parsed!!");
                    return(1);
                    //break;
                }

                else if (value.Contains("S"))
                {
                    int state = Int32.Parse(value[2].ToString());
                    stack.Push(state);

                    symbol.Push(str[inp_pointer].ToString());
                    inp_pointer++;
                    Console.WriteLine("tt Shift " + state + " end");
                    parseInputTable[l, 3] = "\tShift " + state;
                }
                else if (value.Contains("R"))
                {
                    int prod_no = Int32.Parse(value[2].ToString());
                    for (int i = 0; i < x[prod_no].Right.Length; i++)
                    {
                        symbol.Pop();
                        stack.Pop();
                    }
                    int token_inserted = x[prod_no].Left;
                    symbol.Push(token[token_inserted]);
                    //Console.WriteLine(stack.Peek() + "\t" + symbol.Peek() + "\t" + str.Substring(inp_pointer, str.Length - inp_pointer));

                    if (stack.Peek() == 0 && symbol.Count != 0 && symbol.Peek() == "S" && str[inp_pointer] == '$')
                    {
                        Console.WriteLine("\n Input parsed!!");
                        return(1);
                        // break;
                    }
                    string temp           = parseTable[stack.Peek() + 1, token_inserted + 2];
                    int    state_inserted = Int32.Parse(temp[2].ToString());
                    stack.Push(state_inserted);
                    Console.WriteLine("tt Reduce " + prod_no + " end");
                    parseInputTable[l, 3] = "\tReduce " + prod_no;
                }
                else
                {
                    Console.WriteLine("\nParse error!");
                    return(-1);
                    //break;
                }
            }
        }