Beispiel #1
0
        /// <summary>Test Parser Elements.
        /// First element is testet with the load function.</summary>
        /// <param name="code">String to parse.</param>
        /// <param name="markup">Expected markup from rule output.</param>
        /// <param name="elements">List of rules to test. The first rule is loaded.</param>
        public static void ParserLoadElement(List <ParserElementBase> elements, string code, string markup)
        {
            //var parser = new Parser();
            var outElements = new List <TextElement>();

            TextBuffer buffer = Util.NewBufferWs(code);

            for (int i = 0; i < elements.Count; i++)
            {
                elements[i] = elements[i].CloneForParse(buffer);
            }
            //foreach (var item in elements)
            //    item = item.CloneForParse(buffer);


            //parser.Rules = elements.Select(r => r.CloneForParse(buffer) as Rule).ToList();
            //ParserFactory.InitializeGrammar(parser, parser.Rules, buffer.Status);
            //ParserFactory.ValidateGrammar(parser, buffer.Status);

            ParserElementBase elem   = elements[0];
            string            syntax = elem.GetGrammar();

            Assert.AreEqual(true, elem.Load(outElements, 0), string.Format("rule '{0}': cant read", elem.Name));
            if (markup.Length > 0)
            {
                string actual = outElements.Aggregate("", (str, e) => str + e.ToMarkupProtected(string.Empty));
                Assert.AreEqual(markup, actual, "Equation TestOption: document fail");
            }
        }
Beispiel #2
0
        void LineComplete(ParserElementBase aElement)
        {
            ParserLine       line      = (ParserLine)aElement;
            TUserContextType tableType = (TUserContextType)line.Tag;
            UserContextTable table     = CrashDebugger.UserContextTableManager[tableType];

            // Each line should have a known number of entries stored within it's field collection.
            int expectedCount = UserContextTable.EntryCount * 2; // 2 fields per table entry
            int actualCount   = line.Count;

            if (expectedCount == actualCount)
            {
                for (int i = 0; i < expectedCount; i += 2)
                {
                    ParserField fieldType  = line[i + 0];
                    ParserField fieldValue = line[i + 1];
                    //
                    if (fieldType.IsUint && fieldValue.IsUint)
                    {
                        UserContextTable.TArmRegisterIndex reg = (UserContextTable.TArmRegisterIndex)(i / 2);
                        UserContextTableEntry entry            = table[reg];
                        //
                        UserContextTableEntry.TType type = (UserContextTableEntry.TType)fieldType.AsUint;
                        byte value = (byte)fieldValue.AsUint;
                        //
                        entry.Type   = type;
                        entry.Offset = value;
                    }
                }
            }
            else
            {
                throw new Exception("User Context Table Corruption");
            }
        }
Beispiel #3
0
 internal CodeElement(ParserElementBase element, TextSubString pointer)
 {
     if (element != null)
     {
         Name = element.Name;
     }
     SubString     = pointer;
     ParserElement = element;
 }
        void ThreadMState_ElementComplete(ParserElementBase aElement)
        {
            ParserLine      line      = (ParserLine)aElement;
            ParserParagraph paragraph = line.Paragraph;

            System.Diagnostics.Debug.Assert(paragraph.Tag is DThread);
            DThread thread = (DThread)paragraph.Tag;

            DThread.TThreadState state = (DThread.TThreadState)line.Tag;
            thread.MState = state;
        }
Beispiel #5
0
        void NThreadState_ElementComplete(ParserElementBase aElement)
        {
            ParserLine line = (ParserLine)aElement;

            System.Diagnostics.Debug.Assert(line.Tag is NThread.TNThreadState);
            NThread.TNThreadState state     = (NThread.TNThreadState)line.Tag;
            ParserParagraph       paragraph = line.Paragraph;

            System.Diagnostics.Debug.Assert(paragraph.Tag is NThread);
            NThread thread = (NThread)paragraph.Tag;

            thread.NState = state;
        }
        void NoUserStackCallBack(ParserElementBase aElement)
        {
            // Called back when a thread has no user stack - in which case, dump the
            // user-stack items as they will prevent us gathering the supervisor info.
            ParserLine      line = (ParserLine)aElement;
            ParserParagraph para = line.Paragraph;

            //
            foreach (ParserLine l in para)
            {
                l.IsDisabled = true;
            }
        }
