zclsyntax: change template control sequence introducer to %{
Previously it was !{, but in real examples this looked confusing since an exclamation point after a word looks (to humans) like literal punctuation rather than syntax. % is not ideal either since it's also the marker traditionally used for printf, but has the advantage that programmers are already primed for it to be syntax.
This commit is contained in:
parent
e7d33665d0
commit
e594a232b3
@ -130,43 +130,43 @@ trim`,
|
|||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
`!{ if true ~} hello !{~ endif }`,
|
`%{ if true ~} hello %{~ endif }`,
|
||||||
nil,
|
nil,
|
||||||
cty.StringVal("hello"),
|
cty.StringVal("hello"),
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`!{ if false ~} hello !{~ endif}`,
|
`%{ if false ~} hello %{~ endif}`,
|
||||||
nil,
|
nil,
|
||||||
cty.StringVal(""),
|
cty.StringVal(""),
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`!{ if true ~} hello !{~ else ~} goodbye !{~ endif }`,
|
`%{ if true ~} hello %{~ else ~} goodbye %{~ endif }`,
|
||||||
nil,
|
nil,
|
||||||
cty.StringVal("hello"),
|
cty.StringVal("hello"),
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`!{ if false ~} hello !{~ else ~} goodbye !{~ endif }`,
|
`%{ if false ~} hello %{~ else ~} goodbye %{~ endif }`,
|
||||||
nil,
|
nil,
|
||||||
cty.StringVal("goodbye"),
|
cty.StringVal("goodbye"),
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`!{ if true ~} !{~ if false ~} hello !{~ else ~} goodbye !{~ endif ~} !{~ endif }`,
|
`%{ if true ~} %{~ if false ~} hello %{~ else ~} goodbye %{~ endif ~} %{~ endif }`,
|
||||||
nil,
|
nil,
|
||||||
cty.StringVal("goodbye"),
|
cty.StringVal("goodbye"),
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`!{ if false ~} !{~ if false ~} hello !{~ else ~} goodbye !{~ endif ~} !{~ endif }`,
|
`%{ if false ~} %{~ if false ~} hello %{~ else ~} goodbye %{~ endif ~} %{~ endif }`,
|
||||||
nil,
|
nil,
|
||||||
cty.StringVal(""),
|
cty.StringVal(""),
|
||||||
0,
|
0,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`!{ of true ~} hello !{~ endif}`,
|
`%{ of true ~} hello %{~ endif}`,
|
||||||
nil,
|
nil,
|
||||||
cty.UnknownVal(cty.String),
|
cty.UnknownVal(cty.String),
|
||||||
2, // "of" is not a valid control keyword, and "endif" is therefore also unexpected
|
2, // "of" is not a valid control keyword, and "endif" is therefore also unexpected
|
||||||
|
@ -972,27 +972,27 @@ var _zcltok_trans_keys []byte = []byte{
|
|||||||
163, 165, 186, 144, 145, 146, 147, 148,
|
163, 165, 186, 144, 145, 146, 147, 148,
|
||||||
150, 151, 152, 155, 157, 158, 160, 170,
|
150, 151, 152, 155, 157, 158, 160, 170,
|
||||||
171, 172, 175, 128, 159, 161, 169, 173,
|
171, 172, 175, 128, 159, 161, 169, 173,
|
||||||
191, 128, 191, 10, 13, 33, 34, 36,
|
191, 128, 191, 10, 13, 34, 36, 37,
|
||||||
92, 128, 191, 192, 223, 224, 239, 240,
|
92, 128, 191, 192, 223, 224, 239, 240,
|
||||||
247, 248, 255, 10, 13, 33, 34, 36,
|
247, 248, 255, 10, 13, 34, 92, 36,
|
||||||
92, 128, 191, 192, 223, 224, 239, 240,
|
37, 128, 191, 192, 223, 224, 239, 240,
|
||||||
247, 248, 255, 10, 13, 33, 36, 92,
|
247, 248, 255, 10, 13, 92, 36, 37,
|
||||||
128, 191, 192, 223, 224, 239, 240, 247,
|
128, 191, 192, 223, 224, 239, 240, 247,
|
||||||
248, 255, 33, 36, 92, 192, 223, 224,
|
248, 255, 92, 36, 37, 192, 223, 224,
|
||||||
239, 240, 247, 10, 13, 33, 34, 36,
|
239, 240, 247, 10, 13, 34, 92, 36,
|
||||||
92, 192, 223, 224, 239, 240, 247, 248,
|
37, 192, 223, 224, 239, 240, 247, 248,
|
||||||
255, 10, 13, 33, 34, 36, 92, 128,
|
255, 10, 13, 34, 92, 36, 37, 128,
|
||||||
223, 224, 239, 240, 247, 248, 255, 10,
|
223, 224, 239, 240, 247, 248, 255, 10,
|
||||||
13, 33, 34, 36, 92, 128, 191, 192,
|
13, 34, 92, 36, 37, 128, 191, 192,
|
||||||
223, 224, 239, 240, 247, 248, 255, 123,
|
223, 224, 239, 240, 247, 248, 255, 123,
|
||||||
126, 123, 126, 128, 191, 128, 191, 128,
|
126, 123, 126, 128, 191, 128, 191, 128,
|
||||||
191, 10, 13, 33, 36, 128, 191, 192,
|
191, 10, 13, 36, 37, 128, 191, 192,
|
||||||
223, 224, 239, 240, 247, 248, 255, 10,
|
223, 224, 239, 240, 247, 248, 255, 10,
|
||||||
13, 33, 36, 128, 191, 192, 223, 224,
|
13, 36, 37, 128, 191, 192, 223, 224,
|
||||||
239, 240, 247, 248, 255, 126, 126, 128,
|
239, 240, 247, 248, 255, 126, 126, 128,
|
||||||
191, 128, 191, 128, 191, 10, 13, 33,
|
191, 128, 191, 128, 191, 10, 13, 36,
|
||||||
36, 128, 191, 192, 223, 224, 239, 240,
|
37, 128, 191, 192, 223, 224, 239, 240,
|
||||||
247, 248, 255, 10, 13, 33, 36, 128,
|
247, 248, 255, 10, 13, 36, 37, 128,
|
||||||
191, 192, 223, 224, 239, 240, 247, 248,
|
191, 192, 223, 224, 239, 240, 247, 248,
|
||||||
255, 126, 126, 128, 191, 128, 191, 128,
|
255, 126, 126, 128, 191, 128, 191, 128,
|
||||||
191,
|
191,
|
||||||
@ -1124,9 +1124,9 @@ var _zcltok_single_lengths []byte = []byte{
|
|||||||
1, 0, 0, 0, 0, 1, 1, 1,
|
1, 0, 0, 0, 0, 1, 1, 1,
|
||||||
0, 0, 1, 30, 47, 13, 9, 3,
|
0, 0, 1, 30, 47, 13, 9, 3,
|
||||||
0, 1, 28, 2, 0, 18, 16, 0,
|
0, 1, 28, 2, 0, 18, 16, 0,
|
||||||
6, 6, 5, 3, 6, 6, 6, 1,
|
6, 4, 3, 1, 4, 4, 4, 1,
|
||||||
1, 1, 1, 0, 0, 0, 4, 4,
|
1, 1, 1, 0, 0, 0, 4, 2,
|
||||||
1, 1, 0, 0, 0, 4, 4, 1,
|
1, 1, 0, 0, 0, 4, 2, 1,
|
||||||
1, 0, 0, 0,
|
1, 0, 0, 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1256,9 +1256,9 @@ var _zcltok_range_lengths []byte = []byte{
|
|||||||
0, 2, 2, 5, 2, 3, 5, 3,
|
0, 2, 2, 5, 2, 3, 5, 3,
|
||||||
2, 3, 5, 1, 1, 1, 3, 1,
|
2, 3, 5, 1, 1, 1, 3, 1,
|
||||||
1, 2, 2, 3, 1, 2, 3, 1,
|
1, 2, 2, 3, 1, 2, 3, 1,
|
||||||
5, 5, 5, 3, 4, 4, 5, 0,
|
5, 6, 6, 4, 5, 5, 6, 0,
|
||||||
0, 0, 0, 1, 1, 1, 5, 5,
|
0, 0, 0, 1, 1, 1, 5, 6,
|
||||||
0, 0, 1, 1, 1, 5, 5, 0,
|
0, 0, 1, 1, 1, 5, 6, 0,
|
||||||
0, 1, 1, 1,
|
0, 1, 1, 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1388,10 +1388,10 @@ var _zcltok_index_offsets []int16 = []int16{
|
|||||||
4941, 4943, 4946, 4949, 4955, 4958, 4963, 4970,
|
4941, 4943, 4946, 4949, 4955, 4958, 4963, 4970,
|
||||||
4975, 4978, 4982, 4989, 5021, 5070, 5085, 5098,
|
4975, 4978, 4982, 4989, 5021, 5070, 5085, 5098,
|
||||||
5103, 5105, 5109, 5140, 5146, 5148, 5169, 5189,
|
5103, 5105, 5109, 5140, 5146, 5148, 5169, 5189,
|
||||||
5191, 5203, 5215, 5226, 5233, 5244, 5255, 5267,
|
5191, 5203, 5214, 5224, 5230, 5240, 5250, 5261,
|
||||||
5269, 5271, 5273, 5275, 5277, 5279, 5281, 5291,
|
5263, 5265, 5267, 5269, 5271, 5273, 5275, 5285,
|
||||||
5301, 5303, 5305, 5307, 5309, 5311, 5321, 5331,
|
5294, 5296, 5298, 5300, 5302, 5304, 5314, 5323,
|
||||||
5333, 5335, 5337, 5339,
|
5325, 5327, 5329, 5331,
|
||||||
}
|
}
|
||||||
|
|
||||||
var _zcltok_indicies []int16 = []int16{
|
var _zcltok_indicies []int16 = []int16{
|
||||||
@ -2045,22 +2045,21 @@ var _zcltok_indicies []int16 = []int16{
|
|||||||
1022, 1023, 1024, 1025, 1021, 1027, 1028, 1029,
|
1022, 1023, 1024, 1025, 1021, 1027, 1028, 1029,
|
||||||
1030, 1014, 1026, 1014, 887, 1014, 887, 1031,
|
1030, 1014, 1026, 1014, 887, 1014, 887, 1031,
|
||||||
1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038,
|
1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038,
|
||||||
1039, 1036, 767, 1040, 1040, 1041, 1040, 1041,
|
1039, 1036, 767, 1040, 1040, 1040, 1035, 1041,
|
||||||
1035, 1040, 768, 769, 1042, 1040, 767, 1040,
|
1040, 768, 769, 1042, 1040, 767, 1040, 1040,
|
||||||
1040, 1043, 1043, 1035, 1040, 768, 769, 1042,
|
1035, 1043, 1040, 768, 769, 1042, 1040, 767,
|
||||||
1040, 767, 1043, 1043, 1035, 1044, 1045, 1046,
|
1035, 1043, 1044, 1045, 1046, 767, 1040, 1040,
|
||||||
767, 1040, 1040, 1041, 1040, 1041, 1035, 768,
|
1040, 1035, 1041, 768, 769, 1042, 1040, 767,
|
||||||
769, 1042, 1040, 767, 1040, 1040, 1041, 1040,
|
1040, 1040, 1040, 1035, 1041, 768, 769, 1042,
|
||||||
1041, 1035, 768, 769, 1042, 1040, 767, 1040,
|
1040, 767, 1040, 1040, 1040, 1035, 1041, 769,
|
||||||
1040, 1041, 1040, 1041, 1035, 769, 768, 769,
|
768, 769, 1042, 1040, 767, 1048, 767, 1050,
|
||||||
1042, 1040, 767, 1048, 767, 1050, 1049, 1051,
|
1049, 1051, 767, 1053, 1052, 767, 1054, 771,
|
||||||
767, 1053, 1052, 767, 1054, 771, 1054, 1055,
|
1054, 1055, 1054, 773, 1056, 1057, 1058, 1059,
|
||||||
1054, 773, 1056, 1057, 1058, 1059, 1060, 1061,
|
1060, 1061, 1062, 1059, 775, 773, 1056, 1064,
|
||||||
1062, 1059, 775, 773, 1056, 1064, 1064, 1063,
|
1063, 776, 777, 1065, 1063, 775, 1067, 1066,
|
||||||
776, 777, 1065, 1063, 775, 1067, 1066, 1069,
|
1069, 1068, 775, 1070, 776, 1070, 777, 1070,
|
||||||
1068, 775, 1070, 776, 1070, 777, 1070, 781,
|
781, 1071, 1072, 1073, 1074, 1075, 1076, 1077,
|
||||||
1071, 1072, 1073, 1074, 1075, 1076, 1077, 1074,
|
1074, 783, 781, 1071, 1079, 1078, 784, 785,
|
||||||
783, 781, 1071, 1079, 1079, 1078, 784, 785,
|
|
||||||
1080, 1078, 783, 1082, 1081, 1084, 1083, 783,
|
1080, 1078, 783, 1082, 1081, 1084, 1083, 783,
|
||||||
1085, 784, 1085, 785, 1085,
|
1085, 784, 1085, 785, 1085,
|
||||||
}
|
}
|
||||||
@ -2195,7 +2194,7 @@ var _zcltok_trans_targs []int16 = []int16{
|
|||||||
819, 820, 821, 822, 823, 824, 825, 826,
|
819, 820, 821, 822, 823, 824, 825, 826,
|
||||||
855, 880, 883, 884, 886, 893, 894, 897,
|
855, 880, 883, 884, 886, 893, 894, 897,
|
||||||
901, 913, 918, 919, 921, 924, 926, 1000,
|
901, 913, 918, 919, 921, 924, 926, 1000,
|
||||||
1007, 1000, 1009, 1002, 1000, 1011, 1012, 1013,
|
1000, 1007, 1009, 1002, 1000, 1011, 1012, 1013,
|
||||||
1000, 928, 931, 1003, 1004, 1005, 1006, 1000,
|
1000, 928, 931, 1003, 1004, 1005, 1006, 1000,
|
||||||
1008, 1000, 1000, 1010, 1000, 1000, 1000, 933,
|
1008, 1000, 1000, 1010, 1000, 1000, 1000, 933,
|
||||||
934, 939, 940, 1014, 1018, 1019, 1020, 1014,
|
934, 939, 940, 1014, 1018, 1019, 1020, 1014,
|
||||||
@ -2334,13 +2333,13 @@ var _zcltok_trans_actions []byte = []byte{
|
|||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
0, 0, 0, 0, 0, 0, 0, 13,
|
0, 0, 0, 0, 0, 0, 0, 13,
|
||||||
0, 11, 0, 5, 15, 0, 5, 5,
|
11, 0, 0, 5, 15, 0, 5, 5,
|
||||||
21, 0, 0, 0, 5, 5, 5, 23,
|
21, 0, 0, 0, 5, 5, 5, 23,
|
||||||
0, 19, 9, 0, 17, 7, 25, 0,
|
0, 17, 7, 0, 19, 9, 25, 0,
|
||||||
0, 0, 0, 37, 0, 139, 139, 43,
|
0, 0, 0, 37, 0, 139, 139, 43,
|
||||||
0, 0, 41, 33, 39, 31, 45, 0,
|
0, 0, 39, 31, 41, 33, 45, 0,
|
||||||
0, 0, 57, 0, 145, 145, 63, 0,
|
0, 0, 57, 0, 145, 145, 63, 0,
|
||||||
0, 61, 53, 59, 51, 65,
|
0, 59, 51, 61, 53, 65,
|
||||||
}
|
}
|
||||||
|
|
||||||
var _zcltok_to_state_actions []byte = []byte{
|
var _zcltok_to_state_actions []byte = []byte{
|
||||||
@ -2803,7 +2802,7 @@ func scanTokens(data []byte, filename string, start zcl.Pos, mode scanMode) []To
|
|||||||
f.emitToken(TokenType(b[0]), ts, te)
|
f.emitToken(TokenType(b[0]), ts, te)
|
||||||
}
|
}
|
||||||
|
|
||||||
// line 2815 "scan_tokens.go"
|
// line 2814 "scan_tokens.go"
|
||||||
{
|
{
|
||||||
top = 0
|
top = 0
|
||||||
ts = 0
|
ts = 0
|
||||||
@ -2811,7 +2810,7 @@ func scanTokens(data []byte, filename string, start zcl.Pos, mode scanMode) []To
|
|||||||
act = 0
|
act = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// line 2823 "scan_tokens.go"
|
// line 2822 "scan_tokens.go"
|
||||||
{
|
{
|
||||||
var _klen int
|
var _klen int
|
||||||
var _trans int
|
var _trans int
|
||||||
@ -2836,7 +2835,7 @@ func scanTokens(data []byte, filename string, start zcl.Pos, mode scanMode) []To
|
|||||||
|
|
||||||
ts = p
|
ts = p
|
||||||
|
|
||||||
// line 2847 "scan_tokens.go"
|
// line 2846 "scan_tokens.go"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3715,7 +3714,7 @@ func scanTokens(data []byte, filename string, start zcl.Pos, mode scanMode) []To
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// line 3591 "scan_tokens.go"
|
// line 3590 "scan_tokens.go"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3736,7 +3735,7 @@ func scanTokens(data []byte, filename string, start zcl.Pos, mode scanMode) []To
|
|||||||
|
|
||||||
act = 0
|
act = 0
|
||||||
|
|
||||||
// line 3611 "scan_tokens.go"
|
// line 3610 "scan_tokens.go"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,24 +193,24 @@ func scanTokens(data []byte, filename string, start zcl.Pos, mode scanMode) []To
|
|||||||
}
|
}
|
||||||
|
|
||||||
TemplateInterp = "${" ("~")?;
|
TemplateInterp = "${" ("~")?;
|
||||||
TemplateControl = "!{" ("~")?;
|
TemplateControl = "%{" ("~")?;
|
||||||
EndStringTmpl = '"';
|
EndStringTmpl = '"';
|
||||||
StringLiteralChars = (AnyUTF8 - ("\r"|"\n"));
|
StringLiteralChars = (AnyUTF8 - ("\r"|"\n"));
|
||||||
TemplateStringLiteral = (
|
TemplateStringLiteral = (
|
||||||
('$' ^'{') |
|
('$' ^'{') |
|
||||||
('!' ^'{') |
|
('%' ^'{') |
|
||||||
('\\' StringLiteralChars) |
|
('\\' StringLiteralChars) |
|
||||||
(StringLiteralChars - ("$" | "!" | '"'))
|
(StringLiteralChars - ("$" | '%' | '"'))
|
||||||
)+;
|
)+;
|
||||||
HeredocStringLiteral = (
|
HeredocStringLiteral = (
|
||||||
('$' ^'{') |
|
('$' ^'{') |
|
||||||
('!' ^'{') |
|
('%' ^'{') |
|
||||||
(StringLiteralChars - ("$" | "!"))
|
(StringLiteralChars - ("$" | '%'))
|
||||||
)*;
|
)*;
|
||||||
BareStringLiteral = (
|
BareStringLiteral = (
|
||||||
('$' ^'{') |
|
('$' ^'{') |
|
||||||
('!' ^'{') |
|
('%' ^'{') |
|
||||||
(StringLiteralChars - ("$" | "!"))
|
(StringLiteralChars - ("$" | '%'))
|
||||||
)* Newline?;
|
)* Newline?;
|
||||||
|
|
||||||
stringTemplate := |*
|
stringTemplate := |*
|
||||||
|
@ -365,7 +365,7 @@ func TestScanTokens_normal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
`"!{a}"`,
|
`"%{a}"`,
|
||||||
[]Token{
|
[]Token{
|
||||||
{
|
{
|
||||||
Type: TokenOQuote,
|
Type: TokenOQuote,
|
||||||
@ -377,7 +377,7 @@ func TestScanTokens_normal(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
Type: TokenTemplateControl,
|
Type: TokenTemplateControl,
|
||||||
Bytes: []byte(`!{`),
|
Bytes: []byte(`%{`),
|
||||||
Range: zcl.Range{
|
Range: zcl.Range{
|
||||||
Start: zcl.Pos{Byte: 1, Line: 1, Column: 2},
|
Start: zcl.Pos{Byte: 1, Line: 1, Column: 2},
|
||||||
End: zcl.Pos{Byte: 3, Line: 1, Column: 4},
|
End: zcl.Pos{Byte: 3, Line: 1, Column: 4},
|
||||||
|
Loading…
Reference in New Issue
Block a user