Exemple #1
0
        public override Result VisitMacro([NotNull] MacroContext context)
        {
            return(_writer.UsingIndent("{", "}", () =>
            {
                var id = context.SYNTAX().GetText();
                if (id == "include")
                {
                    var provider = $"{nameof(RuntimeProviders)}.{nameof(RuntimeProviders.GetEmiter)}";
                    _writer.WriteIndentLine($"var emiter = {provider}<{id}>();");
                    _writer.WriteIndentLine($"var result = emiter.{nameof(ISdmapEmiter.BuildText)}(self);");
                }
                else
                {
                    var provider = $"{nameof(RuntimeProviders)}.{nameof(RuntimeProviders.RuntimeMacros)}";
                    _writer.WriteIndent($"var result = {provider}.{context.SYNTAX()}(");
                    WriteMacroParameters(context.macroParameter());
                }

                _writer.WriteIndentLine($"if (result.{nameof(Result.IsSuccess)})");
                _writer.UsingIndent("{", "}", () =>
                {
                    _writer.WriteIndentLine(
                        $"sb.Append(result.{nameof(Result<int>.Value)});");
                });
                _writer.WriteIndentLine("else");
                _writer.UsingIndent("{", "}", () =>
                {
                    _writer.WriteIndentLine("return result;");
                });
                return Result.Ok();
            }));
        }