Skip to content

Commit cc4efc7

Browse files
committed
support for inline parent operator, v0.6
1 parent ca2be8d commit cc4efc7

30 files changed

+103
-145
lines changed

src/CascadiumCompiler.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
using Cascadium.Extensions;
44
using Cascadium.Object;
55
using System;
6-
using System.Collections.Generic;
7-
using System.Linq;
86
using System.Text;
9-
using System.Threading.Tasks;
107

118
namespace Cascadium;
129

src/CascadiumException.cs

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

84
namespace Cascadium;
95

src/CascadiumLexer.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
<PackageTags>css,scss,sass,less</PackageTags>
2222
<RepositoryType>git</RepositoryType>
2323

24-
<Version>0.4.0</Version>
25-
<AssemblyVersion>0.4.0</AssemblyVersion>
26-
<FileVersion>0.4.0</FileVersion>
24+
<Version>0.6.0</Version>
25+
<AssemblyVersion>0.6.0</AssemblyVersion>
26+
<FileVersion>0.6.0</FileVersion>
2727

2828
<NeutralLanguage>en</NeutralLanguage>
2929
<IncludeSymbols>True</IncludeSymbols>

src/CascadiumOptions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Collections.Specialized;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
85

96
namespace Cascadium;
107

src/Compiler/Assembler.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
using Cascadium.Object;
33
using System;
44
using System.Collections.Generic;
5-
using System.Data;
65
using System.Linq;
76
using System.Text;
8-
using System.Threading.Tasks;
97

108
namespace Cascadium.Compiler;
119

@@ -121,12 +119,12 @@ string BuildCssSelector(IList<string[]> selectors)
121119
}
122120
}
123121

124-
string BuildCssSelector(string[] cSelectors, string[] bSelectors)
122+
string BuildCssSelector(string[] currentSelectors, string[] parentSelectors)
125123
{
126124
StringBuilder sb = new StringBuilder();
127-
if (bSelectors.Length == 0)
125+
if (parentSelectors.Length == 0)
128126
{
129-
foreach (string cSelector in cSelectors)
127+
foreach (string cSelector in currentSelectors)
130128
{
131129
string prepared = Helper.PrepareSelectorUnit(cSelector, Options.KeepNestingSpace, Options.Pretty);
132130
sb.Append(prepared);
@@ -136,13 +134,15 @@ string BuildCssSelector(string[] cSelectors, string[] bSelectors)
136134
}
137135
goto finish;
138136
}
139-
foreach (string C in cSelectors)
137+
138+
foreach (string C in currentSelectors)
140139
{
141140
string c = C.Trim();
142-
foreach (string B in bSelectors)
141+
foreach (string B in parentSelectors)
143142
{
144143
string b = B.Trim();
145144
string s;
145+
146146
if (c.StartsWith('&'))
147147
{
148148
sb.Append(b);
@@ -152,6 +152,12 @@ string BuildCssSelector(string[] cSelectors, string[] bSelectors)
152152
s = s.TrimStart();
153153
}
154154
}
155+
else if (c.Contains('&'))
156+
{
157+
string repl = Helper.SafeStrReplace(c, '&', b);
158+
s = repl;
159+
;
160+
}
155161
else
156162
{
157163
sb.Append(b);

src/Compiler/Flattener.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
75

86
namespace Cascadium.Compiler;
97

src/Compiler/Helper.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,44 @@
33
using System.Collections.Generic;
44
using System.Linq;
55
using System.Text;
6-
using System.Threading.Tasks;
76

87
namespace Cascadium.Compiler;
98

109
internal static class Helper
1110
{
11+
public static string SafeStrReplace(string input, char search, string replacement)
12+
{
13+
StringBuilder sb = new StringBuilder();
14+
bool inSingleString = false;
15+
bool inDoubleString = false;
16+
17+
for (int i = 0; i < input.Length; i++)
18+
{
19+
char c = input[i];
20+
char b = i > 0 ? input[i - 1] : '\0';
21+
22+
if (c == '\'' && b != '\\' && !inDoubleString)
23+
{
24+
inSingleString = !inSingleString;
25+
}
26+
else if (c == '"' && b != '\\' && !inSingleString)
27+
{
28+
inDoubleString = !inDoubleString;
29+
}
30+
31+
if ((inDoubleString || inSingleString) == false && c == search)
32+
{
33+
sb.Append(replacement);
34+
}
35+
else
36+
{
37+
sb.Append(c);
38+
}
39+
}
40+
41+
return sb.ToString();
42+
}
43+
1244
public static int SafeCountIncidences(string value, char op)
1345
{
1446
int incidences = 0;

src/Compiler/Parser.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using Cascadium.Entity;
22
using Cascadium.Object;
3-
using System;
43
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
84

95
namespace Cascadium.Compiler;
106

@@ -130,5 +126,5 @@ static bool IsSelectorInvalidRuleset(string content)
130126
}
131127

132128
return false;
133-
}
129+
}
134130
}

src/Compiler/Sanitizer.cs

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

73
namespace Cascadium.Compiler;
84

src/Compiler/TextInterpreter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using System;
1+
using Cascadium.Object;
2+
using System;
23
using System.Text;
3-
using Cascadium.Object;
44

55
namespace Cascadium.Compiler;
66

src/Compiler/Tokenizer.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
1-
using System;
1+
using Cascadium.Object;
22
using System.Collections.Generic;
3-
using System.Diagnostics;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
7-
using System.Xml.Linq;
8-
using Cascadium.Entity;
9-
using Cascadium.Object;
103

114
namespace Cascadium.Compiler;
125

@@ -121,6 +114,6 @@ IEnumerable<Token> ReadSelectors(string selectorCode)
121114
{
122115
yield return new Token(TokenType.Em_Selector, s.Trim(), Interpreter);
123116
}
124-
}
117+
}
125118
}
126119
}

