public static sym_drawing_base Parse(List <Token> tokens) { sym_drawing_base result = null; switch (tokens[0].Value) { case "S": result = sym_rectangle.Parse(tokens); break; case "X": result = sym_pin.Parse(tokens); break; case "T": result = sym_text.Parse(tokens); break; case "P": result = sym_polygon.Parse(tokens); break; case "C": result = sym_circle.Parse(tokens); break; case "A": result = sym_arc.Parse(tokens); break; default: Console.WriteLine("unknown {0}", tokens[0].Value); result = null; break; } return(result); }
public static Symbol Parse(List <string> lines) { int index = 0; Symbol sym = new Symbol(); List <Token> tokens; // DEF AT89C2051-P IC 0 40 Y Y 1 F N while ((index < lines.Count) && (lines[index].StartsWith("#"))) { index++; } tokens = Utils.Tokenise(lines[index]); sym.Name = tokens[1].Value; sym.Visible = true; if (sym.Name.StartsWith("~")) { sym.Visible = false; sym.Name = sym.Name.Substring(1); } sym.Reference = tokens[2].Value; // param 3 is always 0 sym.Offset = tokens[4].IntValue; sym.ShowPinNumber = tokens[5].Value == "Y"; sym.ShowPinName = tokens[6].Value == "Y"; sym.NumUnits = tokens[7].IntValue; sym.Locked = tokens[8].Value == "L"; sym.PowerSymbol = tokens[9].Value == "P"; index++; // while ((index < lines.Count) && (lines[index] != "DRAW")) { tokens = Utils.Tokenise(lines[index]); if (tokens[0].Value.StartsWith("F")) { SymbolField text = SymbolField.Parse(tokens); switch (tokens[0].Value) { case "F0": sym.fReference = text; break; case "F1": sym.fValue = text; break; case "F2": sym.fPcbFootprint = text; break; case "F3": sym.fUserDocLink = text; break; default: { int field_index; if (int.TryParse(tokens[0].Value.Substring(1), out field_index)) { text.Index = field_index; sym.UserFields.Add(text); } } break; } index++; } else if (tokens[0].Value == "ALIAS") { for (int j = 1; j < tokens.Count; j++) { sym.Alias.Add(tokens[j].Value); } index++; } else if (tokens[0].Value == "$FPLIST") { index++; sym.Footprints = new List <string>(); while ((index < lines.Count) && (lines[index] != "$ENDFPLIST")) { sym.Footprints.Add(lines[index].Trim()); index++; } if ((index < lines.Count) && (lines[index] == "$ENDFPLIST")) { index++; } } else { // unknown? index++; } } if ((index < lines.Count) && (lines[index] == "DRAW")) { index++; while ((index < lines.Count) && (lines[index] != "ENDDRAW")) { tokens = Utils.Tokenise(lines[index]); if ((tokens[0].Value == "X") && (tokens.Count != 12)) { if ((tokens.Count == 13) && (tokens[11].Type == TokenType.Name)) { sym_drawing_base drawing = sym_drawing_base.Parse(tokens); if (drawing != null) { sym.Drawings.Add(drawing); } } else { Console.WriteLine("{0} invalid pin def {1}:{2}", sym.Name, index, lines[index]); } } else { sym_drawing_base drawing = sym_drawing_base.Parse(tokens); if (drawing != null) { sym.Drawings.Add(drawing); } } // todo: index++; } if ((index < lines.Count) && (lines[index] == "ENDDRAW")) { index++; } } // DRAW // expecting ENDDEF if ((index < lines.Count) && (lines[index] == "ENDDEF")) { index++; } return(sym); }