void IASTElementGeneratesDebugXML.GenerateDebugXMLTree(IASTElement parent, StringBuilder output) { output.Append("<Liturgy>"); foreach (var line in Lines) { ((IASTElementGeneratesDebugXML)line).GenerateDebugXMLTree(this, output); } output.Append("</Liturgy>"); }
void IASTElementGeneratesDebugXML.GenerateDebugXMLTree(IASTElement parent, StringBuilder output) { output.Append("<ASTProgram>"); foreach (var child in Children) { child.GenerateDebugXMLTree(this, output); } output.Append("</ASTProgram>"); }
IASTElement IParsable.Parse(Lexer lexer, IASTElement parent) { while (!lexer.InspectEOF()) { lexer.GobbleWhitespace(); // find a valid command IASTElement cmd = new ASTCommand(); Children.Add(cmd.Parse(lexer, this)); lexer.GobbleWhitespace(); } return(this); }
void IASTElementGeneratesDebugXML.GenerateDebugXMLTree(IASTElement parent, StringBuilder output) { output.Append($"<ASTLiturgyLine Speaker=\"{Speaker}\" SpeakerText=\"{SpeakerText}\">"); foreach (var word in Words) { output.Append($"<Word Format=\"{word.Format}\" Value=\"{word.Value}\">"); foreach (var kvp in word.Attributes) { output.Append($"<Attribute Name=\"{kvp.Key}\" Value=\"{kvp.Value}\"/>"); } output.Append($"</Word>"); } output.Append("</ASTLiturgyLine>"); }
IASTElement IParsable.Parse(Lexer lexer, IASTElement parent) { /* * Figure out what command it is * Parse the actual command */ lexer.GobbleWhitespace(); CommandName = lexer.Peek(); if (CommandName.Value == "Liturgy" && !CommandName.IsEscaped) { Command = new ASTLiturgy_cmd(); Command.Parse(lexer, this); return(this); } else { // unrecognized sequence throw new MidnightCompilerParseError(lexer.CurrenToken, $"[Compiler Error] Error parsing 'Command'. Unrecognized command {lexer.CurrenToken.Value} at Line: {lexer.CurrenToken.LineNumber} on Col: {lexer.CurrenToken.SColNumber}"); } }
IASTElement IParsable.Parse(Lexer lexer, IASTElement parent) { if (!lexer.Consume("Liturgy")) { throw new MidnightCompilerParseError(lexer.CurrenToken, string.Join(Environment.NewLine, lexer.Messages)); } lexer.GobbleWhitespace(); if (!lexer.Consume("(")) { throw new MidnightCompilerParseError(lexer.CurrenToken, string.Join(Environment.NewLine, lexer.Messages)); } lexer.GobbleWhitespace(); if (!lexer.Consume(")")) { throw new MidnightCompilerParseError(lexer.CurrenToken, string.Join(Environment.NewLine, lexer.Messages)); } lexer.GobbleWhitespace(); if (!lexer.Consume("{")) { throw new MidnightCompilerParseError(lexer.CurrenToken, string.Join(Environment.NewLine, lexer.Messages)); } Content = lexer.ConsumeUntil("}"); LiturgySubCompiler liturgySubCompiler = new LiturgySubCompiler(); Lines = liturgySubCompiler.ParseLiturgyLines(Content); if (!lexer.Consume("}")) { throw new MidnightCompilerParseError(lexer.CurrenToken, string.Join(Environment.NewLine, lexer.Messages)); } return(this); }
void IASTElementGeneratesDebugXML.GenerateDebugXMLTree(IASTElement parent, StringBuilder output) { output.Append($"<ASTCommand CommandName=\"{CommandName.AsText}\">"); Command.GenerateDebugXMLTree(this, output); output.Append("</ASTCommand>"); }