예제 #1
0
		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();
		}
예제 #2
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
				PrintNodeBeg(PegNode p, bool bAlignVertical, ref int nOffsetLineBeg, int nLevel)
		{
			PrintIdAsName(p);
			treeOut_.Write("<");
			if (bAlignVertical)
			{
				treeOut_.WriteLine();
				treeOut_.Write(new string(' ', nOffsetLineBeg += 2));
			}
			else
			{
				++nOffsetLineBeg;
			}
		}
예제 #3
0
			private void HandleEscSeq3(PegNode node, StyleContext context, StructuralGlyph parent)
			{
				int posBeg = node.match_.posBeg_;
				var childNode = node.child_;

				if (childNode == null)
					throw new ArgumentNullException("childNode");

				string escHeader = _sourceText.Substring(posBeg, childNode.match_.posBeg_ - posBeg);

				switch (escHeader.ToLowerInvariant())
				{
					case @"\%(":
						{
							string s1 = GetText(childNode);
							string s2 = GetText(childNode.next_);
							string s3 = GetText(childNode.next_.next_);
							int plotNumber, plotLayer;
							if (int.TryParse(s1, out plotLayer) && int.TryParse(s2, out plotNumber))
							{
								var label = new PlotName(context, plotNumber, plotLayer);
								label.SetPropertyColumnName(s3);
								parent.Add(label);
							}
						}
						break;
				}
			}
