public void Load(string file_contents) { AllItems = new List <TextLine>(); foreach (var line in file_contents.Split(ENV.SEP_LINES, STR.SPL_NONE)) { TextLine n = null; var trimmed = line.Trim(); if (trimmed == "") { n = new BlankLine(); } else if (trimmed.StartsWith(";")) { n = new CommentLine(); } else { n = new TLine(); } n.Load(line); AllItems.Add(n); } }
private static bool GetCommandLineParts(string line, out string foundLabel, out OpCode opCode, out string operandPart, out string comment, out Command errorCommand) { errorCommand = null; var hasLabel = line[0] != ' ' && line[0] != '\t'; var commentSplit = line.Split(';').ToList(); var withoutComment = commentSplit[0]; comment = commentSplit.Count() > 1 ? commentSplit[1].Trim() : string.Empty; var rx = new Regex(@"\s+", RegexOptions.Compiled); var parts = rx.Split(withoutComment).Where(s => !string.IsNullOrWhiteSpace(s)).ToList(); foundLabel = null; if (hasLabel) { foundLabel = parts.First().TrimEnd(':'); parts = parts.Skip(1).ToList(); if (!parts.Any()) { errorCommand = new BlankLine(withoutComment); errorCommand.SetLabel(foundLabel); opCode = OpCode.INVALID; operandPart = null; return(false); } } if (!Enum.TryParse <OpCode>(parts[0], ignoreCase: true, result: out opCode)) { errorCommand = new UnparsableLine(withoutComment, "Invalid OpCode"); operandPart = null; return(false); } operandPart = string.Join("", parts.Skip(1)); return(true); }
public object Visit(BlankLine special, object data) { if (!specialHasBeenHandled(special)) { formatter.PrintBlankLine(ForceWriteInPreviousLine); considerSpecialAsHandled(special); } return(data); }
public void Write(StringBuilder builder, BlankLine blankLine) { if (builder == null || blankLine == null) { return; } Write(builder, BlankLine.Pattern); }
private static IniItem TryCreateBlankLine(string line) { if (line.Trim().Length == 0) { var blankLine = new BlankLine(); blankLine.Padding.Left = line.Length; return(blankLine); } return(null); }
/// <summary> /// Creates a new instance of <see cref="BlockElement"/>. /// Its type will be determined with the specified first line. /// </summary> /// <param name="line">The line which is the first line of the block.</param> /// <param name="currentIndent">The indent count of <paramref name="line"/>.</param> /// <param name="config">Configuration of the parser.</param> /// <param name="createListItem"> /// Creates a <see cref="ListItem"/> instead of <see cref="ListBlock"/> when <c>true</c> is specified. /// </param> /// <returns>The new element that the type corresponds to <paramref name="line"/>.</returns> public static BlockElement CreateBlockFromLine(string line, int currentIndent, ParserConfig config, bool createListItem = false) { if (IndentedCodeBlock.CanStartBlock(line, currentIndent)) { return(new IndentedCodeBlock(config)); } if (ThematicBreak.CanStartBlock(line, currentIndent)) { return(new ThematicBreak(config)); } if (AtxHeading.CanStartBlock(line, currentIndent)) { return(new AtxHeading(config)); } if (FencedCodeBlock.CanStartBlock(line, currentIndent)) { return(new FencedCodeBlock(config)); } if (HtmlBlock.CanStartBlock(line, currentIndent)) { return(new HtmlBlock(config)); } if (BlockQuote.CanStartBlock(line, currentIndent)) { return(new BlockQuote(config)); } if (ListBlock.CanStartBlock(line, currentIndent)) { return(createListItem ? (BlockElement) new ListItem(config) : new ListBlock(config)); } if (BlankLine.CanStartBlock(line)) { return(new BlankLine(config)); } return(new UnknownElement(config)); }
public static List <int> GetBlankLiens(VSTextView textView) { List <int> lines = new List <int>(); using (IParser parser = ParserFactory.CreateParser(SupportedLanguage.CSharp, new StringReader(textView.GetWholeText()))) { parser.ParseMethodBodies = false; parser.Parse(); List <ISpecial> currentSpecials = parser.Lexer.SpecialTracker.CurrentSpecials; TextSpan textSpan = new TextSpan(); foreach (ISpecial currentSpecial in currentSpecials) { if (currentSpecial is BlankLine) { BlankLine region = currentSpecial as BlankLine; lines.Add(region.StartPosition.Line - 1); } } } return(lines); }
public object Visit(BlankLine special, object data) { formatter.PrintBlankLine(ForceWriteInPreviousLine); return(data); }
public object Visit(BlankLine special, object data) { formatter.PrintBlankLine(ForceWriteInPreviousLine); return data; }
object ISpecialVisitor.Visit(BlankLine special, object data) { WriteSpecialText(false, ""); return(null); }
public object Visit(BlankLine special, object data) { formatter.NewLine(); return(data); }
/// <summary> /// 添加电路图中的元件,并设置其位置 /// </summary> private void drawGraph(ISet <ShortBranchNode> brs, bool left, bool right) { //绘制并联电路的封闭垂线 if (view.Type) { ISet <ShortBranchNode> total = DigraphBuilder.expandBranch(brs); foreach (ShortBranchNode node in view.LabelToBranch.Values) { if (node == null || node.EndName == "GND" || node.EndName == "DC110V") { continue; } var filterNodes = total.Where(p => node.EndName == p.EndName).ToList(); if (filterNodes.Count == 0 || filterNodes.Count == 1) { continue; } double max = filterNodes.Max(p => p.Uis[p.Uis.Count - 1].Pos.Y); double min = filterNodes.Min(p => p.Uis[p.Uis.Count - 1].Pos.Y); INotifyComponentChanged info = node.Nodes.First().Uis[node.Nodes.First().Uis.Count - 1].Info; INotifyComponentChanged cpinfo = info.clone(); view.Observer.addListener(cpinfo); VerticalLine line = new VerticalLine(cpinfo); line.setLineLength((max - min) * 60); ShortBranchNode brnode = filterNodes.FirstOrDefault(p => p.Uis[p.Uis.Count - 1].Pos.Y == min); Canvas.SetLeft(line, DigraphBuilder.START_POS.X + brnode.Uis[brnode.Uis.Count - 1].Pos.X * 150 + 150); Canvas.SetTop(line, DigraphBuilder.START_POS.Y + brnode.Uis[0].Pos.Y * 60 + 37.5); map.Children.Add(line); } } //总正垂线 if (left) { Line line = new Line(); line.Stroke = Brushes.Black; line.StrokeThickness = 1; line.X1 = 0; line.Y1 = 0; line.X2 = 0; line.Y2 = (brs.Last().Uis[0].Pos.Y - brs.First().Uis[0].Pos.Y) * 60; Canvas.SetLeft(line, DigraphBuilder.START_POS.X + brs.First().Uis[0].Pos.X * 150); Canvas.SetTop(line, DigraphBuilder.START_POS.Y + brs.First().Uis[0].Pos.Y * 60 + 37.5); map.Children.Add(line); } /*核心元器件*/ List <TNodeUI> uis = new List <TNodeUI>(); double widthMax = 0, heightMax = 0; double miny = double.MaxValue, maxy = double.MinValue, maxx = double.MinValue; ISet <ShortBranchNode> branchs = new HashSet <ShortBranchNode>(brs); while (branchs.Count != 0) { ISet <ShortBranchNode> temp = new HashSet <ShortBranchNode>(); foreach (ShortBranchNode brNode in branchs) { foreach (ShortBranchNode child in brNode.Nodes) { temp.Add(child); } if (brNode.Nodes.Count == 0) { if (brNode.Uis[0].Pos.Y < miny) { miny = brNode.Uis[0].Pos.Y; } if (brNode.Uis[0].Pos.Y > maxy) { maxy = brNode.Uis[0].Pos.Y; } if (brNode.Uis.Last().Pos.X > maxx) { maxx = brNode.Uis.Last().Pos.X; } if (brNode.EndName == "GND") { uis.Add(brNode.Uis.Last()); } } foreach (TNodeUI ui in brNode.Uis) { UIElement ele = BranchFactory.convert(ui); map.Children.Add(ele); ElectricAnalysis.Graph.Point realPos = ui.RealPos; Canvas.SetLeft(ele, realPos.X); Canvas.SetTop(ele, realPos.Y); if (DigraphBuilder.START_POS.X + ui.Pos.X * 150 > widthMax) { widthMax = DigraphBuilder.START_POS.X + ui.Pos.X * 150; } if (DigraphBuilder.START_POS.Y + ui.Pos.Y * 60 > heightMax) { heightMax = DigraphBuilder.START_POS.Y + ui.Pos.Y * 60; } } //绘垂线 if (brNode.Nodes.Count > 1) { INotifyComponentChanged cpinfo = brNode.Uis[brNode.Uis.Count - 1].Info.clone(); view.Observer.addListener(cpinfo); VerticalLine line = new VerticalLine(cpinfo); line.setLineLength((brNode.Nodes.Last().Uis[0].Pos.Y - brNode.Nodes.First().Uis[0].Pos.Y) * 60); Canvas.SetLeft(line, DigraphBuilder.START_POS.X + brNode.Nodes.First().Uis[0].Pos.X * 150); Canvas.SetTop(line, DigraphBuilder.START_POS.Y + brNode.Nodes.First().Uis[0].Pos.Y * 60 + 37.5); map.Children.Add(line); } } branchs = temp; } outerBd.Width = widthMax + 250; outerBd.Height = heightMax + 150; //总负垂线 if (right) { Line line = new Line(); line.Stroke = Brushes.Black; line.StrokeThickness = 1; line.X1 = 0; line.Y1 = 0; line.X2 = 0; line.Y2 = (maxy - miny) * 60; Canvas.SetLeft(line, widthMax + 150); Canvas.SetTop(line, DigraphBuilder.START_POS.Y + brs.First().Uis[0].Pos.Y * 60 + 37.5); map.Children.Add(line); foreach (TNodeUI ui in uis) { for (double i = ui.Pos.X + 1; i <= maxx; i++) { BlankLine bk = new BlankLine(ui.Info); map.Children.Add(bk); Canvas.SetLeft(bk, DigraphBuilder.START_POS.X + i * 150); Canvas.SetTop(bk, DigraphBuilder.START_POS.Y + ui.Pos.Y * 60); } } } }
public static UIElement convert(TNodeUI node) { UIElement rst = null; switch (node.Info.CptType) { case ComponentType.Terminal: { rst = new Terminal(node.Info); break; } case ComponentType.Switch: { rst = new Switch(node.Info); break; } case ComponentType.Resistance: { rst = new Resistance(node.Info); break; } case ComponentType.Indicator: { rst = new Indicator(node.Info); break; } case ComponentType.Diode: { rst = new Diode(node.Info, node.Reverse); break; } case ComponentType.ContactClose: case ComponentType.ContactOpen: { rst = new StandardContact(node.Info); break; } case ComponentType.Coil: { rst = new Coil(node.Info); break; } case ComponentType.Capacitance: { rst = new Capacitance(node.Info); break; } case ComponentType.Breaker: { rst = new Breaker(node.Info); break; } case ComponentType.Blank: { rst = new BlankLine(node.Info); break; } } return(rst); }