Example #1
0
        bool firstMatcherDominatesSecond(PatternMatcher a, PatternMatcher b)
        {
            //	Compare their class word first

            //	Compare the associated patterns.

            //	Extract the patterns from a, b.
            ProseObject[] pa = a.AssociatedPattern;
            ProseObject[] pb = b.AssociatedPattern;

            for (int i = 0; i < pa.Length; i++)
            {
                //	Most often they'll be the same and then
                if (pa[i] == pb[i])
                {
                    continue;
                }

                //	@prose is weaker than everything else
                if (pa[i] == @prose && pb[i] != @prose)
                {
                    return(false);
                }
                else if (pa[i] != @prose && pb[i] == @prose)
                {
                    continue;
                }

                else if (pa[i] == @raw && pb[i] is Word)
                {
                    return(false);
                }
                else if (pa[i] is Word && pb[i] == @raw)
                {
                    continue;
                }

                Word aword = (Word)pa[i];
                List <ProseObject> descendents = aword.getAllDescendents(this);
                //	If there even one piece of b's pattern doesn't descend from a's
                //	then a doesn't dominate.
                if (!descendents.Contains(pb[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
Example #2
0
        private List <ProseObject> getMatchingPatternWords(ProseObject obj)
        {
            List <ProseObject> matchingPatternWords = new List <ProseObject>(16);

            //
            //	Create a list of ProseObjects that, if they appeared in a pattern, would match with obj.
            //

            //	Objects match themselves
            matchingPatternWords.Add(obj);

            if (obj is ProseAction)
            {
                matchingPatternWords.Add(runtime.@prose);
                matchingPatternWords.Add(runtime.@action);
                //	Pure actions can appear in text.
                if (((ProseAction)obj).IsPure)
                {
                    matchingPatternWords.Add(runtime.@text);
                }
            }
            else if (obj is StringLiteralObject)
            {
                matchingPatternWords.Add(runtime.@prose);
                matchingPatternWords.Add(runtime.@string);
                matchingPatternWords.Add(runtime.@text);
            }
            else if (obj is RawWordObject)
            {
                matchingPatternWords.Add(runtime.@prose);
                matchingPatternWords.Add(runtime.@raw);
                //	Don't need to add @text because "" handles it.
            }
            else if (obj is Word)
            {
                //	If we see an opening "" we could start matching prose or text or string
                if (obj == runtime.Quadquote)
                {
                    matchingPatternWords.Add(runtime.@string);
                    matchingPatternWords.Add(runtime.@text);
                    matchingPatternWords.Add(runtime.@prose);
                }
                //	If we see an opening {, the ONLY options is that we're matching prose.
                else if (obj == runtime.LeftCurlyBracket)
                {
                    //if (obj != runtime.@prose)
                    matchingPatternWords.Add(runtime.@prose);
                }
                else
                {
                    //	Arbitrary words can be @prose or @pattern (neither of which require
                    //	any parenthetical notation).  @text is left out because "" always tells
                    //	you when you're entering a text block.

                    //	I DON"T UNDERATND WHAT THESE IF STATEMENTS WERE SUPPOSED TO DO
                    //if (obj != runtime.@prose)
                    matchingPatternWords.Add(runtime.@prose);
                    //if (obj != runtime.@pattern)
                    matchingPatternWords.Add(runtime.@pattern);

                    matchingPatternWords.Add(runtime.@raw);

                    //	If it's a word, then all descendent words are matches.
                    Word word = (Word)obj;
                    matchingPatternWords.AddRange(word.getAllDescendents(runtime));
                }
            }

            return(matchingPatternWords);
        }