public static Ast.ComplexString ParseComplexString(TokenStream Stream, ParseContext Context) { System.Diagnostics.Debug.Assert(Stream.Next().Type == TokenType.Dollar); var start = Stream.Next(); Stream.PushState(TokenStreamState.ComplexString); //Enter complex string parsing mode Stream.Advance(); if (Stream.Next().Type != TokenType.ComplexStringQuote) throw new CompileError("[015] Expected \"", Stream); Stream.Advance(); var stringPieces = new List<Ast.Node>(); while (Stream.Next().Type != TokenType.ComplexStringQuote) { if (Stream.Next().Type == TokenType.ComplexStringPart) { stringPieces.Add(new Ast.StringLiteral(Stream.Next(), Stream.Next().Value)); Stream.Advance(); } else if (Stream.Next().Type == TokenType.OpenBracket) { Stream.PushState(TokenStreamState.Normal); //Make sure we are parsing normally for the Stream.Advance(); //Skip the [ //embedded expression stringPieces.Add(ParseExpression(Stream, Context, TokenType.CloseBracket)); if (Stream.Next().Type != TokenType.CloseBracket) //Shouldn't be possible throw new CompileError("[016] Expected ]", Stream); Stream.PopState(); //Return to complex string parsing mode Stream.Advance(); } else throw new InvalidProgramException(); } Stream.PopState(); //Return to normal parsing mode Stream.Advance(); return new Ast.ComplexString(start, stringPieces); }