Beispiel #1
0
 public static StackCfg Default() => new StackCfg
 {
     Includes   = new HashSet <string>(),
     Assemblies = new HashSet <string>()
     {
         "System.Core",
         "Microsoft.CSharp",
         typeof(StackCfg).Assembly.Location,
     },
     Usings = new HashSet <string>()
     {
         "System",
         "System.Collections.Generic",
         "System.Linq",
         "System.Text",
         "System.Dynamic",
         "System.Reflection",
         "System.Text",
         "System.Text.RegularExpressions",
         "System.IO",
         "System.Runtime.CompilerServices",
         nameof(Whomst)
     },
     DefaultFormatCfg = FormatCfg.Default(),
     FormatDict       = new FmtDict
     {
         [".py"] = FormatCfg.Python(),
     },
     InitialDefines = new DefineDict
     {
         ["Credit"] = $"/* Made with help from {nameof(Whomst)}: http://github.com/OswaldHurlem/Whomst */",
     }
 };
Beispiel #2
0
        public StackCfg AddFormatCfgs(FmtDict fmtCfgs)
        {
            foreach (var kvp in fmtCfgs)
            {
                FormatCfg f = null;
                if (!FormatDict.TryGetValue(kvp.Key, out f))
                {
                    f = new FormatCfg();
                }
                FormatDict[kvp.Key] = f.MergeOverWith(kvp.Value);
            }

            return(this);
        }
Beispiel #3
0
        public static FileCfg ParseCommandLine(string[] args, out string jsonFilename)
        {
            var    firstJob          = new FileCfg();
            string jsonFilenameLocal = null;
            bool   showHelp          = false;

            var options = new OptionSet
            {
                { "i|input=", "the file to preprocess", i => firstJob.InputFileName = i },
                { "g|generate", "generate code", g => firstJob.Generate = (g != null) },
                { "c|clean", "deletes generated code", c => firstJob.DeleteOutput = (c != null) },
                { "p|private", "deletes whomst generator code", p => firstJob.DeleteCode = (p != null) },
                { "cfg|config=", "json file holding configuration", f => jsonFilenameLocal = f },
                { "h|help", "show this message and exit", v => showHelp = (v != null) },
                {
                    "x|skip",
                    "doesn't evaluate whomst code (and therefore does not generate it). Still tries to eval lines beginning " +
                    $"with force directive (default  \"{FormatCfg.Default().ForceDirective}\"",
                    x => firstJob.SkipCompute = (x != null)
                },
                {
                    "o|output=",
                    "where the file with generated code added gets written to. Leave blank to replace existing file",
                    o => firstJob.OutputFileName = o
                },
            };

            try { options.Parse(args); }
            catch (OptionException e)
            {
                options.WriteOptionDescriptions(Console.Out);
                throw e;
            }

            if (showHelp)
            {
                options.WriteOptionDescriptions(Console.Out);
                Environment.Exit(0);
            }

            jsonFilename = jsonFilenameLocal;

            return(firstJob);
        }
Beispiel #4
0
        public FileCfg GetProtoFileCfg(string fileExtension)
        {
            FormatCfg fmtCfg = FormatCfg.Default();

            fmtCfg = fmtCfg.MergeOverWith(DefaultFormatCfg);

            FormatDict.TryGetValue(fileExtension, out var fromFileExt);
            if (fromFileExt != null)
            {
                fmtCfg = fmtCfg.MergeOverWith(fromFileExt);
            }

            var fileCfg = new FileCfg()
            {
                FormatCfg = fmtCfg
            };

            fileCfg.AddDefines(InitialDefines);
            return(fileCfg);
        }
Beispiel #5
0
 public StackCfg WithDefaultFormatCfg(FormatCfg fmtCfg)
 {
     DefaultFormatCfg = DefaultFormatCfg.MergeOverWith(fmtCfg);
     return(this);
 }