예제 #4
0
			private void HandleEscSeq1(PegNode node, StyleContext context, StructuralGlyph parent)
			{
				int posBeg = node.match_.posBeg_;
				var childNode = node.child_;

				if (childNode == null)
					throw new ArgumentNullException("childNode");

				string escHeader = _sourceText.Substring(posBeg, childNode.match_.posBeg_ - posBeg);

				switch (escHeader.ToLowerInvariant())
				{
					case @"\id(":
						{
							const string DefPropertyHead = "$Property[\"";
							const string DefPropertyTail = "\"]";

							string s = GetText(childNode).Trim();
							if (s == "$DI")
							{
								parent.Add(new DocumentIdentifier(context));
							}
							else if (s.StartsWith(DefPropertyHead) && s.EndsWith(DefPropertyTail))
							{
								string propertyName = s.Substring(DefPropertyHead.Length, s.Length - DefPropertyHead.Length - DefPropertyTail.Length);
								if (!string.IsNullOrEmpty(propertyName))
									parent.Add(new ValueOfProperty(context, propertyName));
							}
						}
						break;

					case @"\g(":
						{
							var newContext = context.Clone();
							newContext.SetFont(context.FontId.WithFamily("Symbol"));
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\i(":
						{
							var newContext = context.Clone();
							newContext.MergeFontStyle(FontXStyle.Italic);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\b(":
						{
							var newContext = context.Clone();
							newContext.MergeFontStyle(FontXStyle.Bold);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\u(":
						{
							var newContext = context.Clone();
							newContext.MergeFontStyle(FontXStyle.Underline);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\s(":
						{
							var newContext = context.Clone();
							newContext.MergeFontStyle(FontXStyle.Strikeout);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\n(":
						{
							var newContext = context.Clone();
							newContext.SetFontStyle(FontXStyle.Regular);
							VisitNode(childNode, newContext, parent);
						}
						break;

					case @"\+(":
						{
							var newParent = new Superscript();
							newParent.Style = context;
							parent.Add(newParent);

							var newContext = context.Clone();
							newContext.ScaleFont(0.65);
							VisitNode(childNode, newContext, newParent);
						}
						break;

					case @"\-(":
						{
							var newParent = new Subscript();
							newParent.Style = context;
							parent.Add(newParent);

							var newContext = context.Clone();
							newContext.ScaleFont(0.65);
							VisitNode(childNode, newContext, newParent);
						}
						break;

					case @"\l(":
						{
							string s = GetText(childNode);
							int plotNumber;
							if (int.TryParse(s, out plotNumber))
							{
								parent.Add(new PlotSymbol(context, plotNumber));
							}
						}
						break;

					case @"\%(":
						{
							string s = GetText(childNode);
							int plotNumber;
							if (int.TryParse(s, out plotNumber))
							{
								parent.Add(new PlotName(context, plotNumber));
							}
						}
						break;

					case @"\ad(":
						{
							var newParent = new DotOverGlyph();
							newParent.Style = context;
							parent.Add(newParent);
							VisitNode(childNode, context, newParent);
						}
						break;

					case @"\ab(":
						{
							var newParent = new BarOverGlyph();
							newParent.Style = context;
							parent.Add(newParent);
							VisitNode(childNode, context, newParent);
						}
						break;
				}
			}
예제 #5
0
			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);
				}
			}
예제 #6
0
			private StructuralGlyph VisitNode(PegNode node, StyleContext context, StructuralGlyph parent)
			{
				StructuralGlyph nextparent = parent;

				switch ((EAltaxo_LabelV1)node.id_)
				{
					case EAltaxo_LabelV1.WordSpan:
					case EAltaxo_LabelV1.WordSpanExt:
					case EAltaxo_LabelV1.WordSpanNC:
						HandleWordSpan(node, context, parent);
						break;

					case EAltaxo_LabelV1.Sentence:
					case EAltaxo_LabelV1.SentenceNC:
						HandleSentence(node, context, parent);
						break;

					case EAltaxo_LabelV1.Space:
						nextparent = HandleSpace(node, context, parent);
						break;

					case EAltaxo_LabelV1.EscSeq1:
						HandleEscSeq1(node, context, parent);
						break;

					case EAltaxo_LabelV1.EscSeq2:
						HandleEscSeq2(node, context, parent);
						break;

					case EAltaxo_LabelV1.EscSeq3:
						HandleEscSeq3(node, context, parent);
						break;
				}

				if (null != node.next_)
					nextparent = VisitNode(node.next_, context, nextparent);

				return nextparent;
			}
예제 #7
0
		private IMultiRenameElement HandleEscBracket(PegNode node)
		{
			return new MultiRenameLiteralElement("[");
		}
예제 #8
0
		private string GetEscStringText(PegNode node)
		{
			return TransformToLiteral(GetText(node));
		}
예제 #9
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
				PrintDistNext(PegNode p, bool bAlignVertical, ref int nOffsetLineBeg, int nLevel)
		{
			if (bAlignVertical)
			{
				treeOut_.WriteLine();
				treeOut_.Write(new string(' ', nOffsetLineBeg));
			}
			else
			{
				treeOut_.Write(' ');
				++nOffsetLineBeg;
			}
		}
예제 #10
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
		public override bool IsLeaf(PegNode p)
		{
			return p.child_ == null;
		}
예제 #11
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
		public override int LenLeaf(PegNode p)
		{
			int nLen = p.match_.posEnd_ - p.match_.posBeg_ + 2;
			if (bVerbose_) nLen += LenIdAsName(p) + 2;
			return nLen;
		}
예제 #12
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
		public override void PrintLeaf(PegNode p, ref int nOffsetLineBeg, bool bAlignVertical)
		{
			if (bVerbose_)
			{
				PrintIdAsName(p);
				treeOut_.Write('<');
			}
			int len = p.match_.posEnd_ - p.match_.posBeg_;
			treeOut_.Write("'");
			if (len > 0)
			{
				treeOut_.Write(src_.Substring(p.match_.posBeg_, p.match_.posEnd_ - p.match_.posBeg_));
			}
			treeOut_.Write("'");
			if (bVerbose_) treeOut_.Write('>');
		}
예제 #13
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
		public override int LenNodeEnd(PegNode p)
		{
			return 1;
		}
예제 #14
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
		public override int LenNodeBeg(PegNode p)
		{
			return LenIdAsName(p) + 1;
		}
예제 #15
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
				PrintNodeEnd(PegNode p, bool bAlignVertical, ref int nOffsetLineBeg, int nLevel)
		{
			if (bAlignVertical)
			{
				treeOut_.WriteLine();
				treeOut_.Write(new string(' ', nOffsetLineBeg -= 2));
			}
			treeOut_.Write('>');
			if (!bAlignVertical)
			{
				++nOffsetLineBeg;
			}
		}
예제 #16
0
		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);
		}
예제 #17
0
		private IMultiRenameElement HandleArrayTemplate(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;
			string separator = "\\";

			while (null != (childNode = childNode.next_))
			{
				switch (childNode.id_)
				{
					case (int)EAltaxo_MultiRename.StringContent:
						separator = GetEscStringText(childNode);
						break;

					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 MultiRenameArrayElement(_renameData, shortCut, start, last, separator);
		}
예제 #18
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
				LenDistNext(PegNode p, bool bAlignVertical, ref int nOffsetLineBeg, int nLevel)
		{
			return 1;
		}
예제 #19
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
		private int LenIdAsName(PegNode p)
		{
			string name = GetNodeName_(p);
			return name.Length;
		}
예제 #20
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
		private void PrintIdAsName(PegNode p)
		{
			string name = GetNodeName_(p);
			treeOut_.Write(name);
		}
예제 #21
0
			public StructuralGlyph VisitTree(PegNode root, StyleContext context, double lineSpacingFactor, bool isFixedLineSpacing)
			{
				var rootGlyph = new VerticalStack();
				rootGlyph.Style = context;
				rootGlyph.LineSpacingFactor = lineSpacingFactor;
				rootGlyph.FixedLineSpacing = isFixedLineSpacing;

				var line = new GlyphLine();
				line.Style = context;

				rootGlyph.Add(line);

				if (null != root && null != root.child_)
					VisitNode(root.child_, context, line);

				return rootGlyph;
			}
예제 #22
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
		protected PegNode DefaultNodeCreator(ECreatorPhase phase, PegNode parentOrCreated, int id)
		{
			if (phase == ECreatorPhase.eCreate || phase == ECreatorPhase.eCreateAndComplete)
				return new PegNode(parentOrCreated, id);
			else return null;
		}
예제 #23
0
			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));
			}
예제 #24
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
		private void RestoreTree(PegNode prevCur, PegTree.AddPolicy prevPolicy)
		{
			if (bMute_) return;
			if (prevCur == null)
			{
				tree.root_ = null;
			}
			else if (prevPolicy == PegTree.AddPolicy.eAddAsChild)
			{
				prevCur.child_ = null;
			}
			else
			{
				prevCur.next_ = null;
			}
			tree.cur_ = prevCur;
			tree.addPolicy = prevPolicy;
		}
예제 #25
0
			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);
			}
예제 #26
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
		public virtual string TreeNodeToString(PegNode node)
		{
			return GetRuleNameFromId(node.id_);
		}
예제 #27
0
			private void HandleEscSeq2(PegNode node, StyleContext context, StructuralGlyph parent)
			{
				int posBeg = node.match_.posBeg_;
				var childNode = node.child_;

				if (childNode == null)
					throw new ArgumentNullException("childNode");

				string escHeader = _sourceText.Substring(posBeg, childNode.match_.posBeg_ - posBeg);

				switch (escHeader.ToLowerInvariant())
				{
					case @"\=(":
						{
							var newParent = new SubSuperScript();
							newParent.Style = context;
							parent.Add(newParent);

							var newContext = context.Clone();
							newContext.ScaleFont(0.65);
							VisitNode(childNode, newContext, newParent);
						}
						break;

					case @"\p(":
						{
							double val;
							string s1 = GetText(childNode).Trim();
							var newContext = context.Clone();
							string numberString;
							Altaxo.Serialization.LengthUnit lengthUnit;

							if (s1.EndsWith("%"))
							{
								numberString = s1.Substring(0, s1.Length - 1);
								if (double.TryParse(numberString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val))
								{
									newContext.BaseFontId = context.BaseFontId.WithSize(context.BaseFontId.Size * val / 100);
									newContext.ScaleFont(val / 100);
								}
							}
							else if (Altaxo.Serialization.LengthUnit.TryParse(s1, out lengthUnit, out numberString) &&
								double.TryParse(numberString, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val)
								)
							{
								double newSize = val * (double)(lengthUnit.UnitInMeter / Altaxo.Serialization.LengthUnit.Point.UnitInMeter);
								newContext.BaseFontId = context.BaseFontId.WithSize(newSize);
								newContext.FontId = context.FontId.WithSize(newSize);
							}
							else if (double.TryParse(s1, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out val)
								)
							{
								double newSize = val;
								newContext.BaseFontId = context.BaseFontId.WithSize(newSize);
								newContext.FontId = context.FontId.WithSize(newSize);
							}
							VisitNode(childNode.next_, newContext, parent);
						}
						break;

					case @"\c(":
						{
							string s1 = GetText(childNode).Trim();
							var newContext = context.Clone();
							var conv = new ColorConverter();

							try
							{
								object result = conv.ConvertFromInvariantString(s1);
								newContext.brush = new SolidBrush((Color)result);
							}
							catch (Exception)
							{
							}

							VisitNode(childNode.next_, newContext, parent);
						}
						break;

					case @"\l(":
						{
							string s1 = GetText(childNode);
							string s2 = GetText(childNode.next_);
							int plotNumber, plotLayer;
							if (int.TryParse(s1, out plotLayer) && int.TryParse(s2, out plotNumber))
							{
								parent.Add(new PlotSymbol(context, plotNumber, plotLayer));
							}
						}
						break;

					case @"\%(":
						{
							string s1 = GetText(childNode);
							string s2 = GetText(childNode.next_);
							int plotNumber, plotLayer;
							if (int.TryParse(s1, out plotLayer) && int.TryParse(s2, out plotNumber))
							{
								parent.Add(new PlotName(context, plotNumber, plotLayer));
							}
							else if (int.TryParse(s1, out plotNumber))
							{
								var label = new PlotName(context, plotNumber);
								label.SetPropertyColumnName(s2);
								parent.Add(label);
							}
						}
						break;
				}
			}
예제 #28
0
		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);
		}
예제 #29
0
			private string GetText(PegNode node)
			{
				return _sourceText.Substring(node.match_.posBeg_, node.match_.Length);
			}
예제 #30
0
파일: PegBase.cs 프로젝트: Altaxo/Altaxo
		private int DetermineLineLength(PegNode parent, int nOffsetLineBeg)
		{
			int nLen = LenNodeBeg(parent);
			PegNode p;
			for (p = parent.child_; p != null; p = p.next_)
			{
				if (IsSkip(p)) continue;
				if (IsLeaf(p))
				{
					nLen += LenLeaf(p);
				}
				else
				{
					nLen += DetermineLineLength(p, nOffsetLineBeg);
				}
				if (nLen + nOffsetLineBeg > LenMaxLine())
				{
					return nLen + nOffsetLineBeg;
				}
			}
			nLen += LenNodeEnd(p);
			return nLen;
		}