public static ReplaceSetToken Parse(Token parent, Scope scope, PreprocessorToken replaceToken) { #if DEBUG if (replaceToken == null) throw new ArgumentNullException("replaceToken"); #endif var file = scope.File; var startPos = replaceToken.Span.Start; var scopeIndent = scope.Indent(); var ret = new ReplaceSetToken(parent, scope, new Span(startPos, startPos)); ret._replaceToken = new ReplaceToken(ret, scope, replaceToken.Span, ret); ret._tokens.Add(ret._replaceToken); var done = false; while (!file.EndOfFile && !done) { var token = file.ParseToken(ret, scopeIndent); if (token == null) break; if (token.GetType() == typeof(PreprocessorToken)) { if ((token as PreprocessorToken).Text == "#with" && ret._withToken == null) { ret._withToken = new ReplaceToken(ret, scope, token.Span, ret); ret._tokens.Add(ret._withToken); } else if ((token as PreprocessorToken).Text == "#endreplace") { ret._endReplaceToken = new ReplaceToken(ret, scope, token.Span, ret); ret._tokens.Add(ret._endReplaceToken); done = true; } else { ret._tokens.Add(token); if (ret._withToken == null) ret._oldTokens.Add(token); else ret._newTokens.Add(token); } } else { ret._tokens.Add(token); if (ret._withToken == null) ret._oldTokens.Add(token); else ret._newTokens.Add(token); } } ret.Span = new Span(startPos, file.Position); return ret; }
public static Token Parse(Token parent, Scope scope, PreprocessorToken insertToken) { var ret = new InsertToken(parent, scope); var scopeIndent = scope.Indent(); var tokens = new List<Token>(); tokens.Add(ret._startToken = new InsertBoundaryToken(ret, scope, insertToken.Span, true)); while (true) { var token = scope.File.ParseToken(parent, scopeIndent); if (token == null) break; if (token.GetType() == typeof(PreprocessorToken) && token.Text == "#endinsert") { tokens.Add(ret._endToken = new InsertBoundaryToken(ret, scope, token.Span, false)); break; } else tokens.Add(token); } ret._tokens = tokens.ToArray(); ret.Span = new Span(ret._tokens.First().Span.Start, ret._tokens.Last().Span.End); return ret; }