Skip to content

Commit cd158db

Browse files
committed
add docs
1 parent 252406c commit cd158db

23 files changed

+549
-25
lines changed

DescribeCompiler/DescribeCompiler.cs

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ bool ParseFolder_LowVerbosity(DirectoryInfo dirInfo, out string html)
499499
while (unfold.Files.Count() > 0)
500500
{
501501
string filename = unfold.Files[0];
502+
unfold.CurFile = filename;
502503
bool result = ParseFile_LowVerbosity(new FileInfo(filename), unfold);
503504
if (result)
504505
{
@@ -583,6 +584,7 @@ bool ParseFolder_MediumVerbosity(DirectoryInfo dirInfo, out string html)
583584
while (unfold.Files.Count() > 0)
584585
{
585586
string filename = unfold.Files[0];
587+
unfold.CurFile = filename;
586588
bool result = ParseFile_MediumVerbosity(new FileInfo(filename), unfold);
587589
if (result)
588590
{
@@ -669,6 +671,7 @@ bool ParseFolder_HighVerbosity(DirectoryInfo dirInfo, out string html)
669671
while(unfold.Files.Count() > 0)
670672
{
671673
string filename = unfold.Files[0];
674+
unfold.CurFile = filename;
672675
bool result = ParseFile_HighVerbosity(new FileInfo(filename), unfold);
673676
if(result)
674677
{
@@ -818,6 +821,7 @@ bool ParseFile_MediumVerbosity(FileInfo fileInfo, DescribeUnfold unfold)
818821
try
819822
{
820823
source = File.ReadAllText(fileInfo.FullName);
824+
source = EncodeNonAsciiCharacters(source);
821825
if (source.Length == 0)
822826
{
823827
LogError("Error - the file you are trying to parse is empty");
@@ -915,6 +919,7 @@ bool ParseFile_HighVerbosity(FileInfo fileInfo, DescribeUnfold unfold)
915919
try
916920
{
917921
source = File.ReadAllText(fileInfo.FullName);
922+
source = EncodeNonAsciiCharacters(source);
918923
if (source.Length == 0)
919924
{
920925
LogError("Error - the file you are trying to parse is empty");
@@ -1304,7 +1309,7 @@ enum GrammarName
13041309
Tags, //0.7
13051310
Links, //0.8
13061311
Decorators, //0.9
1307-
Official, //1.0
1312+
Official, //1.0
13081313
}
13091314
string GrammarNameToFullGramarName(GrammarName name)
13101315
{
@@ -1349,22 +1354,67 @@ private void log(string text)
13491354
}
13501355
private string EncodeNonAsciiCharacters(string value)
13511356
{
1357+
//we add a character before and after that we will not use,
1358+
//in order to skip if tests to see if we are not on the first or last char
1359+
//for null reference. The new line we keep, as it is a workaround for the
1360+
//runaway group last comment bug
1361+
value = "." + value + Environment.NewLine;
1362+
13521363
//https://stackoverflow.com/questions/1615559/convert-a-unicode-string-to-an-escaped-ascii-string
13531364
StringBuilder sb = new StringBuilder();
1354-
foreach (char c in value)
1365+
for (int i = 1; i < value.Length - 1; i++)
13551366
{
1356-
if (c > 127)
1367+
if (value[i] > 127)
13571368
{
13581369
// This character is too big for ASCII
1359-
string encodedValue = "&#x" + ((int)c).ToString("x4") + "\\;";
1370+
string encodedValue = "&#x" + ((int)value[i]).ToString("x4") + "\\;";
13601371
sb.Append(encodedValue);
13611372
}
13621373
else
13631374
{
1364-
sb.Append(c);
1375+
if (value[i] == '-'
1376+
&& value[i + 1] != '>'
1377+
&& value[i - 1] != '\\')
1378+
{
1379+
sb.Append('\\');
1380+
}
1381+
else if (value[i] == '*'
1382+
&& value[i + 1] != '/'
1383+
&& value[i - 1] != '\\')
1384+
{
1385+
sb.Append('\\');
1386+
}
1387+
else if (value[i] == '/'
1388+
&& value[i + 1] != '/'
1389+
&& value[i - 1] != '/'
1390+
&& value[i + 1] != '*'
1391+
&& value[i - 1] != '*'
1392+
&& value[i - 1] != '\\')
1393+
{
1394+
sb.Append('\\');
1395+
}
1396+
else if (value[i] == '\\'
1397+
&& value[i - 1] != '\\'
1398+
&& value[i + 1] != '\\'
1399+
&& value[i + 1] != '-'
1400+
&& value[i + 1] != '*'
1401+
&& value[i + 1] != '/'
1402+
&& value[i + 1] != '<'
1403+
&& value[i + 1] != '>'
1404+
&& value[i + 1] != '['
1405+
&& value[i + 1] != ']'
1406+
&& value[i + 1] != '{'
1407+
&& value[i + 1] != '}'
1408+
&& value[i + 1] != ','
1409+
&& value[i + 1] != ';')
1410+
{
1411+
sb.Append('\\');
1412+
}
1413+
1414+
sb.Append(value[i]);
13651415
}
13661416
}
1367-
return sb.ToString() + Environment.NewLine;
1417+
return sb.ToString();
13681418
}
13691419

13701420

DescribeCompiler/DescribeCompiler.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@
6060
</ItemGroup>
6161
<ItemGroup>
6262
<Content Include="describe.ico" />
63+
<EmbeddedResource Include="Translations\Link.html" />
64+
<EmbeddedResource Include="Translations\NotSpacedItemColored.html" />
6365
<EmbeddedResource Include="Translations\NotSpacedItemComment.html" />
6466
<EmbeddedResource Include="Translations\NotSpacedItemEmpty.html" />
6567
<EmbeddedResource Include="Translations\NotSpacedItem.html" />

DescribeCompiler/DescribeUnfold.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ public class DescribeUnfold
88
public Dictionary<string, List<string>> Productions; //id of lhs item vs ids of rhs items
99
public Dictionary<string, string> Translations; //id of item vs text of item
1010

11-
public string CurFileNamespace; //current namespace we are in
11+
public string CurNamespace; //current namespace we are in
12+
public string CurFile; //current file we are in
1213
public List<string> Files; //list of files
13-
public Dictionary<string, string> IdFile; //id vs filepath that contains it
14+
15+
public Dictionary<string, List<string>> ItemIdFile; //item id vs filepath that contains it
16+
public Dictionary<string, string> ProdIdFile; //production id vs filepath that contains it
1417

1518
public Dictionary<string, List<string>> Links; //id vs links texts
1619
public Dictionary<string, List<string>> Decorators; //id vs decorators texts
1720

21+
1822
/// <summary>
1923
/// Ctor.
2024
/// </summary>
@@ -24,9 +28,12 @@ public DescribeUnfold()
2428
Productions = new Dictionary<string, List<string>>();
2529
Translations = new Dictionary<string, string>();
2630

27-
CurFileNamespace = "";
31+
CurNamespace = "";
32+
CurFile = "";
2833
Files = new List<string>();
29-
IdFile = new Dictionary<string, string>();
34+
35+
ItemIdFile = new Dictionary<string, List<string>>();
36+
ProdIdFile = new Dictionary<string, string>();
3037

3138
Links = new Dictionary<string, List<string>>();
3239
Decorators = new Dictionary<string, List<string>>();

DescribeCompiler/Optimizations.cs

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ private static string[] DoLinks(Reduction r)
6666
private static string DoDecorator(string text)
6767
{
6868
string s = text.Substring(1, text.Length - 2);
69-
return s;
69+
70+
//we need to remove spaces here for the translations later on
71+
return s.Replace(" ", "");
7072
}
7173
private static string[] DoDecorators(Reduction r)
7274
{
@@ -220,15 +222,15 @@ private static string DoItem(DescribeUnfold u, Reduction r)
220222
{
221223
tag = getRandomString();
222224
}
223-
if(u.CurFileNamespace != "")
225+
if(u.CurNamespace != "")
224226
{
225227
if (tag.StartsWith("."))
226228
{
227-
tag = u.CurFileNamespace + tag;
229+
tag = u.CurNamespace + tag;
228230
}
229231
else if(tag.Contains(".") == false)
230232
{
231-
tag = u.CurFileNamespace + "." + tag;
233+
tag = u.CurNamespace + "." + tag;
232234
}
233235
}
234236

@@ -267,6 +269,16 @@ private static string DoItem(DescribeUnfold u, Reduction r)
267269
}
268270
}
269271

272+
//idFile
273+
if (u.ItemIdFile.ContainsKey(tag) == false)
274+
{
275+
u.ItemIdFile.Add(tag, new List<string>() { u.CurFile });
276+
}
277+
else
278+
{
279+
u.ItemIdFile[tag].Add(u.CurFile);
280+
}
281+
270282

271283
return tag;
272284
}
@@ -369,7 +381,11 @@ private static string DoExpression(DescribeUnfold u, Reduction r)
369381
if (u.Productions.ContainsKey(head))
370382
{
371383
string item = u.Translations[head] + " <" + head + ">";
372-
throw new Exception("Collision! Item \"" + item + "\" - there is production head item with the same id.");
384+
string prodfile = u.ProdIdFile[head];
385+
string message = "Collision! Item \"" + item +
386+
"\" - there is production head with the same id in file: \"" +
387+
prodfile + "\"";
388+
throw new Exception(message);
373389
}
374390
u.Productions.Add(head, new List<string>() { right });
375391
}
@@ -382,10 +398,19 @@ private static string DoExpression(DescribeUnfold u, Reduction r)
382398
if (u.Productions.ContainsKey(head))
383399
{
384400
string item = u.Translations[head] + " <" + head + ">";
385-
throw new Exception("Collision! Item \"" + item + "\" - there is production head item with the same id.");
401+
string prodfile = u.ProdIdFile[head];
402+
string message = "Collision! Item \"" + item +
403+
"\" - there is production head with the same id in file: \"" +
404+
prodfile + "\"";
405+
throw new Exception(message);
386406
}
387407
u.Productions.Add(head, rights.ToList());
388408
}
409+
410+
//idFile
411+
u.ProdIdFile.Add(head, u.CurFile);
412+
413+
//return
389414
return head;
390415
}
391416

@@ -413,7 +438,7 @@ private static string[] DoExpressionList(DescribeUnfold u, Reduction r, bool isP
413438
foreach (string directive in directives)
414439
{
415440
string keyword = u.Translations[directive];
416-
if(keyword == "namespace") u.CurFileNamespace = directive;
441+
if(keyword == "namespace") u.CurNamespace = directive;
417442
u.Translations.Remove(directive);
418443
}
419444

@@ -457,7 +482,7 @@ private static string[] DoExpressionList(DescribeUnfold u, Reduction r, bool isP
457482
public static bool DoScripture(DescribeUnfold u, Reduction r)
458483
{
459484
//reset namespace for the file
460-
u.CurFileNamespace = "";
485+
u.CurNamespace = "";
461486

462487
//if we have no productions whatsoever
463488
//then this must be the primary file

0 commit comments

Comments
 (0)