void GenHtmlForBlock(PegNode block) { var child = block.child_; var content = string.Empty; switch ((EMarkdown)child.id_) { case EMarkdown.Heading: content = GenHeading(child); break; case EMarkdown.BulletList: case EMarkdown.OrderedList: content = GetList(child); break; default: break; } _outFile.Write(content); }
private void HandleWordSpan(PegNode node, StyleContext context, StructuralGlyph parent) { int posBeg = node.match_.posBeg_; int posEnd = node.match_.posEnd_; var childNode = node.child_; string str = string.Empty; if (null == childNode) // no escape sequences { str = _sourceText.Substring(posBeg, posEnd - posBeg); } else // at least one child node (Esc seq) { int beg = posBeg; int end = childNode.match_.posBeg_; while (childNode != null) { str += _sourceText.Substring(beg, end - beg); str += _sourceText.Substring(childNode.match_.posBeg_ + 1, 1); beg = childNode.match_.posEnd_; childNode = childNode.next_; end = null != childNode ? childNode.match_.posBeg_ : posEnd; } str += _sourceText.Substring(beg, end - beg); } parent.Add(new TextGlyph(str, context)); }
bool Exec(PegCharParser.Matcher startRule, out PegNode tree) { bool bMatches = startRule(); tree = ((PegCharParser)startRule.Target).GetRoot(); return(bMatches); }
void GenHtmlForBlock(PegNode block) { var child = block.child_; var content = string.Empty; switch ((EHtml)child.id_) { case EHtml.HtmlBlockH1: case EHtml.HtmlBlockH2: case EHtml.HtmlBlockH3: case EHtml.HtmlBlockH4: case EHtml.HtmlBlockH5: case EHtml.HtmlBlockH6: content = GenHeading(child); break; case EHtml.HtmlBlockOl: case EHtml.HtmlBlockUl: content = GetList(child); break; default: break; } _outFile.Write(content); }
private IMultiRenameElement HandleIntegerTemplate(PegNode node) { var childNode = node.child_; if (childNode == null) { throw new ArgumentNullException("childNode"); } string shortCut = _sourceText.Substring(childNode.match_.posBeg_, childNode.match_.Length); int numberOfDigits = 0; int offset = 0; int step = 1; while (null != (childNode = childNode.next_)) { switch (childNode.id_) { case (int)EAltaxo_MultiRename.IntArgNumberOfDigits: numberOfDigits = int.Parse(_sourceText.Substring(childNode.match_.posBeg_, childNode.match_.Length)); break; case (int)EAltaxo_MultiRename.IntArg1st: offset = int.Parse(_sourceText.Substring(childNode.match_.posBeg_, childNode.match_.Length)); break; case (int)EAltaxo_MultiRename.IntArg2nd: step = int.Parse(_sourceText.Substring(childNode.match_.posBeg_, childNode.match_.Length)); break; } } return(new MultiRenameIntegerElement(_renameData, shortCut, numberOfDigits, offset, step)); }
public static IEnumerable <PegNode> FindNodeGroup(PegNode node, int id) { var nodes = new List <PegNode>(); var child = FindNode(node, id); if (child != null) { nodes.Add(child); } for (child = child.next_; child != null; child = child.next_) { if (node.id_ == (int)id) { nodes.Add(child); } else { break; } } return(nodes); }
public static PegNode FindNode(PegNode node, int nodeDistance, params int[] ids)/*FIND_IN_SEMANTIC_BLOCK*/ { if (node == null || nodeDistance <= 0) { return(null); } foreach (int id in ids) { if (node.id_ == id) { return(node); } } PegNode foundNode = FindNode(node.child_, nodeDistance - 1, ids); if (foundNode != null) { return(foundNode); } foundNode = FindNode(node.next_, nodeDistance - 1, ids); if (foundNode != null) { return(foundNode); } return(null); }
private IMultiRenameElement HandleDateTimeTemplate(PegNode node) { string dateTimeFormat = null; bool useUtcTime = false; var childNode = node.child_; if (childNode == null) { throw new ArgumentNullException("childNode"); } string shortCut = _sourceText.Substring(childNode.match_.posBeg_, childNode.match_.Length); while (null != (childNode = childNode.next_)) { switch (childNode.id_) { case (int)EAltaxo_MultiRename.StringContent: dateTimeFormat = GetEscStringText(childNode); break; case (int)EAltaxo_MultiRename.DateTimeKind: useUtcTime = 'u' == char.ToLowerInvariant(_sourceText[childNode.match_.posBeg_]); break; } } return(new MultiRenameDateTimeElement(_renameData, shortCut, dateTimeFormat, useUtcTime)); }
private IMultiRenameElement HandleStringTemplate(PegNode node) { var childNode = node.child_; if (childNode == null) { throw new ArgumentNullException("childNode"); } string shortCut = _sourceText.Substring(childNode.match_.posBeg_, childNode.match_.Length); int start = 0; int last = -1; while (null != (childNode = childNode.next_)) { switch (childNode.id_) { case (int)EAltaxo_MultiRename.IntArgOnly: start = last = int.Parse(_sourceText.Substring(childNode.match_.posBeg_, childNode.match_.Length)); break; case (int)EAltaxo_MultiRename.IntArg1st: start = int.Parse(_sourceText.Substring(childNode.match_.posBeg_, childNode.match_.Length)); break; case (int)EAltaxo_MultiRename.IntArg2nd: last = int.Parse(_sourceText.Substring(childNode.match_.posBeg_, childNode.match_.Length)); break; } } return(new MultiRenameStringElement(_renameData, shortCut, start, last)); }
private void btnPostProcess_Click(object sender, EventArgs e) { if (cmbPostProcess.SelectedIndex < 0 || cboGrammar.SelectedIndex < 0) { return; } SampleInfo selectedSample = (SampleInfo)cboGrammar.Items[cboGrammar.SelectedIndex]; PegNode root = (PegNode)(tvParseTree.Nodes.Count == 0 ? null : tvParseTree.Nodes[0].Tag); TextBoxWriter errOut = new TextBoxWriter(Output); ParserPostProcessParams postProcParams; if (selectedSample.startRule.Target is PegCharParser) { string grammarFileName, src; GetGrammarFileNameAndSource((PegCharParser)selectedSample.startRule.Target, root.id_, out grammarFileName, out src); postProcParams = new ParserPostProcessParams(GetOutputDirectory(), GetSourceFileTitle(), grammarFileName, root, src, errOut); } else { string grammarFileName; byte[] src; GetGrammarFileNameAndSource((PegByteParser)selectedSample.startRule.Target, root.id_, out grammarFileName, out src); postProcParams = new ParserPostProcessParams(GetOutputDirectory(), GetSourceFileTitle(), grammarFileName, root, src, errOut); } var selectedPostProcessor = (IParserPostProcessor)cmbPostProcess.Items[cmbPostProcess.SelectedIndex]; if (selectedPostProcessor != null) { selectedPostProcessor.Postprocess(postProcParams); } }
private void WriteLength(BinaryWriter rw, PegNode pegNode, bool bIsComposite) { Debug.Assert(pegNode.child_ != null && pegNode.child_.next_ != null); if (bIsComposite) { rw.Write((byte)0x80); } else { PegNode lengthNode = pegNode.child_.next_; uint length = GetLength(lengthNode.next_); int bytesToWrite = GetLengthEncodingLength(length); if (bytesToWrite == 1) { lengthBuffer[0] = (byte)length; } else { lengthBuffer[0] = (byte)((bytesToWrite - 1) | 0x80); int j = 1; for (int i = bytesToWrite - 1; i > 0; i--) { byte @byte = (byte)((length & (0xFF << 8 * (i - 1))) >> 8 * (i - 1)); lengthBuffer[j++] = @byte; } } rw.Write(lengthBuffer, 0, bytesToWrite); } }
private void WriteInDefinite(BinaryWriter rw, PegNode pegNode) { PegNode child; if (pegNode == null) { return; } bool bIsComposite = IsComposite(pegNode, out child); WriteTag(rw, pegNode); WriteLength(rw, pegNode, bIsComposite); if (bIsComposite) { for (; child != null; child = child.next_) { WriteInDefinite(rw, child); } rw.Write((ushort)0x0000); } else { Debug.Assert(pegNode.child_ != null && pegNode.child_.next_ != null && pegNode.child_.next_.next_ != null); WriteContent(rw, pegNode.child_.next_.next_); } }
private string GetListBlock(PegNode node) { //TODO inline var itemString = node.GetAsString(_src); return(itemString); }
public void CreateHtml() { pegSrc = File.ReadAllText(_htmlPEGFile); root = PegRunUtils.ParsePegGrammar(pegSrc, errOut); var postProcParams = new ParserPostProcessParams(GetOutputDirectory(), "Html", "Html", root, pegSrc, errOut); PegRunUtils.CreatePegCodeFile(postProcParams); }
private void WriteTag(BinaryWriter rw, PegNode pegNode) { Debug.Assert(pegNode.child_ != null); PegNode tagNode = pegNode.child_; Debug.Assert(tagNode.id_ == (int)EBERTree.OneOctetTag || tagNode.id_ == (int)EBERTree.MultiOctetTag); rw.Write(context_.byteSrc_, tagNode.match_.posBeg_, tagNode.match_.posEnd_ - tagNode.match_.posBeg_); }
internal TreeContext(ParserPostProcessParams generatorParams) { generatorParams_ = generatorParams; root_ = generatorParams.root_; byteSrc_ = generatorParams.byteSrc_; errOut_ = generatorParams.errOut_; sErrorPrefix = "<BER_DEFINITE_CONVERTER> FILE:'" + generatorParams_.grammarFileName_ + "' "; }
public void Postprocess(ParserPostProcessParams postProcessorParams) { _root = postProcessorParams.root_; _src = postProcessorParams.src_; _generatorParams = postProcessorParams; OpenOutFile("", ".html"); GenHtmlForBlock(); }
private void HandleSentence(PegNode node, StyleContext context, StructuralGlyph parent) { var line = new GlyphLine(); parent.Add(line); if (node.child_ != null) { VisitNode(node.child_, context, line); } }
public override string TreeNodeToString(PegNode node) { string s = GetRuleNameFromId(node.id_); BERTreeNode berNode = node as BERTreeNode; if (berNode != null) { s += ": " + berNode.TreeNodeToString(src_); } return(s); }
PegNode PrimitiveValueNodeCreator(ECreatorPhase phase, PegNode parentOrCreated, int id) { if (phase == ECreatorPhase.eCreate || phase == ECreatorPhase.eCreateAndComplete) { return(new PrimitiveValueNode(parentOrCreated, id)); } else { return(null); } }
public static PegNode FindNodeInParents(PegNode node, int id) { for (; node != null; node = node.parent_) { if (node.id_ == (int)id) { return(node); } } return(null); }
public static PegNode FindNodeNext(PegNode node, int id) { for (node = node.next_; node != null; node = node.next_) { if (node.id_ == (int)id) { return(node); } } return(null); }
private string GetListContinuation(PegNode node) { var listHead = string.Empty; var listbody = new List <string>(); var listBlockNode = PegUtils.FindNode(node, (int)EMarkdown.ListBlock); //TODO 暂时简化点,只检查第一个元素 var enumeratorReg = new Regex("[0-9]+."); var bulletReg = new Regex("[+*-]"); if (listBlockNode.child_.id_ == (int)EMarkdown.Symbol) { listHead = templates[MarkdownKind.BulletList].sCodeTemplate; } else { listHead = templates[MarkdownKind.OrderedList].sCodeTemplate; } if (listBlockNode != null) { for (; listBlockNode != null; listBlockNode = PegUtils.FindNodeNext(listBlockNode, (int)EMarkdown.ListBlock)) { var blockstring = GetListBlock(listBlockNode); var bulletMatch = bulletReg.Match(blockstring); if (bulletMatch != Match.Empty) { if (bulletMatch.Index == 0) { blockstring = blockstring.Remove(bulletMatch.Index, bulletMatch.Length); } } var enumeratorMatch = enumeratorReg.Match(blockstring); if (enumeratorMatch != Match.Empty) { if (enumeratorMatch.Index == 0) { blockstring = blockstring.Remove(enumeratorMatch.Index, enumeratorMatch.Length); } } listbody.Add( templates[MarkdownKind.ListItem].sCodeTemplate .Replace("${ListItemBody}", blockstring)); } } return(listHead.Replace("${ListBody}", string.Join("", listbody))); }
PegNode LengthNodeCreator(ECreatorPhase phase, PegNode parentOrCreated, int id) { if (phase == ECreatorPhase.eCreate || phase == ECreatorPhase.eCreateAndComplete) { return(new LengthNode(parentOrCreated, id)); } else { ((LengthNode)parentOrCreated).lengthValue_ = top.length; return(null); } }
PegNode TagNodeCreator(ECreatorPhase phase, PegNode parentOrCreated, int id) { if (phase == ECreatorPhase.eCreate || phase == ECreatorPhase.eCreateAndComplete) { return(new TagNode(parentOrCreated, id)); } else { ((TagNode)parentOrCreated).tagValue_ = top.tag; return(null); } }
public MultiRenameTreeWalker(string sourceText, MultiRenameData data) { _sourceText = sourceText; _renameData = data; var parser = new MultiRenameParser(data); parser.SetSource(_sourceText); bool bMatches = parser.MainSentence(); _tree = parser.GetRoot(); }
public static PegNode FindNodeInParents(PegNode node, params int[] ids) { foreach (int id in ids) { PegNode foundNode = FindNodeInParents(node, id); if (foundNode != null) { return(foundNode); } } return(null); }
public static string PegNodeToXml(PegNode pn, string text) { var message = new StringBuilder(10000); var xml = XmlWriter.Create(new StringWriterWithEncoding(message, Encoding.UTF8), DEFAULT_XML_WRITER_SETTINGS); xml.WriteStartDocument(); PegNodeToXmlRecurse(pn, text, xml); xml.WriteEndDocument(); xml.Close(); return(message.ToString()); }
private StructuralGlyph HandleSpace(PegNode node, StyleContext context, StructuralGlyph parent) { if (_sourceText[node.match_.posBeg_] == '\t') { HandleTab(parent); return(parent); } else // newline { return(HandleNewline(parent, context)); } }
public ParserPostProcessParams(string outputDirectory,string sourceFileTitle, string grammarFileName, PegNode root, byte[] byteSrc, TextWriter errOut) { outputDirectory_ = outputDirectory; sourceFileTitle_ = sourceFileTitle; grammarFileName_ = grammarFileName; root_ = root; src_ = null; byteSrc_ = byteSrc; errOut_ = errOut; maxLineLength_= 60; spacesPerTap_ = 4; }