Permalink
Browse files

Added support for multiple defaults in single block

  • Loading branch information...
1 parent bda2298 commit 38f8f026b31869aa58eceedccfc84e29ec436ef7 @claco committed Jun 10, 2009
View
8 README
@@ -14,4 +14,10 @@ WHAT'S WORKING?
- variable fallback from Process(data) to Settings(variables)
- implicit variable set [% variable = x %], where x is string, number, decimal
- explicit variable set [% SET variable = x %], where x is string, number, decimal
- - set defaults [% DEFAULT variable = x %], where x is string, number, decimal
+ - set defaults [% DEFAULT variable = x %], where x is string, number, decimal
+ - set multiple defaults in one block
+ [% DEFAULT
+ foo = 1
+ bar = 'baz'
+ baz = 2.34
+ %]
View
@@ -86,6 +86,8 @@
<ItemGroup>
<None Include="templates\DEFAULT.decimal.output" />
<None Include="templates\DEFAULT.decimal.source" />
+ <None Include="templates\DEFAULT.multiple.output" />
+ <None Include="templates\DEFAULT.multiple.source" />
<None Include="templates\DEFAULT.number.output" />
<None Include="templates\DEFAULT.number.source" />
</ItemGroup>
View
@@ -91,6 +91,7 @@ public void DefaultLiteralVariable()
Expect(result, Is.EqualTo(Output("DEFAULT.literal")));
Expect(data["variable"], Is.EqualTo("Hello World"));
+ Expect(data.Count, Is.EqualTo(1));
}
[Test, Category("Unit")]
@@ -133,6 +134,19 @@ public void DefaultIgnoresNotNull()
Expect(data["variable"], Is.EqualTo("Exists"));
}
+ [Test, Category("Unit")]
+ public void DefaultMultipleVariables()
+ {
+ var data = new Dictionary<string, object>();
+ var result = Template.Process(Source("DEFAULT.multiple"), data);
+
+ Expect(result, Is.EqualTo(Output("DEFAULT.multiple")));
+ Expect(data["foo"], Is.EqualTo("Hello World"));
+ Expect(data["bar"], Is.EqualTo(5));
+ Expect(data["baz"], Is.EqualTo(42.95));
+ Expect(data.Count, Is.EqualTo(3));
+ }
+
#endregion
}
}
@@ -0,0 +1 @@
+
@@ -0,0 +1,5 @@
+[% DEFAULT
+ foo = 'Hello World'
+ bar = 5
+ baz = 42.95
+%]
View
@@ -1,4 +1,4 @@
-// $ANTLR 3.1.3 Mar 18, 2009 10:09:25 TT\\CSharpGenerator.g 2009-06-09 20:24:21
+// $ANTLR 3.1.3 Mar 18, 2009 10:09:25 TT\\CSharpGenerator.g 2009-06-09 21:30:30
// The variable 'variable' is assigned but its value is never used.
#pragma warning disable 168, 219
View
@@ -83,23 +83,23 @@ Print(GetVariable("<name>").ToString());<\n>
>>
setLiteralVariable(name, literal) ::= <<
-SetVariable("<name>", "<literal>");
+SetVariable("<name>", "<literal>");<\n>
>>
setNumericVariable(name, number) ::= <<
-SetVariable("<name>", <number>);
+SetVariable("<name>", <number>);<\n>
>>
setDecimalVariable(name, decimal) ::= <<
-SetVariable("<name>", Convert.ToDecimal(<decimal>));
+SetVariable("<name>", Convert.ToDecimal(<decimal>));<\n>
>>
setDefaultLiteralVariable(name, literal) ::= <<
-SetDefault("<name>", "<literal>");
+SetDefault("<name>", "<literal>");<\n>
>>
setDefaultNumericVariable(name, number) ::= <<
-SetDefault("<name>", <number>);
+SetDefault("<name>", <number>);<\n>
>>
setDefaultDecimalVariable(name, decimal) ::= <<
View
@@ -94,9 +94,13 @@ setExpr
| 'SET'? ID ASSIGN NUMBER -> ^(SET ID NUMBER)
| 'SET'? ID ASSIGN DECIMAL -> ^(SET ID DECIMAL)
;
-
+
defaultExpr
- : DEFAULT ID ASSIGN LITERAL -> ^(DEFAULT ID LITERAL)
- | DEFAULT ID ASSIGN NUMBER -> ^(DEFAULT ID NUMBER)
- | DEFAULT ID ASSIGN DECIMAL -> ^(DEFAULT ID DECIMAL)
+ : DEFAULT (assignment)+ -> ^(DEFAULT assignment)+
+ ;
+
+assignment
+ : ID ASSIGN LITERAL -> ID LITERAL
+ | ID ASSIGN NUMBER -> ID NUMBER
+ | ID ASSIGN DECIMAL -> ID DECIMAL
;
View
@@ -1,4 +1,4 @@
-// $ANTLR 3.1.3 Mar 18, 2009 10:09:25 TT\\Template.g 2009-06-09 20:24:20
+// $ANTLR 3.1.3 Mar 18, 2009 10:09:25 TT\\Template.g 2009-06-09 21:30:29
// The variable 'variable' is assigned but its value is never used.
#pragma warning disable 168, 219
Oops, something went wrong.

0 comments on commit 38f8f02

Please sign in to comment.