public SlotModel(ParserRule rule, string baseRule, string baseNamespace, GrammarInfo grammarInfo) : base(rule: rule, baseNamespace: baseNamespace) { if (rule.Alternatives.Count != 1) { throw new ArgumentException(); } BaseRuleName = baseRule?.ToPascalcase(); SyntaxKind = $"{rule.Name.ToPascalcase()}Syntax"; int index = 0; if (IsSection) { // Überprüfen, ob es sich um eine benannte Sektion handelt var expectedSectionName = RuleName.Replace("Section", "Identifier"); // Die Begin-/End Sektionen muss es geben, andernfalls ist die Grammatik falsch formuliert var sb = grammarInfo.Rules.Single(r => r.Name?.ToPascalcase() == SectionBeginName); var sbName = sb.Alternatives.Single().Elements.FirstOrDefault(e => e.Name.ToPascalcase() == expectedSectionName); var se = grammarInfo.Rules.Single(r => r.Name?.ToPascalcase() == SectionEndName); var seName = se.Alternatives.Single().Elements.FirstOrDefault(e => e.Name.ToPascalcase() == expectedSectionName); if (sbName != null && seName != null) { IsNamedSection = true; NamedSectionIdentifierName = expectedSectionName; } } foreach (var element in rule.Alternatives.Single().Elements) { var name = element.Name.ToPascalcase(); if (name == "EOF") { name = "Eof"; } var syntaxKind = element.SyntaxKind; if (syntaxKind == "EOF") { syntaxKind = "Eof"; } Slots.Add(new SlotMemberModel { Name = name, IsToken = element is TokenElement, IsLabeled = element.IsLabeled, SyntaxKind = syntaxKind, Cardinality = element.Cardinality, SlotIndex = index++ }); } }
private ParserProductionBuilder CreateQuantifier(QuantifierKind kind, QuantifierMode mode) { var parserRule = new ParserRule { IsInline = true }; parserRule.Productions.Add(new ParserProduction(CreateArray())); return(new ParserProductionBuilder(new ParserQuantifierEntry(new ParserRuleEntry(parserRule), kind, mode))); }
protected static ParserRule CreateParserRule([CallerMemberName] string name = null) { var parserRule = new ParserRule { Name = name }; CreatedParserRules.Add(parserRule); return(parserRule); }
private Predicate(string name, Sort arg1, params string[][] syntaxPatterns) { Name = name; arg1Sort = arg1; oneArgDomain = new List <string>(); lowLevelPredicate = Language.Predicate <string>(name); generationPattern = syntaxPatterns[0]; foreach (var p in syntaxPatterns) { ParserRule.AddSyntaxRule((Func <string, Literal>)OneArgParser, p); } }
public ParserContext(string womElement, ParserEngine engine, bool ignoreCase) { _ignoreCase = false; _womElement = womElement; _regExpStr = new StringBuilder(); _regExp = null; _engine = engine; _grammar = new GrammarDocument(_engine.GetMainPath); _ruleList = new ParserRuleList(); _parentRule = null; _grammar.ReadRules(this); }
public ParserContext(string womElement, ParserEngine engine, ParserRule rule, string filename) { _womElement = womElement; _ignoreCase = rule.ParentContext.IgnoreCase; _regExpStr = new StringBuilder(); _regExp = null; _engine = engine; _grammar = new GrammarDocument(filename); _ruleList = new ParserRuleList(); _parentRule = rule; AddParentRule(rule); _grammar.ReadRules(this); }
public ParserContext(string womElement, ParserEngine engine, ParserRule rule) { if (!String.IsNullOrEmpty(womElement)) { _womElement = womElement; } else { _womElement = rule.WomElement; } _ignoreCase = rule.ParentContext.IgnoreCase; _regExpStr = new StringBuilder(); _regExp = null; _engine = engine; _ruleList = new ParserRuleList(); _parentRule = rule; AddParentRule(rule); }
public EmailParserResult Invalid(ParserRule rule) { IsValid = false; Rule = rule; return(this); }
public void AddRule(ParserRule rule) { _ruleList.Add(rule); if (!String.IsNullOrEmpty(rule.Pattern)) { RegExpStr = rule.Pattern; } }
private void AddParentRule(ParserRule rule) { if (!String.IsNullOrEmpty(rule.End)) { AddRule(new ParserRule(rule.WomElement + "End", rule.End, "", "", "", null, rule.ParentContext, this)); } }
public ParserRuleEntry(ParserRule rule) { Rule = rule; Name = rule.Name; }
public void ReadRules(ParserContext context) { _reader = new XmlTextReader(_filename); string womObject = ""; string pattern = ""; string end = ""; string jump = ""; string optimization = ""; string temp = ""; string[] elements = null; ParserRule rule; while (_reader.Read()) { switch (_reader.NodeType) { case XmlNodeType.Element: switch (_reader.LocalName) { case "Rule": womObject = _reader.GetAttribute("Name"); pattern = _reader.GetAttribute("Pattern"); optimization = _reader.GetAttribute("Optimization"); temp = _reader.GetAttribute("Elements"); if (!String.IsNullOrEmpty(temp)) { elements = temp.Split(','); } if (_reader.AttributeCount == 6) { end = _reader.GetAttribute("End"); jump = _reader.GetAttribute("Jump"); } rule = new ParserRule(womObject, pattern, end, jump, optimization, elements, null, context); context.AddRule(rule); womObject = ""; pattern = ""; end = ""; jump = ""; optimization = ""; elements = null; break; } break; } } }
private Exception CreateExceptionFromRule(ParserRule matchingRule) { return (Exception)Activator.CreateInstance(matchingRule.ExceptionToThrow, Get(matchingRule.BadTokenIndex), matchingRule.ExpectedTokenType, matchingRule.LiteralTypeHint); }
public EmailParserResult(bool isValid, ParserRule rule) { IsValid = isValid; Rule = rule; }
private ICmdArgument CreateArgumentFromRule(ParserRule matchingRule) { var paramName = Get(matchingRule.NameIndex).Term; var paramValue = matchingRule.ParamIndex != -1 ? Get(matchingRule.ParamIndex).Term : null; var param = new CmdArgument(paramName, paramValue); return param; }
public void SimpleAdd(string text, string womElement, string jump, ParserRule rule) { MatchCollection matches; StringBuilder temp = new StringBuilder(); string savedtext = text; string ns = ""; string topic = ""; if (_inpre && !womElement.Contains("EmptyLine")) { if (!womElement.Contains("PreformattedSingleLine")) { _intermediate.AppendLine("</PreformattedSingleLine>"); _inpre = false; } } if (_intable && _lastWom.Contains("TableRowEnd") && (!womElement.Contains("TableRow"))) { if (_lastitemlevel > 0 && !_initem && !womElement.Contains("rderedList")) { int indx = _templist.ToString().LastIndexOf("</item>"); int len = _templist.Length; _templist.Remove(indx, len - indx); for (int x = _lastitemlevel; x > 0; x--) { _templist.AppendLine("</item></list>"); } _lastitemlevel = 0; _intermediate.Append(_templist.ToString()); _templist = new StringBuilder(); } if (!String.IsNullOrEmpty(_unclosedTableElements)) { temp = new StringBuilder(); string[] _tempElements = _unclosedTableElements.Split(';'); for (int i = _tempElements.Length - 2; i > -1; i--) { temp.AppendFormat("</{0}>", _tempElements[i]); } _intermediate.AppendLine(temp.ToString()); _unclosedTableElements = ""; } _intable = false; } if (_lastitemlevel > 0 && !_initem && !womElement.Contains("rderedList")) { int indx = _templist.ToString().LastIndexOf("</item>"); int len = _templist.Length; _templist.Remove(indx, len - indx); for (int x = _lastitemlevel; x > 0; x--) { _templist.AppendLine("</item></list>"); } _lastitemlevel = 0; _intermediate.Append(_templist.ToString()); _templist = new StringBuilder(); } if (text == "\r\n" || String.IsNullOrEmpty(text)) { if (womElement.Contains("rderedList")) { _templist.AppendLine("</item>"); _initem = false; } else if (womElement == "WikiStylingEnd") { string originalElement; while (rule.ParentContext.ParentRule != null) { rule = rule.ParentContext.ParentRule; //originalElement = rule.WomElement; } originalElement = rule.WomElement; if (_initem) { if (originalElement == "MultilineTableRow") { _templist.AppendLine("</WikiStyling></item><Break />\r\n"); } else { _templist.AppendLine("</WikiStyling></item>\r\n"); } } else if (originalElement == "MultilineTableRow") { WriteWom("</WikiStyling><Break />\r\n"); } else { WriteWom("</WikiStyling></" + originalElement + ">\r\n"); } _initem = false; } else if (womElement == "ParaEnd") { WriteWom("</" + womElement.Substring(0, womElement.Length - 3) + ">\r\n"); } else if (womElement == "HiddenWikiTalkMethodEnd") { WriteWom("</HiddenWikiTalkMethod>\r\n"); } else if (womElement.EndsWith("End")) { WriteWom("</" + womElement.Substring(0, womElement.Length - 3) + ">"); } else { if (_lastWom.Contains("PreformattedSingleLine")) { WriteWom("\r\n<Para>"); //womElement = "Para"; } else { if (womElement == "EmptyLine") { WriteWom("<EmptyLine />"); } else { WriteWom("\r\n<Para>"); } } } } else if (!String.IsNullOrEmpty(jump)) { switch (womElement) { case "UnorderedList": if (text.StartsWith("\r\n")) { _currentitemlevel = text.Length - 3; } else { _currentitemlevel = text.Length - 1; } if (_lastitemlevel < _currentitemlevel) { if (_lastitemlevel > 0) { _templist.Remove(_templist.Length - 9, 9); } _templist.AppendLine("<list type=\"unordered\"><item>"); } else if (_lastitemlevel > _currentitemlevel) { //_templist.Remove(_templist.Length - 9, 9); for (int x = _lastitemlevel; x > _currentitemlevel; x--) { _templist.AppendLine("</list></item>"); } _templist.AppendLine("<item>"); } else // (_lastitemlevel == text.Length - 1) { _templist.AppendLine("<item>"); } _lastitemlevel = _currentitemlevel; _initem = true; break; case "OrderedList": if (text.StartsWith("\r\n")) { _currentitemlevel = text.Length - 4; } else { _currentitemlevel = text.Length - 2; } if (_lastitemlevel < _currentitemlevel) { if (_lastitemlevel > 0) { _templist.Remove(_templist.Length - 9, 9); } _templist.AppendLine("<list type=\"ordered\"><item>"); } else if (_lastitemlevel > _currentitemlevel) { //_templist.Remove(_templist.Length - 9, 9); for (int x = _lastitemlevel; x > _currentitemlevel; x--) { _templist.AppendLine("</list></item>"); } //_currentitemlevel--; //_lastitemlevel = _currentitemlevel; _templist.AppendLine("<item>"); } else // (_lastitemlevel == text.Length - 1) { _templist.AppendLine("<item>"); } _lastitemlevel = _currentitemlevel; _initem = true; break; case "OrderedListForContinuation": if (text.StartsWith("\r\n")) { _currentitemlevel = text.Length - 3; } else { _currentitemlevel = text.Length - 1; } if (_lastitemlevel < _currentitemlevel) { if (_lastitemlevel > 0) { _templist.Remove(_templist.Length - 9, 9); } _templist.AppendLine("<list type=\"ordered\"><item>"); } else if (_lastitemlevel > _currentitemlevel) { //_templist.Remove(_templist.Length - 9, 9); for (int x = _lastitemlevel; x > _currentitemlevel; x--) { _templist.AppendLine("</list></item>"); } //_currentitemlevel--; //_lastitemlevel = _currentitemlevel; _templist.AppendLine("<item>"); } else // (_lastitemlevel == text.Length - 1) { _templist.AppendLine("<item>"); } _lastitemlevel = _currentitemlevel; _initem = true; break; case "IncludeTopic": _intermediate.AppendFormat("<{0}><Level>{1}</Level>\r\n", womElement, text.Length - 2); break; case "Header" : text = text.Replace("\r\n", ""); _intermediate.AppendFormat("<{0} level=\"{1}\">\r\n", womElement, text.Length); break; case "WikiStyling" : matches = rule.OptRegExp.Matches(text); //_intermediate.AppendFormat("<{0}><{1}>{2}</{1}>", womElement, rule.OptRegExp.GroupNameFromNumber(1), matches[0].Groups[1]); temp.AppendFormat("<{0}>", womElement); foreach (Match match in matches) { for (int x = 1; x < match.Groups.Count; x++) { if (match.Groups[x].Success) { if (x == 3) { temp.AppendFormat("<{0}>{1}</{0}>", rule.OptRegExp.GroupNameFromNumber(x), match.Groups[x]); } else { temp.AppendFormat("<{0}/>", rule.OptRegExp.GroupNameFromNumber(x)); } } } } WriteWom(temp.ToString()); break; case "HiddenSinglelineProperty": case "HiddenWikiTalkMethod": matches = rule.OptRegExp.Matches(text); _intermediate.AppendFormat("<{0}><{1}>{2}</{1}>\r\n", womElement, rule.OptRegExp.GroupNameFromNumber(1), matches[0].Groups[1]); break; case "WikiTalkMethod": case "MultilineProperty": case "SinglelineProperty": text = text.Trim(); string temptext = text; if (escapedText.IsMatch(text)) { _intermediate.AppendFormat("\r\n<{0}><{1}>{2}</{1}>", womElement, "Name", text.Substring(text.IndexOf(@"""""") + 2, text.Length - 7)); } else { matches = rule.OptRegExp.Matches(text); string rulename = rule.OptRegExp.GroupNameFromNumber(1).ToString(); text = matches[0].Groups[1].Value; string oneCap = @"(^[\p{Lu}]{1}|^[\p{Lu}]{1})[\p{Ll}\p{Nd}\P{Lu}]+:"; if (Regex.IsMatch(temptext, oneCap)) { _intermediate.AppendFormat("\r\n<{0}><{1}>{2}</{1}>", womElement, rulename, text); } else if (_mgr.TopicExists(text, ImportPolicy.DoNotIncludeImports)) { ns = _mgr.Namespace; if (_fed.HasPermission(new QualifiedTopicRevision(text, ns), TopicPermission.Read)) { string tipid = NewUniqueIdentifier(); string tiptext = ""; string tipstat = ""; if (_mgr.GetTopicLastModificationTime(text) != null) { tipstat = _mgr.GetTopicLastModificationTime(text).ToString(); } try { tipstat = tipstat + " - " + _mgr.GetTopicLastAuthor(text); } catch (FlexWiki.Security.FlexWikiAuthorizationException ex) { string stuff = ex.ToString(); } _intermediate.AppendFormat("\r\n<{0}><{1}>{2}</{1}><{3}><{4}>{5}</{4}><{6}>{7}</{6}><{8}>{9}</{8}>", womElement, rulename, text, "TopicExists", "Namespace", _defaultns, "Topic", text, "TipId", tipid); _intermediate.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExists", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } else { _intermediate.AppendFormat("\r\n<{0}><{1}>{2}</{1}><{7}><{3}>{4}</{3}><{5}>{6}</{5}></{7}>", womElement, rulename, text, womElement, text, "Namespace", _defaultns, "CreateNewTopic"); } } else { _intermediate.AppendFormat("\r\n<{0}><{1}>{2}</{1}><{7}><{3}>{4}</{3}><{5}>{6}</{5}></{7}>", womElement, rulename, text, womElement, text, "Namespace", _defaultns, "CreateNewTopic"); } } break; case "TableRow": if (!_intable) { _intermediate.AppendLine("<Table><TableRow><womCellText>"); _intable = true; _unclosedTableElements = "Table;TableRow;womCellText;"; } else { _intermediate.AppendLine("<TableRow><womCellText>"); _unclosedTableElements = _unclosedTableElements + "TableRow;womCellText;"; } break; case "MultilineTableRow": if (!_intable) { _intermediate.AppendLine("<Table><TableRow><womMultilineCellText>"); _unclosedTableElements = "Table;TableRow;womMultilineCellText;"; _intable = true; } else { _intermediate.AppendLine("<TableRow><womMultilineCellText>"); _unclosedTableElements = _unclosedTableElements + "TableRow;womMultilineCellText;"; } break; case "Para": case "TableStyle": _intermediate.AppendFormat("<{0}>", womElement); break; case "ExtendedCode": case "PreformattedMultilineKeyed": case "PreformattedMultiline": _intermediate.AppendFormat("<{0}>", womElement); break; case "TextileStrong": WriteWom("<TextileStrong>"); break; default: _intermediate.AppendFormat("<ParseError>{0}; {1}: {2}</ParseError>\r\n", womElement, text, jump); break; } } else if (womElement == "womCellText") { _intermediate.AppendLine("</womCellText><womCellText>"); } else if (womElement == "womMultilineCellText") { _intermediate.AppendLine("</womMultilineCellText><womMultilineCellText>"); } else if (womElement.EndsWith("End")) { if (womElement == "TableRowEnd") { _intermediate.AppendLine("</womCellText></TableRow>"); int indx = _unclosedTableElements.LastIndexOf("womCellText"); if (_unclosedTableElements.Length > indx + 12) { _unclosedTableElements = _unclosedTableElements.Substring(0, indx) + _unclosedTableElements.Substring(indx + 12); } else { _unclosedTableElements = _unclosedTableElements.Substring(0, indx); } indx = _unclosedTableElements.LastIndexOf("TableRow"); if (_unclosedTableElements.Length > indx + 9) { _unclosedTableElements = _unclosedTableElements.Substring(0, indx) + _unclosedTableElements.Substring(indx + 9); } else { _unclosedTableElements = _unclosedTableElements.Substring(0, indx); } } else if (womElement == "MultilineTableRowEnd") { _intermediate.AppendLine("</womMultilineCellText></TableRow>"); int indx = _unclosedTableElements.LastIndexOf("womMultilineCellText"); if (_unclosedTableElements.Length > indx + 21) { _unclosedTableElements = _unclosedTableElements.Substring(0, indx) + _unclosedTableElements.Substring(indx + 21); } else { _unclosedTableElements = _unclosedTableElements.Substring(0, indx); } indx = _unclosedTableElements.LastIndexOf("TableRow"); if (_unclosedTableElements.Length > indx + 9) { _unclosedTableElements = _unclosedTableElements.Substring(0, indx) + _unclosedTableElements.Substring(indx + 9); } else { _unclosedTableElements = _unclosedTableElements.Substring(0, indx); } } else if (womElement == "PreformattedMultilineEnd") { if (text.Length > 4) { _intermediate.AppendFormat("{0}</{1}>\r\n", text.Substring(2, text.Length - 4), womElement.Substring(0, womElement.Length - 3)); } else { WriteWom("</" + womElement.Substring(0, womElement.Length - 3) + ">"); } } else if (womElement.Contains("rderedList")) { if (_currentitemlevel > _lastitemlevel) { for (int x = _currentitemlevel; x > _lastitemlevel; x--) { _templist.AppendLine("</item></list>"); } } _templist.AppendLine("</item>"); _initem = false; } else if (womElement == "HiddenWikiTalkMethodEnd") { WriteWom("</HiddenWikiTalkMethod>\r\n"); } else { WriteWom("</" + womElement.Substring(0, womElement.Length - 3) + ">"); } } else if (womElement.EndsWith("PreformattedSingleLine")) { if (_inpre) { if (text != "\r\n") { _intermediate.Append(text); } } else { if (text.StartsWith(" \r\n")) { _intermediate.AppendFormat("\r\n<{0}>{1}", "PreformattedSingleLine", text.Substring(3)); } else { _intermediate.AppendFormat("\r\n<{0}>{1}", "PreformattedSingleLine", text); } _inpre = true; } } else if (text.EndsWith("\r\n")) { switch (womElement) { case "PageRule": _intermediate.AppendLine("<PageRule/>"); break; case "womMultilineCode": if (text.StartsWith("\r\n\r\n")) { _intermediate.AppendFormat("<{0}>{1}</{0}>\r\n", womElement, text.Substring(2, text.Length - 4)); } else { _intermediate.AppendFormat("<{0}>{1}</{0}>\r\n", womElement, text); } break; case "womMultilineCell": text = text.TrimEnd(lineEnds); WriteWom("<womMultilineCell>" + text + "</womMultilineCell><Break />"); break; case "Containerdiv": case "Containerspan": case "ContainerEnddiv": case "ContainerEndspan": if (_initem) { _templist.AppendFormat("{0}", text); } else { _intermediate.AppendFormat("{0}", text); } break; default: text = text.TrimEnd(lineEnds); _intermediate.AppendFormat("<{0}>{1}</{0}>\r\n", womElement, text); break; } } else { switch (womElement) { case "FreeLinkToHttpImageDisplayGif": case "FreeLinkToHttpsImageDisplayGif": case "FreeLinkToHttpImageDisplayJpg": case "FreeLinkToHttpsImageDisplayJpg": case "FreeLinkToHttpImageDisplayJpeg": case "FreeLinkToHttpsImageDisplayJpeg": case "FreeLinkToHttpImageDisplayPng": case "FreeLinkToHttpsImageDisplayPng": case "FreeLinkToHttpLink": case "FreeLinkToHttpsLink": case "FreeLinkToMailto": matches = rule.OptRegExp.Matches(text); string firstGroupName = rule.OptRegExp.GroupNameFromNumber(1); string freetext = matches[0].Groups[1].Value; string secondGroupName = rule.OptRegExp.GroupNameFromNumber(2); string link = matches[0].Groups[2].Value; string tooltip = ""; if (tooltipRegex.IsMatch(freetext)) { matches = tooltipRegex.Matches(freetext); freetext = matches[0].Groups[1].Value; if (matches[0].Groups[2].Success) { tooltip = matches[0].Groups[2].Value; } } while (textileRegex.IsMatch(freetext)) { freetext = textileMatch(freetext); } if (!String.IsNullOrEmpty(tooltip)) { temp.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}></{0}>", womElement, firstGroupName, freetext, secondGroupName, link, "Tip", tooltip); } else { temp.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}></{0}>", womElement, firstGroupName, freetext, secondGroupName, link); } WriteWom(temp.ToString()); break; case "NamespaceTopic": case "NamespaceMulticapsTopic": string[] testitem = text.Split('.'); if (_fed.NamespaceManagerForNamespace(testitem[0]) != null) { if (_mgr.TopicExists(new UnqualifiedTopicName(testitem[1]), ImportPolicy.IncludeImports)) { ns = testitem[0]; topic = testitem[1]; if (_fed.HasPermission(new QualifiedTopicRevision(topic, ns), TopicPermission.Read)) { string tipid = NewUniqueIdentifier(); string tiptext = ""; if (_mgr.GetTopicProperty(topic, "Summary") != null) { tiptext = _mgr.GetTopicProperty(topic, "Summary").LastValue; } string tipstat = _mgr.GetTopicLastModificationTime(topic) + " - " + _mgr.GetTopicLastAuthor(topic); if (_initem) { _templist.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}><{7}>{8}</{7}>", "TopicExists", "Namespace", ns, "Topic", topic, "TipId", tipid, "DisplayText", topic); _templist.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExists", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } else { _intermediate.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}><{7}>{8}</{7}>", "TopicExists", "Namespace", ns, "Topic", topic, "TipId", tipid, "DisplayText", topic); _intermediate.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExists", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } } else { temp.AppendFormat("<{4}><{0}>{1}</{0}><{2}>{3}</{2}></{4}>", womElement, savedtext, "CreateTopic", topic, "CreateNamespaceTopic"); } } } else { temp.AppendFormat("<{0}>{1}</{0}>", "paraText", savedtext); } WriteWom(temp.ToString()); break; case "StartsWithOneCap": case "StartsWithMulticaps": case "MalformedTopic": if (womElement == "MalformedTopic") { matches = rule.OptRegExp.Matches(text); if (matches.Count > 0) { text = matches[0].Groups[1].Value; } } topic = text.Trim(); if (_mgr.TopicExists(topic, ImportPolicy.IncludeImports)) { ns = _mgr.Namespace; if (_fed.HasPermission(new QualifiedTopicRevision(topic, ns), TopicPermission.Read)) { string tipid = NewUniqueIdentifier(); string tiptext = ""; string tipstat = ""; if (_mgr.GetTopicLastModificationTime(topic) != null) { tipstat = _mgr.GetTopicLastModificationTime(topic).ToString(); } try { tipstat = tipstat + " - " + _mgr.GetTopicLastAuthor(topic); } catch (FlexWiki.Security.FlexWikiAuthorizationException ex) { string stuff = ex.ToString(); } if (_initem) { _templist.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}><{7}>{8}</{7}>", "TopicExists", "Namespace", ns, "Topic", topic, "TipId", tipid, "DisplayText", topic); _templist.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExists", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } else { _intermediate.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}><{7}>{8}</{7}>", "TopicExists", "Namespace", ns, "Topic", topic, "TipId", tipid, "DisplayText", topic); _intermediate.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExists", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } } else { if (_initem) { _templist.AppendFormat("<{0}>{1}</{0}>", "paraText", savedtext); } else { _intermediate.AppendFormat("<{0}>{1}</{0}>", "paraText", savedtext); } } } else { if (_initem) { _templist.AppendFormat("<{4}><{0}>{1}</{0}><{2}>{3}</{2}></{4}>", womElement, topic, "Namespace", _defaultns, "CreateNewTopic"); } else { _intermediate.AppendFormat("<{4}><{0}>{1}</{0}><{2}>{3}</{2}></{4}>", womElement, topic, "Namespace", _defaultns, "CreateNewTopic"); } } break; case "LinkToAnchor": if (rule.OptRegExp.IsMatch(text)) { matches = rule.OptRegExp.Matches(text); text = matches[0].Groups[1].Value; if (_mgr.TopicExists(text, ImportPolicy.DoNotIncludeImports)) { if (_fed.HasPermission(new QualifiedTopicRevision(text, _defaultns), TopicPermission.Read)) { string tipid = NewUniqueIdentifier(); string tiptext = ""; string tipstat = ""; if (_mgr.GetTopicProperty(text, "Summary") != null) { tiptext = _mgr.GetTopicProperty(text, "Summary").LastValue; } if (_mgr.GetTopicLastModificationTime(text) != null) { tipstat = _mgr.GetTopicLastModificationTime(text).ToString(); } try { tipstat = tipstat + " - " + _mgr.GetTopicLastAuthor(text); } catch (FlexWiki.Security.FlexWikiAuthorizationException ex) { string stuff = ex.ToString(); } if (_initem) { _templist.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}><{7}>{8}</{7}><{9}>{10}</{9}>", "TopicExistsAnchor", "Namespace", _defaultns, "Topic", text, "Anchor", matches[0].Groups[2], "TipId", tipid, "DisplayText", matches[0].Groups[1]); _templist.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExistsAnchor", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } else { _intermediate.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}><{7}>{8}</{7}><{9}>{10}</{9}>", "TopicExistsAnchor", "Namespace", _defaultns, "Topic", text, "Anchor", matches[0].Groups[2], "TipId", tipid, "DisplayText", matches[0].Groups[1]); _intermediate.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExistsAnchor", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } } else { if (_initem) { _templist.AppendFormat("<{0}>{1}</{0}>", "paraText", savedtext); } else { _intermediate.AppendFormat("<{0}>{1}</{0}>", "paraText", savedtext); } } } else { if (_initem) { _templist.AppendFormat("<{4}><{0}>{1}</{0}><{2}>{3}</{2}></{4}>", "Topic", text, "Namespace", _defaultns, "CreateNewTopic"); } else { _intermediate.AppendFormat("<{4}><{0}>{1}</{0}><{2}>{3}</{2}></{4}>", "Topic", text, "Namespace", _defaultns, "CreateNewTopic"); } } } break; case "FreeLinkToNamespaceTopic": case "FreeLinkToNamespaceMalformedTopic": try { matches = rule.OptRegExp.Matches(text); ns = matches[0].Groups[2].Value; matches = rule.OptRegExp.Matches(text); text = matches[0].Groups[3].Value; if (_fed.NamespaceManagerForNamespace(ns) != null) { if (_mgr.TopicExists(new UnqualifiedTopicName(text), ImportPolicy.IncludeImports)) { if (_fed.HasPermission(new QualifiedTopicRevision(text, ns), TopicPermission.Read)) { string tipid = NewUniqueIdentifier(); string tiptext = ""; if (_mgr.GetTopicProperty(text, "Summary") != null) { tiptext = _mgr.GetTopicProperty(text, "Summary").LastValue; } string tipstat = _mgr.GetTopicLastModificationTime(text) + " - " + _mgr.GetTopicLastAuthor(text); if (_initem) { _templist.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}><{7}>{8}</{7}>", "TopicExists", "Namespace", ns, "Topic", text, "TipId", tipid, "DisplayText", matches[0].Groups[1]); _templist.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExists", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } else { _intermediate.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}><{7}>{8}</{7}>", "TopicExists", "Namespace", ns, "Topic", text, "TipId", tipid, "DisplayText", matches[0].Groups[1]); _intermediate.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExists", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } } else { if (_initem) { _templist.AppendFormat("<{0}>{1}</{0}>", "paraText", savedtext); } else { _intermediate.AppendFormat("<{0}>{1}</{0}>", "paraText", savedtext); } } } else { if (_initem) { _templist.AppendFormat("<{4}><{0}>{1}</{0}><{2}>{3}</{2}><{5}>{6}</{5}></{4}>", "Topic", text, "Namespace", ns, "CreateNewTopic", "DisplayText", matches[0].Groups[1]); } else { _intermediate.AppendFormat("<{4}><{0}>{1}</{0}><{2}>{3}</{2}><{5}>{6}</{5}></{4}>", "Topic", text, "Namespace", ns, "CreateNewTopic", "DisplayText", matches[0].Groups[1]); } } } else { if (_initem) { _templist.AppendFormat("<{0}>{1}</{0}>", "paraText", savedtext); } else { _intermediate.AppendFormat("<{0}>{1}</{0}>", "paraText", savedtext); } } } catch (FlexWikiException ex) { string error = ex.ToString(); } break; case "FreeLinkToTopic": case "FreeLinkToMultiCapsTopic": case "FreeLinkToMalformedTopic": matches = rule.OptRegExp.Matches(text); text = matches[0].Groups[2].Value; if (_mgr.TopicExists(text, ImportPolicy.IncludeImports)) { string tipid = NewUniqueIdentifier(); string tiptext = ""; string tipstat = ""; if (_mgr.GetTopicProperty(text, "Summary") != null) { tiptext = _mgr.GetTopicProperty(text, "Summary").LastValue; } if (_mgr.GetTopicLastModificationTime(text) != null) { tipstat = _mgr.GetTopicLastModificationTime(text).ToString(); } try { tipstat = tipstat + " - " + _mgr.GetTopicLastAuthor(text); } catch (FlexWiki.Security.FlexWikiAuthorizationException ex) { string stuff = ex.ToString(); } if (_initem) { _templist.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}><{7}>{8}</{7}>", "TopicExists", "Namespace", _defaultns, "Topic", text, "TipId", tipid, "DisplayText", matches[0].Groups[1]); _templist.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExists", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } else { _intermediate.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}><{7}>{8}</{7}>", "TopicExists", "Namespace", _defaultns, "Topic", text, "TipId", tipid, "DisplayText", matches[0].Groups[1]); _intermediate.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExists", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } } else { if (_initem) { _templist.AppendFormat("<{4}><{0}>{1}</{0}><{2}>{3}</{2}><{5}>{6}</{5}></{4}>", "Topic", text, "Namespace", _defaultns, "CreateNewTopic", "DisplayText", matches[0].Groups[1]); } else { _intermediate.AppendFormat("<{4}><{0}>{1}</{0}><{2}>{3}</{2}><{5}>{6}</{5}></{4}>", "Topic", text, "Namespace", _defaultns, "CreateNewTopic", "DisplayText", matches[0].Groups[1]); } } break; case "HiddenMultilineProperty": //matches = rule.OptRegExp.Matches(text); _intermediate.AppendFormat("<{0}>{1}</{0}>\r\n", womElement, text); break; case "FreeLinkToAnchor": matches = rule.OptRegExp.Matches(text); text = matches[0].Groups[2].Value; if (_mgr.TopicExists(text, ImportPolicy.DoNotIncludeImports)) { string tipid = NewUniqueIdentifier(); string tiptext = _mgr.GetTopicProperty(text, "Summary").LastValue; string tipstat = _mgr.GetTopicLastModificationTime(text) + " - " + _mgr.GetTopicLastAuthor(text); if (_initem) { _templist.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}><{7}>{8}</{7}><{9}>{10}</{9}>", "TopicExistsAnchor", "Namespace", _defaultns, "Topic", text, "Anchor", matches[0].Groups[3], "TipId", tipid, "DisplayText", matches[0].Groups[1]); _templist.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExistsAnchor", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } else { _intermediate.AppendFormat("<{0}><{1}>{2}</{1}><{3}>{4}</{3}><{5}>{6}</{5}><{7}>{8}</{7}><{9}>{10}</{9}>", "TopicExistsAnchor", "Namespace", _defaultns, "Topic", text, "Anchor", matches[0].Groups[3], "TipId", tipid, "DisplayText", matches[0].Groups[1]); _intermediate.AppendFormat("<{1}><{2}>{3}</{2}><{4}>{5}</{4}><{6}>{7}</{6}></{1}></{0}>", "TopicExistsAnchor", "TipData", "TipIdData", tipid, "TipText", ParserEngine.escape(tiptext), "TipStat", tipstat); } } else { if (_initem) { _templist.AppendFormat("<{4}><{0}>{1}</{0}><{2}>{3}</{2}><{5}>{6}</{5}></{4}>", "Topic", text, "Namespace", _defaultns, "CreateNewTopic", "DisplayText", matches[0].Groups[1]); } else { _intermediate.AppendFormat("<{4}><{0}>{1}</{0}><{2}>{3}</{2}><{5}>{6}</{5}></{4}>", "Topic", text, "Namespace", _defaultns, "CreateNewTopic", "DisplayText", matches[0].Groups[1]); } } break; case "TextileCodeLineInLine": case "TextileEmphasisInLine": case "TextileDeemphasisInLine": case "TextileDeletionInLine": case "TextileInsertedInLine": case "TextileSubscriptInLine": case "TextileSuperscriptInLine": case "TextileCodeLineLineStart": case "TextileEmphasisLineStart": case "TextileDeemphasisLineStart": case "TextileDeletionLineStart": case "TextileInsertedLineStart": case "TextileSubscriptLineStart": case "TextileSuperscriptLineStart": case "TextileCitationInLine": case "TextileCitationLineStart": case "TextileStrongInLine": case "TextileStrongLineStart": case "Italics": case "Strong": case "EscapedNoFormatText": matches = rule.OptRegExp.Matches(text); if (matches.Count > 0) { text = matches[0].Groups[1].Value; } if (textileRegex.Matches(text).Count > 0) { while (textileRegex.IsMatch(text)) { text = textileMatch(text); } } //else //{ // matches = rule.OptRegExp.Matches(text); // int lencontrol = 1; // if (womElement == "Strong") // { // lencontrol = 3; // } // else if (womElement.Contains("Citation") || womElement.Contains("Deemphasis") || womElement == "EscapedNoFormatText" || womElement == "Italics") // { // lencontrol = 2; // } // text = text.Substring(0, matches[0].Groups[1].Index - lencontrol) + matches[0].Groups[1].Value + text.Substring(matches[0].Groups[1].Index + matches[0].Groups[1].Length + lencontrol); //} if (_initem) { _templist.AppendFormat("<{0}>{1}</{0}>", womElement, text); } else { _intermediate.AppendFormat("<{0}>{1}</{0}>", womElement, text); } break; case "CellStyleColor": case "StyleHexColor": case "StyleHexTextColor": case "CellTextColor": if (_initem) { _templist.AppendFormat("<{0}>{1}</{0}>", womElement, text.Substring(1, text.Length - 2)); } else { _intermediate.AppendFormat("<{0}>{1}</{0}>", womElement, text.Substring(1, text.Length - 2)); } break; case "AltFileLink": matches = rule.OptRegExp.Matches(text); if (_initem) { _templist.AppendFormat("<{0}>{1}</{0}>", womElement, matches[0].Groups[1]); } else { _intermediate.AppendFormat("<{0}>{1}</{0}>", womElement, matches[0].Groups[1]); } break; case "womHeaderText": string anchor = CreateAnchor(text); _intermediate.AppendFormat("<{0}>{1}</{0}><{2}>{3}</{2}>", womElement, text, "AnchorText", anchor); break; case "FreeLinkToHttpDisplayImage": case "WikiTalkLink": case "WikiForm": case "HttpDisplayImage": case "Containerdiv": case "Containerspan": case "ContainerEnddiv": case "ContainerEndspan": case "ErrorMessage": if (_initem) { _templist.AppendFormat("{0}", text); } else { _intermediate.AppendFormat("{0}\r\n", text); } break; case "womMultilineCell": string replacement = Regex.Replace(text, "\r\n", "<Break />"); WriteWom("<womMultilineCell>" + replacement + "</womMultilineCell>"); break; case "womStyledCode": string fixwhitespace = Regex.Replace(text, " ", " "); fixwhitespace = Regex.Replace(fixwhitespace, "\r\n", "<Break />"); //{ // text = "<Break /> "; //} WriteWom("<womStyledCode>" + fixwhitespace + "</womStyledCode>"); break; default: if (_initem) { _templist.AppendFormat("<{0}>{1}</{0}>", womElement, text); } else { _intermediate.AppendFormat("<{0}>{1}</{0}>", womElement, text); } break; } } _lastWom = womElement; }
public AbstractSlotModel(ParserRule rule, string baseNamespace) { RawRuleName = rule.Name; RuleName = rule.Name.ToPascalcase(); BaseNamespace = baseNamespace; }