Exemplo n.º 1
0
        void AppendFilenameAsTypeName()
        {
            int lastSlash = Filename.LastIndexOf('\\');

            if (lastSlash == -1)
            {
                throw new Exception(string.Format("Could not infer interface name from {0}. No backslash", Filename));
            }

            SexBuilder.AppendAsTypeName(sb, Filename.Substring(lastSlash + 1));
        }
Exemplo n.º 2
0
        void AppendNamespace()
        {
            if (!Filename.StartsWith(Globals.Sexel.ContentFolder))
            {
                throw new Exception(string.Format("Cannot infer namespace. The file path '{0}' was not a subdirectory of the content folder '{1}'", Filename, Globals.Sexel.ContentFolder));
            }

            string subpath = Filename.Substring(Globals.Sexel.ContentFolder.Length);

            SexBuilder.AppendPathStringAsNamespace(sb, subpath);
        }
Exemplo n.º 3
0
        public void AppendClass()
        {
            int i = 0;

            foreach (TableParser table in Tables.Items)
            {
                SexBuilder.AppendRowDef(sb, table);
            }

            foreach (TableParser table in Tables.Items)
            {
                sb.Append("(alias ");
                SexBuilder.AppendTableNameToLocalStructName(sb, table);
                sb.Append("Row ");

                AppendNamespace();
                sb.Append('.');
                SexBuilder.AppendTableNameToLocalStructName(sb, table);
                sb.Append("Row)\n");
            }

            sb.Append("\n(class CSXL0");
            AppendFilenameAsTypeName();
            sb.Append("Asset");

            sb.Append(" (defines ");
            AppendNamespace();
            sb.Append('.');
            AppendInterfaceShortName();
            sb.Append(")\n");

            i = 1;

            foreach (TableParser table in Tables.Items)
            {
                sb.Append("\t(array<");
                SexBuilder.AppendAsTypeName(sb, table.Name);
                sb.AppendFormat("Row> table{0}", i++);
                sb.Append(")\n");
            }

            sb.Append(")\n\n");

            i = 1;

            foreach (TableParser table in Tables.Items)
            {
                sb.Append("(method CSXL0");
                AppendFilenameAsTypeName();
                sb.Append("Asset.");
                SexBuilder.AppendAsTypeName(sb, table.Name);
                sb.Append(" -> (array<");
                SexBuilder.AppendAsTypeName(sb, table.Name);
                sb.AppendFormat("Row> table):\n\t(table = this.table{0})\n)\n", i++);
            }

            sb.Append("\n(method CSXL0.");
            AppendFilenameAsTypeName();
            sb.Append("Asset.Construct :\n");

            i = 1;
            foreach (TableParser table in Tables.Items)
            {
                sb.AppendFormat("\t(ConstructFromAppendix table{0} \"table{1}\")\n", i, i++);
            }

            sb.Append(")\n\n");

            i = 1;
            foreach (TableParser table in Tables.Items)
            {
                sb.AppendFormat("(factory ");
                AppendNamespace();
                sb.Append(".New");
                AppendFilenameAsTypeName();
                sb.Append(" ");
                AppendNamespace();
                sb.Append(".IAsset");
                AppendFilenameAsTypeName();
                sb.Append(": (construct CSXL0");
                AppendFilenameAsTypeName();
                sb.Append("))\n");
            }

            sb.Append("\n");

            i = 1;
            foreach (TableParser table in Tables.Items)
            {
                sb.AppendFormat("(' table{0} ", i++);
                SexBuilder.AppendTableNameToLocalStructName(sb, table);

                sb.Append("\n");

                Excel.Range item;

                for (int j = table.FirstRowIndex; j < table.FinalRowIndex; ++j)
                {
                    sb.Append("\t(");

                    for (int k = table.FirstColumnIndex; k < table.FinalColumnIndex; ++k)
                    {
                        if (k != table.FirstColumnIndex)
                        {
                            sb.Append("\t");
                        }

                        string entry = table.GetCellText(k, j, out item);

                        Excel.Range typeEntry;
                        string      type = table.GetFieldType(k, out typeEntry);
                        if (type == "string")
                        {
                            bool usesQuotes = SexBuilder.HasEscapedCharacters(entry);
                            if (usesQuotes)
                            {
                                sb.Append("\"");
                            }

                            SexBuilder.AddEscapedText(sb, entry);

                            if (usesQuotes)
                            {
                                sb.Append("\"");
                            }
                        }
                        else
                        {
                            SexBuilder.AppendMakeSexyCase(sb, entry);
                        }
                    }

                    sb.Append(")\n");
                }

                sb.AppendFormat(")\n");
            }
        }
Exemplo n.º 4
0
 public void AppendHeaders()
 {
     sb.AppendFormat("(' generator: Sexel 1.0.0.0 from: \"");
     SexBuilder.AddEscapedText(sb, Filename);
     sb.AppendFormat("\")\n\n");
 }