src/Converters/CSSConverter.cs

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

83
namespace Cascadium.Converters;
94

src/Converters/StaticCSSConverter.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Collections.Specialized;
4-
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
74

85
namespace Cascadium.Converters;
96

src/Entity/CssRule.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
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;
62

73
namespace Cascadium.Entity;
84

src/Entity/CssStylesheet.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using Cascadium.Compiler;
2-
using System;
32
using System.Collections.Generic;
43
using System.Data;
54
using System.Linq;
65
using System.Text;
7-
using System.Threading.Tasks;
86

97
namespace Cascadium.Entity;
108

src/Entity/FlatRule.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using System.Collections.Generic;
32
using System.Data;
43
using System.Linq;
5-
using System.Text;
6-
using System.Threading.Tasks;
74

85
namespace Cascadium.Entity;
96

src/Entity/FlatStylesheet.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
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;
62

73
namespace Cascadium.Entity;
84

src/Entity/IRuleContainer.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
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;
62

73
namespace Cascadium.Entity;
84

src/Entity/NestedRule.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
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;
62

73
namespace Cascadium.Entity;
84

src/Entity/NestedStylesheet.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
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;
62

73
namespace Cascadium.Entity;
84

src/Extensions/Converter.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
using Cascadium.Converters;
22
using Cascadium.Entity;
3-
using System;
43
using System.Collections.Generic;
54
using System.Collections.Specialized;
65
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
96

107
namespace Cascadium.Extensions;
118

src/Extensions/MediaRewriter.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
using Cascadium.Compiler;
22
using Cascadium.Entity;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
83

94
namespace Cascadium.Extensions;
105

src/Extensions/ValueHandler.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
using Cascadium.Entity;
22
using Cascadium.Object;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
63
using System.Text;
7-
using System.Threading.Tasks;
84

95
namespace Cascadium.Extensions;
106

src/Object/Token.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
using System;
2-
using System.Collections.Generic;
1+
using Cascadium.Compiler;
2+
using System;
33
using System.Linq;
4-
using System.Text;
5-
using System.Threading.Tasks;
6-
using Cascadium.Compiler;
74

85
namespace Cascadium.Object;
96

src/Object/TokenCollection.cs

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

73
namespace Cascadium.Object;
84

tool/Cascadium-Utility.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<AssemblyName>cascadium</AssemblyName>
99
<InvariantGlobalization>true</InvariantGlobalization>
1010

11-
<AssemblyVersion>0.5</AssemblyVersion>
12-
<FileVersion>0.5</FileVersion>
11+
<AssemblyVersion>0.6</AssemblyVersion>
12+
<FileVersion>0.6</FileVersion>
1313
<RootNamespace>cascadiumtool</RootNamespace>
1414
</PropertyGroup>
1515

tool/Compiler.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,8 @@ await Parallel.ForEachAsync(inputFiles,
131131
catch (CascadiumException cex)
132132
{
133133
string linePadText = cex.Line + ".";
134-
AnsiConsole.MarkupLine($"[grey]cascadium[/] [silver]{DateTime.Now:T}[/] [indianred_1]error[/] at file [white]{file.Substring(smallInputLength + 1)}[/], line [deepskyblue3_1]{cex.Line}[/], col. [deepskyblue3_1]{cex.Column}[/]:");
135-
AnsiConsole.WriteLine();
136-
AnsiConsole.MarkupInterpolated($"\t[deepskyblue3_1]{linePadText}[/] [silver]{cex.LineText}[/]");
134+
AnsiConsole.MarkupLine($"[grey]cascadium[/] [silver]{DateTime.Now:T}[/] [indianred_1]error[/] at file [white]{file.Substring(smallInputLength + 1)}[/], line [deepskyblue3_1]{cex.Line}[/], col. [deepskyblue3_1]{cex.Column}[/]:\n");
135+
AnsiConsole.MarkupInterpolated($"\t[deepskyblue3_1]{linePadText}[/] [silver]{cex.LineText.TrimEnd()}[/]\n");
137136
AnsiConsole.MarkupLine($"\t[lightpink4]{new string(' ', cex.Column + linePadText.Length)}^[/]");
138137
AnsiConsole.MarkupInterpolated($"\t[mistyrose3]{cex.Message}[/]");
139138
AnsiConsole.WriteLine();

tool/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace cascadiumtool;
88

99
internal class Program
1010
{
11-
public const string VersionLabel = "v.0.5";
11+
public const string VersionLabel = "v.0.6.0";
1212
public static string CurrentDirectory { get; set; } = Directory.GetCurrentDirectory();
1313
public static bool HasRootConfiguration { get; private set; }
1414
public static JsonCssCompilerOptions? CompilerOptions { get; set; }

0 commit comments

Comments
 (0)