示例#1
0
 static num MapNum(StringTreeNode node)
 {
     return(new num()
     {
         @string = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).FirstOrDefault(),
     });
 }
示例#2
0
 static identifier MapIdentifier(StringTreeNode node)
 {
     return(new identifier()
     {
         @string = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).FirstOrDefault(),
     });
 }
示例#3
0
 static exprsSeq MapExprsSeq(StringTreeNode node)
 {
     return(new exprsSeq()
     {
         exprItems = node.Childs.Where(n => n.Rule.Name == "exprItem").Select(n => MapExprItem(n)).ToArray(),
     });
 }
示例#4
0
 static omitPattern MapOmitPattern(StringTreeNode node)
 {
     return(new omitPattern()
     {
         @string = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).FirstOrDefault(),
     });
 }
示例#5
0
 static condition MapCondition(StringTreeNode node)
 {
     return(new condition()
     {
         _rawTreeNode = node,
         exprSeq = node.Childs.Where(n => n.Rule.Name == "exprSeq").Select(n => MapExprSeq(n)).FirstOrDefault(),
     });
 }
示例#6
0
 static errTransition MapErrTransition(StringTreeNode node)
 {
     return(new errTransition()
     {
         _rawTreeNode = node,
         @string = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).FirstOrDefault(),
     });
 }
示例#7
0
 static stateName MapStateName(StringTreeNode node)
 {
     return(new stateName()
     {
         _rawTreeNode = node,
         identifier = node.Childs.Where(n => n.Rule.Name == "identifier").Select(n => MapIdentifier(n)).FirstOrDefault(),
     });
 }
示例#8
0
 static boolOperator MapBoolOperator(StringTreeNode node)
 {
     return(new boolOperator()
     {
         _rawTreeNode = node,
         @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(),
     });
 }
示例#9
0
 static group MapGroup(StringTreeNode node)
 {
     return(new group()
     {
         @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(),
         exprsSeq = node.Childs.Where(n => n.Rule.Name == "exprsSeq").Select(n => MapExprsSeq(n)).FirstOrDefault(),
     });
 }
示例#10
0
 static quantor MapQuantor(StringTreeNode node)
 {
     return(new quantor()
     {
         @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(),
         quantorSpec = node.Childs.Where(n => n.Rule.Name == "quantorSpec").Select(n => MapQuantorSpec(n)).FirstOrDefault(),
     });
 }
示例#11
0
 static altItem MapAltItem(StringTreeNode node)
 {
     return(new altItem()
     {
         number = node.Childs.Where(n => n.Rule.Name == "number").Select(n => MapNumber(n)).FirstOrDefault(),
         trivial = node.Childs.Where(n => n.Rule.Name == "trivial").Select(n => MapTrivial(n)).FirstOrDefault(),
     });
 }
示例#12
0
 static quantorSpec MapQuantorSpec(StringTreeNode node)
 {
     return(new quantorSpec()
     {
         nums = node.Childs.Where(n => n.Rule.Name == "num").Select(n => MapNum(n)).ToArray(),
         @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(),
     });
 }
示例#13
0
 static not MapNot(StringTreeNode node)
 {
     return(new not()
     {
         @string = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).FirstOrDefault(),
         trivial = node.Childs.Where(n => n.Rule.Name == "trivial").Select(n => MapTrivial(n)).FirstOrDefault(),
     });
 }
示例#14
0
 static nsName MapNsName(StringTreeNode node)
 {
     return(new nsName()
     {
         identifiers = node.Childs.Where(n => n.Rule.Name == "identifier").Select(n => MapIdentifier(n)).ToArray(),
         @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(),
     });
 }
示例#15
0
 public static grammar MapGrammar(StringTreeNode node)
 {
     return(new grammar()
     {
         header = node.Childs.Where(n => n.Rule.Name == "header").Select(n => MapHeader(n)).FirstOrDefault(),
         rules = node.Childs.Where(n => n.Rule.Name == "rule").Select(n => MapRule(n)).ToArray(),
     });
 }
示例#16
0
 static sep MapSep(StringTreeNode node)
 {
     return(new sep()
     {
         _rawTreeNode = node,
         @string = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).FirstOrDefault(),
     });
 }
示例#17
0
 static keyword MapKeyword(StringTreeNode node)
 {
     return(new keyword()
     {
         _rawTreeNode = node,
         @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(),
     });
 }
示例#18
0
 static alternatives MapAlternatives(StringTreeNode node)
 {
     return(new alternatives()
     {
         altItems = node.Childs.Where(n => n.Rule.Name == "altItem").Select(n => MapAltItem(n)).ToArray(),
         @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(),
     });
 }
示例#19
0
 static number MapNumber(StringTreeNode node)
 {
     return(new number()
     {
         trivial = node.Childs.Where(n => n.Rule.Name == "trivial").Select(n => MapTrivial(n)).FirstOrDefault(),
         quantor = node.Childs.Where(n => n.Rule.Name == "quantor").Select(n => MapQuantor(n)).FirstOrDefault(),
     });
 }
示例#20
0
 static exprSeq MapExprSeq(StringTreeNode node)
 {
     return(new exprSeq()
     {
         _rawTreeNode = node,
         exprItems = node.Childs.Where(n => n.Rule.Name == "exprItem").Select(n => MapExprItem(n)).ToArray(),
         boolOperators = node.Childs.Where(n => n.Rule.Name == "boolOperator").Select(n => MapBoolOperator(n)).ToArray(),
     });
 }
