public static bool Parse(SeekableReader r, out System system) { if (!Unit.Parse(r, out Unit? u)) { throw new InvalidSystemException("No core star"); } system = new System() { Core = u }; while (r.Peek() == ' ') { while (r.Peek() == ' ') // w+ { r.Read(); } if (!Companion.Parse(r, out Companion? companion) || companion == null) { throw new InvalidSystemException("Expected companion"); } system.Companions.Add(companion); } return(true); }
public static bool Parse(SeekableReader r, out System system) { Unit u; if (!Unit.Parse(r, out u)) { throw new InvalidSystemException("No core star"); } system = new System(); system.Core = u; while (r.Peek() == ' ') { while (r.Peek() == ' ') // w+ { r.Read(); } Companion companion; if (!Companion.Parse(r, out companion)) { throw new InvalidSystemException("Expected companion"); } system.Companions.Add(companion); } return(true); }
public static bool Parse(SeekableReader r, out FarCompanion far) { if (r.Peek() != '[') { far = null; return(false); } far = new FarCompanion(); r.Read(); // '[' if (!System.Parse(r, out far.Companion)) { throw new InvalidSystemException("Invalid far companion"); } if (r.Read() != ']') { throw new InvalidSystemException("Unclosed far companion"); } return(true); }
public static bool Parse(SeekableReader r, out Pair pair) { if (r.Peek() != '(') { pair = null; return(false); } pair = new Pair(); r.Read(); // "(" if (!Star.Parse(r, out pair.Star1)) { throw new InvalidSystemException("Invalid star within pair"); } if (r.Peek() != ' ') // w+ { throw new InvalidSystemException("Missing whitespace within pair"); } while (r.Peek() == ' ') { r.Read(); } if (!Star.Parse(r, out pair.Star2)) { throw new InvalidSystemException("Invalid star within pair"); } if (r.Read() != ')') { throw new InvalidSystemException("Unclosed pair"); } return(true); }
/// <summary> /// Match one of a set of string options. Will return one of the options or null /// if there is no match. /// </summary> /// <param name="r">Text to parse</param> /// <param name="options">List of accepted options</param> /// <returns>Matched string, or null</returns> private static string Match(SeekableReader r, string[] options) { string found = ""; int pos = r.Position; while (r.Peek() != -1 && IsPrefixIn(found + (char)r.Peek(), options)) { found += (char)r.Read(); } if (options.Any(o => found == o)) { return(found); } r.Position = pos; return(null); }
public static bool Parse(SeekableReader r, out Star star) { string m; m = Match(r, OTHER_TYPES); if (m != null) { // Brown Dwarf, Black Hole, Unknown star = new Star(); star.Type = m; return(true); } m = Match(r, STAR_TYPES); if (m != null) { // Regular star = new Star(); star.Type = m; if (r.Peek() == ' ') { while (r.Peek() == ' ') // w* { r.Read(); } if (Match(r, DWARF_SIZE) == null) { throw new InvalidSystemException("Invalid stellar type"); } star.Tenths = 0; star.Size = "D"; } else if (Match(r, DWARF_SIZE) != null) { star.Tenths = 0; star.Size = "D"; } else { m = Match(r, STAR_TENTHS); if (m == null) { throw new InvalidSystemException("Invalid stellar type"); } star.Tenths = (int)m[0] - (int)'0'; while (r.Peek() == ' ') // w* { r.Read(); } m = Match(r, STAR_SIZES); if (m == null) { throw new InvalidSystemException("Invalid stellar size"); } star.Size = m; } #if EXTENDED_SYSTEM_PARSING if (r.Peek() == '*') { r.Read(); star.Main = true; } #endif return(true); } m = Match(r, DWARF_TYPES); if (m != null) { // Dwarf star = new Star(); star.Type = m; return(true); } star = null; return(false); }
public static bool Parse( SeekableReader r, out FarCompanion far ) { if( r.Peek() != '[' ) { far = null; return false; } far = new FarCompanion(); r.Read(); // '[' if( !System.Parse(r, out far.Companion) ) throw new InvalidSystemException( "Invalid far companion" ); if( r.Read() != ']' ) throw new InvalidSystemException( "Unclosed far companion" ); return true; }
public static bool Parse( SeekableReader r, out Pair pair ) { if( r.Peek() != '(' ) { pair = null; return false; } pair = new Pair(); r.Read(); // "(" if( !Star.Parse( r, out pair.Star1 ) ) throw new InvalidSystemException( "Invalid star within pair" ); if( r.Peek() != ' ' ) // w+ throw new InvalidSystemException( "Missing whitespace within pair" ); while( r.Peek() == ' ' ) r.Read(); if( !Star.Parse( r, out pair.Star2 ) ) throw new InvalidSystemException( "Invalid star within pair" ); if( r.Read() != ')' ) throw new InvalidSystemException( "Unclosed pair" ); return true; }
public static bool Parse(SeekableReader r, out System system) { Unit u; if (!Unit.Parse(r, out u)) throw new InvalidSystemException("No core star"); system = new System(); system.Core = u; while (r.Peek() == ' ') { while (r.Peek() == ' ') // w+ r.Read(); Companion companion; if (!Companion.Parse(r, out companion)) throw new InvalidSystemException("Expected companion"); system.Companions.Add(companion); } return true; }
public static bool Parse(SeekableReader r, out Star star) { string m; m = Match(r, OTHER_TYPES); if (m != null) { // Brown Dwarf, Black Hole, Unknown star = new Star(); star.Type = m; return true; } m = Match(r, STAR_TYPES); if (m != null) { // Regular star = new Star(); star.Type = m; if (r.Peek() == ' ') { while (r.Peek() == ' ') // w* r.Read(); if (Match(r, DWARF_SIZE) == null) throw new InvalidSystemException("Invalid stellar type"); star.Tenths = 0; star.Size = "D"; } else if (Match(r, DWARF_SIZE) != null) { star.Tenths = 0; star.Size = "D"; } else { m = Match(r, STAR_TENTHS); if (m == null) throw new InvalidSystemException("Invalid stellar type"); star.Tenths = (int)m[0] - (int)'0'; while (r.Peek() == ' ') // w* r.Read(); m = Match(r, STAR_SIZES); if (m == null) throw new InvalidSystemException("Invalid stellar size"); star.Size = m; } #if EXTENDED_SYSTEM_PARSING if (r.Peek() == '*') { r.Read(); star.Main = true; } #endif return true; } m = Match(r, DWARF_TYPES); if (m != null) { // Dwarf star = new Star(); star.Type = m; return true; } star = null; return false; }
/// <summary> /// Match one of a set of string options. Will return one of the options or null /// if there is no match. /// </summary> /// <param name="r">Text to parse</param> /// <param name="options">List of accepted options</param> /// <returns>Matched string, or null</returns> private static string Match(SeekableReader r, string[] options) { string found = ""; int pos = r.Position; while (r.Peek() != -1 && IsPrefixIn(found + (char)r.Peek(), options)) { found += (char)r.Read(); } if (options.Any(o => found == o)) return found; r.Position = pos; return null; }