<commit_before>﻿// -----------------------------------------------------------------------
// <copyright file="GenerateCodePass.cs" company="(none)">
//   Copyright © 2013 <NAME>.  All Rights Reserved.
//   This source is subject to the MIT license.
//   Please see license.txt for more information.
// </copyright>
// -----------------------------------------------------------------------

namespace Weave.Compiler
{
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Text;
    using Weave.Expressions;

    internal class GenerateCodePass : CompilePass
    {
        public override void Run(Template template, CompileResult result)
        {
            using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                new GenerateCodeWalker(stringWriter).WalkTemplate(template);
                result.Code = stringWriter.ToString();
            }
        }

        private class GenerateCodeWalker : TemplateWalker
        {
            private static Dictionary<char, string> simpleEscapeChars = new Dictionary<char, string>()
            {
                { '\'', "\\'" }, { '\"', "\\\"" }, { '\\', "\\\\" }, { '\0', "\\0" },
                { '\a', "\\a" }, { '\b', "\\b" }, { '\f', "\\f" }, { '\n', "\\n" },
                { '\r', "\\r" }, { '\t', "\\t" }, { '\v', "\\v" },
            };

            private readonly TextWriter writer;
            private readonly Dictionary<string, int> variables = new Dictionary<string, int>();

            public GenerateCodeWalker(TextWriter writer)
            {
                this.writer = writer;
            }

            public override void WalkTemplate(Template template)
            {
                var settings = template.Settings.ToLookup(s => s.Key, s => s.Value);
                var @namespace = settings["namespace"].Single();
                var classname = settings["classname"].SingleOrDefault() ?? "Templates";
                var methodname = settings["methodname"].SingleOrDefault() ?? "Render";
                var model = settings["model"].SingleOrDefault() ?? "dynamic";

                this.writer.Write("namespace ");
                this.writer.Write(@namespace);
                this.writer.Write("\r\n{\r\n");
                this.writer.Write("public partial class ");
                this.writer.Write(classname);
                this.writer.Write("\r\n{\r\n");
                this.writer.Write("public void ");
                this.writer.Write(methodname);
                this.writer.Write("(");<commit_msg>Added accessibility as an option.<commit_after>﻿// -----------------------------------------------------------------------
// <copyright file="GenerateCodePass.cs" company="(none)">
//   Copyright © 2013 <NAME>.  All Rights Reserved.
//   This source is subject to the MIT license.
//   Please see license.txt for more information.
// </copyright>
// -----------------------------------------------------------------------

namespace Weave.Compiler
{
    using System.Collections.Generic;
    using System.Globalization;
    using System.IO;
    using System.Linq;
    using System.Text;
    using Weave.Expressions;

    internal class GenerateCodePass : CompilePass
    {
        public override void Run(Template template, CompileResult result)
        {
            using (var stringWriter = new StringWriter(CultureInfo.InvariantCulture))
            {
                new GenerateCodeWalker(stringWriter).WalkTemplate(template);
                result.Code = stringWriter.ToString();
            }
        }

        private class GenerateCodeWalker : TemplateWalker
        {
            private static Dictionary<char, string> simpleEscapeChars = new Dictionary<char, string>()
            {
                { '\'', "\\'" }, { '\"', "\\\"" }, { '\\', "\\\\" }, { '\0', "\\0" },
                { '\a', "\\a" }, { '\b', "\\b" }, { '\f', "\\f" }, { '\n', "\\n" },
                { '\r', "\\r" }, { '\t', "\\t" }, { '\v', "\\v" },
            };

            private readonly TextWriter writer;
            private readonly Dictionary<string, int> variables = new Dictionary<string, int>();

            public GenerateCodeWalker(TextWriter writer)
            {
                this.writer = writer;
            }

            public override void WalkTemplate(Template template)
            {
                var settings = template.Settings.ToLookup(s => s.Key, s => s.Value);
                var @namespace = settings["namespace"].Single();
                var accessibility = settings["accessibility"].SingleOrDefault() ?? string.Empty;
                var classname = settings["classname"].SingleOrDefault() ?? "Templates";
                var methodname = settings["methodname"].SingleOrDefault() ?? "Render";
                var model = settings["model"].SingleOrDefault() ?? "dynamic";

                this.writer.Write("namespace ");
                this.writer.Write(@namespace);
                this.writer.Write("\r\n{\r\n");
                this.writer.Write(accessibility);
                this.writer.Write(" partial class ");
                this.writer.Write(classname);
                this.writer.Write("\r\n{\r\n");
                this.writer.Write("public void ");
                this.writer.Write(methodname);
                this.writer.Write("(");
{'fraction_non_alphanumeric': 0.1955193482688391, 'fraction_numerical': 0.0022218107757822625, 'mean_word_length': 1.588404408241495, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '345064', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1265, 'n_words': 294}