示例#21
0
 static rule MapRule(StringTreeNode node)
 {
     return(new rule()
     {
         identifier = node.Childs.Where(n => n.Rule.Name == "identifier").Select(n => MapIdentifier(n)).FirstOrDefault(),
         @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(),
         exprsSeq = node.Childs.Where(n => n.Rule.Name == "exprsSeq").Select(n => MapExprsSeq(n)).FirstOrDefault(),
     });
 }
示例#22
0
 static exprItem MapExprItem(StringTreeNode node)
 {
     return(new exprItem()
     {
         alternatives = node.Childs.Where(n => n.Rule.Name == "alternatives").Select(n => MapAlternatives(n)).FirstOrDefault(),
         number = node.Childs.Where(n => n.Rule.Name == "number").Select(n => MapNumber(n)).FirstOrDefault(),
         trivial = node.Childs.Where(n => n.Rule.Name == "trivial").Select(n => MapTrivial(n)).FirstOrDefault(),
     });
 }
示例#23
0
 static header MapHeader(StringTreeNode node)
 {
     return(new header()
     {
         @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(),
         nsName = node.Childs.Where(n => n.Rule.Name == "nsName").Select(n => MapNsName(n)).FirstOrDefault(),
         identifiers = node.Childs.Where(n => n.Rule.Name == "identifier").Select(n => MapIdentifier(n)).ToArray(),
     });
 }
示例#24
0
 public static automaton MapAutomaton(StringTreeNode node)
 {
     return(new automaton()
     {
         _rawTreeNode = node,
         @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(),
         states = node.Childs.Where(n => n.Rule.Name == "state").Select(n => MapState(n)).ToArray(),
     });
 }
示例#25
0
 static transition MapTransition(StringTreeNode node)
 {
     return(new transition()
     {
         _rawTreeNode = node,
         @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(),
         condition = node.Childs.Where(n => n.Rule.Name == "condition").Select(n => MapCondition(n)).FirstOrDefault(),
         stateName = node.Childs.Where(n => n.Rule.Name == "stateName").Select(n => MapStateName(n)).FirstOrDefault(),
     });
 }
示例#26
0
 static exprItem MapExprItem(StringTreeNode node)
 {
     return(new exprItem()
     {
         _rawTreeNode = node,
         not = node.Childs.Where(n => n.Rule.Name == "not").Select(n => MapNot(n)).FirstOrDefault(),
         literal = node.Childs.Where(n => n.Rule.Name == "literal").Select(n => MapLiteral(n)).FirstOrDefault(),
         identifier = node.Childs.Where(n => n.Rule.Name == "identifier").Select(n => MapIdentifier(n)).FirstOrDefault(),
         exprGroup = node.Childs.Where(n => n.Rule.Name == "exprGroup").Select(n => MapExprGroup(n)).FirstOrDefault(),
     });
 }
示例#27
0
 static trivial MapTrivial(StringTreeNode node)
 {
     return(new trivial()
     {
         identifier = node.Childs.Where(n => n.Rule.Name == "identifier").Select(n => MapIdentifier(n)).FirstOrDefault(),
         regex = node.Childs.Where(n => n.Rule.Name == "regex").Select(n => MapRegex(n)).FirstOrDefault(),
         chars = node.Childs.Where(n => n.Rule.Name == "chars").Select(n => MapChars(n)).FirstOrDefault(),
         check = node.Childs.Where(n => n.Rule.Name == "check").Select(n => MapCheck(n)).FirstOrDefault(),
         not = node.Childs.Where(n => n.Rule.Name == "not").Select(n => MapNot(n)).FirstOrDefault(),
         group = node.Childs.Where(n => n.Rule.Name == "group").Select(n => MapGroup(n)).FirstOrDefault(),
     });
 }
示例#28
0
 static state MapState(StringTreeNode node)
 {
     return(new state()
     {
         _rawTreeNode = node,
         stateName = node.Childs.Where(n => n.Rule.Name == "stateName").Select(n => MapStateName(n)).FirstOrDefault(),
         @strings = node.Childs.Where(n => n.Childs.Count == 0).Select(n => n.Fragment.Content).ToArray(),
         transitions = node.Childs.Where(n => n.Rule.Name == "transition").Select(n => MapTransition(n)).ToArray(),
         skip = node.Childs.Where(n => n.Rule.Name == "skip").Select(n => MapSkip(n)).FirstOrDefault(),
         errTransition = node.Childs.Where(n => n.Rule.Name == "errTransition").Select(n => MapErrTransition(n)).FirstOrDefault(),
     });
 }
示例#29
0
        public string Play(string text)
        {
            StringTreeNode node = _wordsDictionary.Find(text);

            List <StringTreeNode> winningOptions = GetWinningOptions(node);

            if (winningOptions.Any())
            {
                return(GetRandomOption(text, winningOptions));
            }

            return(GameExtendingLongestOption(text, node));
        }
示例#30
0
        private List <StringTreeNode> GetWinningOptions(StringTreeNode node)
        {
            List <StringTreeNode> winningOptions = new List <StringTreeNode>();

            foreach (var childNode in node.GetChildren())
            {
                if (childNode.LeadsToASingleWord() && childNode.GetDeepOfChildren() % 2 != 0 && !childNode.IsWord)
                {
                    winningOptions.Add(childNode);
                }
            }

            return(winningOptions);
        }