Skip to content

Commit 0cefb27

Browse files
author
Viktor Chernev
committed
finish adding Describe v1.0 functionality
1 parent ce6ea9a commit 0cefb27

File tree

72 files changed

+771
-713
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+771
-713
lines changed

@DescribeCompilerAPI/Compiler/Compiler/VerbosityLow.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,6 @@ private bool parseFile_LowVerbosity(FileInfo fileInfo, DescribeUnfold unfold)
200200
string source = "";
201201
try
202202
{
203-
if (fileInfo.FullName.Contains("technologiesAndInventions.ds"))
204-
{
205-
bool lll = false;
206-
}
207-
208203
source = File.ReadAllText(fileInfo.FullName);
209204
source = _Preprocessor.ProcessSource(source);
210205
if (source.Length == 0)

@DescribeCompilerAPI/DescribeCompilerAPI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
<Compile Include="Compiler\Preprocessors\PreprocessorForDescribe08.cs" />
7373
<Compile Include="Compiler\Preprocessors\PreprocessorForDescribe07.cs" />
7474
<Compile Include="Compiler\Preprocessors\PreprocessorForDescribe06.cs" />
75-
<Compile Include="Translators\CharacterDictionaries.cs" />
75+
<Compile Include="Translators\Dictionaries\CharacterDictionaries.cs" />
7676
<Compile Include="Translators\JsonTranslator.cs" />
7777
<Compile Include="Translators\DescribeTranslator.cs" />
7878
<Compile Include="Translators\HtmlTranslator.cs" />

@DescribeCompilerAPI/Translators/DescribeTranslator.cs

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,6 @@ namespace DescribeCompiler.Translators
99
{
1010
public abstract class DescribeTranslator
1111
{
12-
/// <summary>
13-
/// Wether the Translator makes use of template files.
14-
/// </summary>
15-
public abstract bool USES_TEMPLATES
16-
{
17-
get;
18-
}
19-
20-
/// <summary>
21-
/// Wether there are inbuilt templates for the translator.
22-
/// </summary>
23-
public abstract bool HAS_INBUILT_TEMPLATES
24-
{
25-
get;
26-
}
27-
28-
/// <summary>
29-
/// The default name of the templates for the translator.
30-
/// If HAS_INBUILT_TEMPLATES then this should be the name of some
31-
/// of the inbuilt templates in folder "Templates"
32-
/// </summary>
33-
public abstract string DEFAULT_TEMPLATES_NAME
34-
{
35-
get;
36-
}
37-
3812
/// <summary>
3913
/// This is meant as a failsafe - if false then the
4014
/// translation process should not be allowed to start.
@@ -46,21 +20,17 @@ public abstract bool IsInitialized
4620
}
4721

4822

23+
/// <summary>
24+
/// Translade an unfold structure. This is the main method.
25+
/// </summary>
26+
/// <param name="u">The unfold structure to translate.</param>
27+
/// <returns>The resulted string in the target language.</returns>
4928
public abstract string TranslateUnfold(DescribeUnfold u);
50-
public abstract bool LoadExternalTemplates(string path);
51-
public abstract bool LoadInternalTemplates(string name);
52-
5329
}
5430
}
5531
// After we have parsed our files and optimized the resulting parse tree to content in an Unfold
5632
// structure, we might want to translate this unfold structure to a desired language (like HTML,
5733
// or JSON e.g.) This is where Translators come into play.
5834
//
5935
// Previously (before v0.9.2) translators were a part of the compilation process itself, which
60-
// limited flexibility and made implementation of custom translators harder.
61-
//
62-
// Translators might (and will in many cases) make use of "translation templates". Those are
63-
// collections of source code files containing placeholder text where information will be inserted.
64-
// There are inbuilt templates it this project (as embedded resources - folder "Templates"), and
65-
// there are inbuilt translators that will use those. You can use those templates in building
66-
// your own translators, and you can provide an inbuilt translator with external templates.
36+
// limited flexibility and made implementation of custom translators harder.

