public _PC GetLookAhead(bool start) { _PC result = this.GetLookAhead(); if (start) { result.EnsureStarted(); } return(result); }
static CodeStatementCollection _ParseStatements(_PC pc, bool includeComments = false) { var result = new CodeStatementCollection(); pc.EnsureStarted(); while (!pc.IsEnded && ST.rbrace != pc.SymbolId) { result.Add(_ParseStatement(pc, includeComments)); } return(result); }
/// <summary> /// Parses a <see cref="CodeTypeDeclaration"/> from the specified input /// </summary> /// <param name="input">The input to parse</param> /// <returns>A <see cref="CodeTypeDeclaration"/> representing the parsed code</returns> public static CodeTypeDeclaration ParseType(IEnumerable <char> input) { using (var e = new ST(input).GetEnumerator()) { var pc = new _PC(e); pc.EnsureStarted(); var result = _ParseType(pc); if (!pc.IsEnded) { throw new ArgumentException("Unrecognized remainder in type declaration", "input"); } return(result); } }
/// <summary> /// Parses a <see cref="CodeStatement"/> from the specified input /// </summary> /// <param name="input">The input to parse</param> /// <param name="includeComments">True to return parsed comments as statements, or false to skip them</param> /// <returns>A <see cref="CodeStatement"/> representing the parsed code</returns> public static CodeStatement ParseStatement(IEnumerable <char> input, bool includeComments = false) { using (var e = new ST(input).GetEnumerator()) { var pc = new _PC(e); pc.EnsureStarted(); var result = _ParseStatement(pc, includeComments); if (!pc.IsEnded) { throw new ArgumentException("Unrecognized remainder in statement", "input"); } return(result); } }
/// <summary> /// Parses a <see cref="CodeCompileUnit"/> from the specified input /// </summary> /// <param name="input">The input to parse</param> /// <returns>A <see cref="CodeCompileUnit"/> representing the parsed code</returns> public static CodeCompileUnit ParseCompileUnit(IEnumerable <char> input) { using (var e = new ST(input).GetEnumerator()) { var pc = new _PC(e); pc.EnsureStarted(); var result = _ParseCompileUnit(pc); // should never happen if (!pc.IsEnded) { throw new ArgumentException("Unrecognized remainder in namespace", "input"); } return(result); } }
static KeyValuePair <CodeTypeReference, string> _ParsePrivateImplementationType(_PC pc) { // i really hate this routine _SkipComments(pc); CodeTypeReference ptr = null; string name = null; _PC pc2 = pc.GetLookAhead(); pc2.EnsureStarted(); try { ptr = _ParseTypeRef(pc2, true); } catch { ptr = null; } if (ptr != null) { if (ST.dot == pc2.SymbolId) // we didn't finish parsing the next field. This is probably what we wanted to begin with so yay { _ParseTypeRef(pc); pc.Advance(); _SkipComments(pc); if (pc.IsEnded) { throw new ArgumentException("Unterminated private member declaration"); } var s = pc.Value; pc.Advance(); return(new KeyValuePair <CodeTypeReference, string>(ptr, s)); } // HACK: it will have parsed the name as part of the typeref, so we just trim it off. var idx = ptr.BaseType.LastIndexOfAny(new char[] { '.', '+' }); if (0 > idx) { pc.Advance(); if (ST.dot != pc.SymbolId) { // the entire thing is the name. There is no private implementation type if (0 < ptr.TypeArguments.Count) { throw new ArgumentException("Missing member name on private member declaration", "input"); } return(new KeyValuePair <CodeTypeReference, string>(null, ptr.BaseType)); } else // this is probably a "this" { pc.Advance(); _SkipComments(pc); if (ST.keyword == pc.SymbolId && "this" == pc.Value) { pc.Advance(); return(new KeyValuePair <CodeTypeReference, string>(ptr, "this")); } throw new ArgumentException("Illegal private member implementation type.", "input"); } } name = ptr.BaseType.Substring(idx + 1); ptr.BaseType = ptr.BaseType.Substring(0, idx); _ParseTypeRef(pc, false); // advance return(new KeyValuePair <CodeTypeReference, string>(ptr, name)); } var n = pc.Value; pc.Advance(); return(new KeyValuePair <CodeTypeReference, string>(null, n)); //throw new ArgumentException("Expecting identifier on private member declaration", "input"); }