Beispiel #7
0
        void Line_ElementComplete(ParserElementBase aElement)
        {
            int completeCount = 0;

            foreach (ParserLine line in iLines)
            {
                if (line.IsComplete && !line.IsNeverEnding)
                {
                    ++completeCount;
                }
            }
            //
            IsComplete = (completeCount == Count);
        }
        void CodeSegmentLineComplete(ParserElementBase aElement)
        {
            System.Diagnostics.Debug.Assert(iCurrentThread != null);
            ParserLine line = (ParserLine)aElement;
            //
            int    index          = line[0].AsInt;
            int    count          = line[1].AsInt;
            uint   codeSegAddress = line[2].AsUint;
            uint   startAddress   = line[3].AsUint;
            uint   endAddress     = line[4].AsUint;
            string fileName       = line[5].AsString;
            //
            DProcess process = iCurrentThread.OwningProcess;

            if (process != null)
            {
                ProcessCodeSegCollection codeSegs = process.CodeSegments;
                ProcessCodeSeg           codeSeg  = codeSegs[codeSegAddress];
                //
                if (codeSeg == null)
                {
                    // The code seg is not directly part of the process handle list
                    // but it is some how mapped into the process?
                    //
                    // Try looking up the underlying code seg entry details from
                    // the crash debugger data itself. It should be part of the code
                    // seg listing so this should always work.
                    codeSeg = new ProcessCodeSeg(CrashDebugger, codeSegAddress, 0);
                    process.CodeSegments.Add(codeSeg);
                }
                //
                codeSeg.ProcessLocalRunAddress = startAddress;
                codeSeg.Size = (endAddress - startAddress);
            }
            //
            int remaining = count - index;

            if (remaining == 0)
            {
                // Queue up stack data...
                iHelperStack.CreateStackParagraphs(ParserEngine, iCurrentThread);
            }
            else
            {
                // So that we capture the next line
                aElement.SetRepetitions(1);
            }
        }
        void DisableUserStackParagraph(ParserElementBase aElement)
        {
            // Called back when the first supervisor stack item fires. We
            // must disable all items in the user-paragraph so that they don't
            // intercept things like the current stack pointer.
            ParserLine      line   = (ParserLine)aElement;
            ParserParagraph para   = line.Paragraph;
            ParserEngine    engine = (ParserEngine)para.Parent;

            //
            foreach (ParserParagraph paragraph in engine)
            {
                if (paragraph.Name == KParagraphUser)
                {
                    paragraph.IsDisabled = true;
                    break;
                }
            }
        }
Beispiel #10
0
        internal static bool IsBinaryAlternative(Rule ExprRule, ParserElementBase alternative, out WordSymbol symbol, out Rule rule)
        {
            // is it a binary operator
            // find symbol for 'rule' binary operators
            ParserElementBase binaryOperation = null;

            if (alternative is RuleLink)
            {
                rule            = ((RuleLink)alternative).RuleElement;
                binaryOperation = rule;
            }
            else
            {
                rule = null;
            }

            // find symbol for inline binary operators
            if (alternative is SetOfElements)
            {
                binaryOperation = alternative;
            }

            // Is it a binary operation ?
            if (binaryOperation != null && binaryOperation.ChildNodes.Count == 3)
            {
                var expre1 = binaryOperation.ChildNodes[0] as RuleLink;
                symbol = binaryOperation.ChildNodes[1] as WordSymbol;
                var expre2 = binaryOperation.ChildNodes[2] as RuleLink;

                // add binary operator
                if (expre1 != null && expre1.RuleElement == ExprRule &&
                    symbol != null &&
                    expre2 != null && expre2.RuleElement == ExprRule)
                {
                    return(true);
                }
            }

            symbol = null;
            return(false);
        }
Beispiel #11
0
        private void AddAlternatives(Rule ExprRule, ParserElementBase alternative)
        {
            // is it more alternatives?
            var or = alternative as Or;

            if (or != null)
            {
                AddAlternatives(ExprRule, or.ChildNodes[0]);
                AddAlternatives(ExprRule, or.ChildNodes[1]);
                return;
            }

            // is it a binary operator? (depends opun how Or is implemented)
            WordSymbol symbol = null;
            Rule       rule   = null;

            if (IsBinaryAlternative(ExprRule, alternative, out symbol, out rule))
            {
                var wordOp = new WordBinaryOperator(symbol, rule != null ? rule.Name : symbol.Value, TextBuffer);
                _binaryOperators.Add(wordOp);
                if (rule != null)
                {
                    rule.ReplaceSubElement(symbol, wordOp);
                }
                else
                {
                    Add(wordOp);
                }
            }

            // Other forms
            else
            {
                _otherForms.Add(alternative);
            }
        }
        private bool SetPointerBackSet(int from, ParserElementBase failItem, List <TextElement> outElements, int level)
        {
            int ptrFail = TextBuffer.PointerNextChar;

            if (from < TextBuffer.Status.UnambiguousPointer && TextBuffer.Status.Error == null)
            {
                int failIndex = ChildNodes.IndexOf(failItem);

                CodeElement last = outElements.OfType <CodeElement>().LastOrDefault();
                if (last != null)
                {
                    for (int i = failIndex - 1; i > -1; i--)
                    {
                        TextBuffer.GetLoopLast(null);
                        if (ChildNodes[i].ResolveErrorsLast(last, 0) != 0)
                        {
                            break;
                        }
                    }
                }

                TextBuffer.PointerNextChar = ptrFail;

                for (int i = failIndex; i < ChildNodes.Count; i++)
                {
                    TextBuffer.GetLoopForward(null);
                    if (!ChildNodes[i].ResolveErrorsForward(0))
                    {
                        break;
                    }
                }
            }

            TextBuffer.PointerNextChar = from;
            return(false);
        }
Beispiel #13
0
 /// <summary>Creator for <see cref="Or"/>.</summary>
 internal Or(ParserElementBase element1, ParserElementBase element2)
 {
     Add(element1);
     Add(element2);
 }