@DescribeCompilerAPI/Translators/CharacterDictionaries.cs renamed to @DescribeCompilerAPI/Translators/Dictionaries/CharacterDictionaries.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
1+
using System.Collections.Generic;
2+
63

74
namespace DescribeCompiler.Translators
85
{
@@ -203,6 +200,5 @@ public static class CharacterDictionariesHtml
203200
}
204201
}
205202
// http://xahlee.info/comp/unicode_circled_numbers.html
206-
//
207203
// Those are simply dictionaries that map normal characters or integer numbers to Unicode escape sequences.
208204
// Those can then be used when writing translators.

@DescribeCompilerAPI/Translators/HtmlTranslator.cs

Lines changed: 14 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@ namespace DescribeCompiler.Translators
1414
{
1515
public class HtmlTranslator : DescribeTranslator
1616
{
17-
public override bool USES_TEMPLATES
18-
{
19-
get { return true; }
20-
}
21-
public override bool HAS_INBUILT_TEMPLATES
22-
{
23-
get { return true; }
24-
}
25-
public override string DEFAULT_TEMPLATES_NAME
26-
{
27-
get { return "HTML_PARACORD"; }
28-
}
2917
public override bool IsInitialized
3018
{
3119
get;
@@ -34,9 +22,7 @@ public override bool IsInitialized
3422

3523

3624
//templates
37-
public bool selectInbuiltTemplate = true;
38-
public string selectedTemplate = null;
39-
25+
const string templatesFolderName = "HTML_PARACORD";
4026
static string pageTemplate;
4127
static string rootTemplate;
4228
static string itemTemplate;
@@ -64,130 +50,29 @@ public HtmlTranslator()
6450
//try to initialize templates
6551
try
6652
{
67-
if (!USES_TEMPLATES)
68-
{
69-
IsInitialized = true;
70-
LogInfo("Translator initialized - not using templates");
71-
}
72-
else if (HAS_INBUILT_TEMPLATES)
73-
{
74-
string n = DEFAULT_TEMPLATES_NAME;
75-
pageTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"Page");
76-
rootTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"Root");
77-
coloredProductionTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"ProductionColored");
78-
productionTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"Production");
79-
itemTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"Item");
80-
emptyItemTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"ItemEmpty");
81-
nlcommentItemTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"ItemCommentNl");
82-
commentItemTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"ItemComment");
83-
coloredItemTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"ItemColored");
84-
linkTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"Link");
85-
86-
LogInfo("Translator initialized - using template \"" + n + "\"");
87-
selectInbuiltTemplate = true;
88-
selectedTemplate = n;
89-
IsInitialized = true;
90-
}
91-
else
92-
{
93-
LogInfo("Translator NOT initialized - Must further load templates from folder before using.");
94-
selectInbuiltTemplate = false;
95-
IsInitialized = false;
96-
}
97-
}
98-
catch (Exception ex)
99-
{
100-
IsInitialized = false;
101-
LogError("Fatal error: " + ex.Message);
102-
}
103-
}
104-
105-
/// <summary>
106-
/// Load templates from an external folder.
107-
/// </summary>
108-
/// <param name="path">The path to the desired templates folder</param>
109-
/// <returns>True if successful</returns>
110-
public override bool LoadExternalTemplates(string path)
111-
{
112-
try
113-
{
114-
DirectoryInfo directoryInfo = new DirectoryInfo(path);
115-
if (directoryInfo.Exists)
116-
{
117-
FileInfo[] fs = directoryInfo.GetFiles();
118-
foreach (FileInfo finfo in fs)
119-
{
120-
// make sure that "ItemEmpty" or "ItemComment" and all other
121-
// that start with Item are before "Item"
122-
if (finfo.Name.StartsWith("Page")) pageTemplate = File.ReadAllText(finfo.FullName);
123-
else if (finfo.Name.StartsWith("Root")) rootTemplate = File.ReadAllText(finfo.FullName);
124-
else if (finfo.Name.StartsWith("ProductionColored")) coloredProductionTemplate = File.ReadAllText(finfo.FullName);
125-
else if (finfo.Name.StartsWith("Production")) productionTemplate = File.ReadAllText(finfo.FullName);
126-
else if (finfo.Name.StartsWith("ItemEmpty")) emptyItemTemplate = File.ReadAllText(finfo.FullName);
127-
else if (finfo.Name.StartsWith("ItemCommentNl")) nlcommentItemTemplate = File.ReadAllText(finfo.FullName);
128-
else if (finfo.Name.StartsWith("ItemComment")) commentItemTemplate = File.ReadAllText(finfo.FullName);
129-
else if (finfo.Name.StartsWith("ItemColored")) coloredItemTemplate = File.ReadAllText(finfo.FullName);
130-
else if (finfo.Name.StartsWith("Item")) itemTemplate = File.ReadAllText(finfo.FullName);
131-
else if (finfo.Name.StartsWith("Link")) linkTemplate = File.ReadAllText(finfo.FullName);
132-
}
133-
134-
LogInfo("Translator initialized - using external template \"" + path + "\"");
135-
selectInbuiltTemplate = false;
136-
selectedTemplate = path;
137-
IsInitialized = true;
138-
return true;
139-
}
140-
else
141-
{
142-
LogInfo("Translator Not initialized - external template path does not exist \"" + path + "\"");
143-
selectInbuiltTemplate = false;
144-
selectedTemplate = path;
145-
IsInitialized = false;
146-
return false;
147-
}
148-
}
149-
catch (Exception ex)
150-
{
151-
IsInitialized = false;
152-
LogError("Fatal error: " + ex.Message);
153-
return false;
154-
}
155-
}
156-
157-
/// <summary>
158-
/// Load templates from an internal folder of embedded resources.
159-
/// </summary>
160-
/// <param name="name">The name of the internal folder</param>
161-
/// <returns>True if successful</returns>
162-
public override bool LoadInternalTemplates(string name)
163-
{
164-
try
165-
{
166-
pageTemplate = ResourceUtil.ExtractResourceByFileName_String(name, @"Page");
167-
rootTemplate = ResourceUtil.ExtractResourceByFileName_String(name, @"Root");
168-
coloredProductionTemplate = ResourceUtil.ExtractResourceByFileName_String(name, @"ProductionColored");
169-
productionTemplate = ResourceUtil.ExtractResourceByFileName_String(name, @"Production");
170-
itemTemplate = ResourceUtil.ExtractResourceByFileName_String(name, @"Item");
171-
emptyItemTemplate = ResourceUtil.ExtractResourceByFileName_String(name, @"ItemEmpty");
172-
nlcommentItemTemplate = ResourceUtil.ExtractResourceByFileName_String(name, @"ItemCommentNl");
173-
commentItemTemplate = ResourceUtil.ExtractResourceByFileName_String(name, @"ItemComment");
174-
coloredItemTemplate = ResourceUtil.ExtractResourceByFileName_String(name, @"ItemColored");
175-
linkTemplate = ResourceUtil.ExtractResourceByFileName_String(name, @"Link");
53+
string n = templatesFolderName;
54+
pageTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"Page");
55+
rootTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"Root");
56+
coloredProductionTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"ProductionColored");
57+
productionTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"Production");
58+
itemTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"Item");
59+
emptyItemTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"ItemEmpty");
60+
nlcommentItemTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"ItemCommentNl");
61+
commentItemTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"ItemComment");
62+
coloredItemTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"ItemColored");
63+
linkTemplate = ResourceUtil.ExtractResourceByFileName_String(n, @"Link");
17664

177-
LogInfo("Translator initialized - using template \"" + name + "\"");
178-
selectInbuiltTemplate = true;
179-
selectedTemplate = name;
65+
LogInfo("Translator initialized - using template \"" + n + "\"");
18066
IsInitialized = true;
181-
return true;
18267
}
18368
catch (Exception ex)
18469
{
18570
IsInitialized = false;
18671
LogError("Fatal error: " + ex.Message);
187-
return false;
18872
}
18973
}
19074

75+
19176
/// <summary>
19277
/// Get html code from unfold
19378
/// </summary>

0 commit comments

Comments
 (0)