public RapidXamlParsingEventArgs(RapidXamlDocument document, string file, ITextSnapshot snapshot, ParsedAction action)
 {
     this.Document = document;
     this.File     = file;
     this.Snapshot = snapshot;
     this.Action   = action;
 }
示例#2
0
        public string FillInTemplate(ParsedAction action, Character speaker, string templateString, Character spokenTo)
        {
            var fillInBlankMatches = Regex.Matches(templateString, "[{][^}]+[}]")
                                     .Cast <Match>()
                                     .Select(m => m.Value)
                                     .ToArray();

            foreach (var match in fillInBlankMatches)
            {
                Func <Character, string> speakerReplacementFunc = null;;
                templatesForSpeaker.TryGetValue(match, out speakerReplacementFunc);

                Func <Character, string> replierReplacementFunc = null;
                templatesForSpokenTo.TryGetValue(match, out replierReplacementFunc);

                Func <ParsedAction, string> actionReplacementFunc = null;
                _templatesForActions.TryGetValue(match, out actionReplacementFunc);


                if (speakerReplacementFunc != null)
                {
                    templateString = templateString.Replace(match, speakerReplacementFunc(speaker));
                }
                else if (replierReplacementFunc != null)
                {
                    templateString = templateString.Replace(match, replierReplacementFunc(spokenTo));
                }
                else if (actionReplacementFunc != null)
                {
                    templateString = templateString.Replace(match, actionReplacementFunc(action));
                }
            }

            var grammarMatches = Regex.Matches(templateString, "a\\(n\\)")
                                 .Cast <Match>()
                                 .Select(m => m.Value)
                                 .ToArray();


            foreach (var match in grammarMatches)
            {
                Func <TemplateInText, string> grammarReplacementFunc = null;
                _templatesForGrammarRules.TryGetValue(match, out grammarReplacementFunc);

                if (grammarReplacementFunc != null)
                {
                    var grammarTemplateText = new TemplateInText
                    {
                        TemplateIndex = templateString.IndexOf(match, StringComparison.Ordinal),
                        Text          = templateString
                    };
                    var regex = new Regex(Regex.Escape(match));
                    templateString = regex.Replace(templateString, grammarReplacementFunc(grammarTemplateText), 1);
                }
            }

            // Capitalize filled in words for filled interactions.
            // We can probably move a(an) to just either a/an and find those specific words and double check them.
            // verb modifiers for plural - first person - second person/singular like take/takes, have/has, do/does etc I hope there is a library for this or at least a list of these verbs

            return(templateString);
        }