Форматные строки (#285)
This commit is contained in:
parent
170e47253d
commit
1e648d5a43
|
|
@ -927,6 +927,9 @@ namespace CodeFormatters
|
|||
|
||||
public override void visit(string_const _string_const)
|
||||
{
|
||||
int pos = GetPosition(_string_const.source_context.begin_position.line_num, _string_const.source_context.begin_position.column_num);
|
||||
if (Text[pos] == '$')
|
||||
sb.Append('$');
|
||||
sb.Append("'");
|
||||
sb.Append(_string_const.Value.Replace("'","''"));
|
||||
sb.Append("'");
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// This CSharp output file generated by Gardens Point LEX
|
||||
// Version: 1.1.3.301
|
||||
// Machine: IVAN-PC
|
||||
// DateTime: 18.03.2018 11:46:44
|
||||
// DateTime: 20.03.2018 20:53:51
|
||||
// UserName: Ivan
|
||||
// GPLEX input file <ABCPascal.lex>
|
||||
// GPLEX frame file <embedded resource>
|
||||
|
|
@ -124,8 +124,8 @@ namespace GPPGParserScanner
|
|||
|
||||
enum Result {accept, noMatch, contextFound};
|
||||
|
||||
const int maxAccept = 65;
|
||||
const int initial = 66;
|
||||
const int maxAccept = 66;
|
||||
const int initial = 67;
|
||||
const int eofNum = 0;
|
||||
const int goStart = -1;
|
||||
const int INITIAL = 0;
|
||||
|
|
@ -177,7 +177,7 @@ public PT parsertools;
|
|||
}
|
||||
};
|
||||
|
||||
static int[] startState = new int[] {66, 100, 101, 102, 102, 103,
|
||||
static int[] startState = new int[] {67, 102, 103, 104, 104, 105,
|
||||
0};
|
||||
|
||||
#region TwoLevelCharacterMap
|
||||
|
|
@ -1177,14 +1177,14 @@ public PT parsertools;
|
|||
return MapC(code);
|
||||
}
|
||||
|
||||
static Table[] NxS = new Table[105] {
|
||||
static Table[] NxS = new Table[107] {
|
||||
/* NxS[ 0] */ new Table(0, 0, 0, null),
|
||||
/* NxS[ 1] */ new Table(1, 19, -1, new sbyte[] {54, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 55}),
|
||||
/* NxS[ 1] */ new Table(1, 19, -1, new sbyte[] {55, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 56}),
|
||||
/* NxS[ 2] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 3] */ new Table(4, 1, -1, new sbyte[] {99}),
|
||||
/* NxS[ 4] */ new Table(26, 19, -1, new sbyte[] {52, 52, 52, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 52, -1, -1, -1, -1, 52, 52, 52}),
|
||||
/* NxS[ 3] */ new Table(4, 1, -1, new sbyte[] {101}),
|
||||
/* NxS[ 4] */ new Table(26, 20, -1, new sbyte[] {52, 52, 52, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 52, -1, -1, -1, -1, 52, 52, 52, 100}),
|
||||
/* NxS[ 5] */ new Table(8, 1, -1, new sbyte[] {51}),
|
||||
/* NxS[ 6] */ new Table(8, 12, -1, new sbyte[] {49, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 50}),
|
||||
|
|
@ -1203,27 +1203,27 @@ public PT parsertools;
|
|||
/* NxS[ 18] */ new Table(19, 1, -1, new sbyte[] {43}),
|
||||
/* NxS[ 19] */ new Table(19, 4, -1, new sbyte[] {41, -1, -1, 42}),
|
||||
/* NxS[ 20] */ new Table(19, 1, -1, new sbyte[] {40}),
|
||||
/* NxS[ 21] */ new Table(19, 5, -1, new sbyte[] {35, -1, -1, 36, 72}),
|
||||
/* NxS[ 21] */ new Table(19, 5, -1, new sbyte[] {35, -1, -1, 36, 73}),
|
||||
/* NxS[ 22] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 23] */ new Table(26, 1, -1, new sbyte[] {71}),
|
||||
/* NxS[ 24] */ new Table(13, 32, -1, new sbyte[] {68, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, 24, 24, 69, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, 24, -1, 69}),
|
||||
/* NxS[ 23] */ new Table(26, 1, -1, new sbyte[] {72}),
|
||||
/* NxS[ 24] */ new Table(13, 32, -1, new sbyte[] {69, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, 24, 24, 70, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, 24, -1, 70}),
|
||||
/* NxS[ 25] */ new Table(26, 19, -1, new sbyte[] {25, 25, 25, 25, 25, 25,
|
||||
25, 25, 25, 25, 25, 25, 25, 25, -1, 25, 25, 25, 25}),
|
||||
/* NxS[ 26] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 27] */ new Table(45, 4, 67, new sbyte[] {31, 67, 67, -1}),
|
||||
/* NxS[ 27] */ new Table(45, 4, 68, new sbyte[] {31, 68, 68, -1}),
|
||||
/* NxS[ 28] */ new Table(26, 19, -1, new sbyte[] {29, 29, 30, 30, 30, 30,
|
||||
30, 30, 30, 30, 30, 30, 30, 30, -1, 30, 29, 30, 30}),
|
||||
/* NxS[ 29] */ new Table(26, 17, -1, new sbyte[] {29, 29, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 29}),
|
||||
/* NxS[ 30] */ new Table(26, 19, -1, new sbyte[] {30, 30, 30, 30, 30, 30,
|
||||
30, 30, 30, 30, 30, 30, 30, 30, -1, 30, 30, 30, 30}),
|
||||
/* NxS[ 31] */ new Table(45, 1, -1, new sbyte[] {67}),
|
||||
/* NxS[ 31] */ new Table(45, 1, -1, new sbyte[] {68}),
|
||||
/* NxS[ 32] */ new Table(26, 17, -1, new sbyte[] {32, 32, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 32}),
|
||||
/* NxS[ 33] */ new Table(26, 19, -1, new sbyte[] {33, 33, 69, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 33, -1, 69}),
|
||||
/* NxS[ 33] */ new Table(26, 19, -1, new sbyte[] {33, 33, 70, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 33, -1, 70}),
|
||||
/* NxS[ 34] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 35] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 36] */ new Table(0, 0, -1, null),
|
||||
|
|
@ -1244,68 +1244,70 @@ public PT parsertools;
|
|||
/* NxS[ 51] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 52] */ new Table(26, 19, -1, new sbyte[] {52, 52, 52, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 52, -1, -1, -1, -1, 52, 52, 52}),
|
||||
/* NxS[ 53] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 54] */ new Table(0, 7, 54, new sbyte[] {-1, 54, 54, 54, 54, 54,
|
||||
/* NxS[ 53] */ new Table(45, 1, -1, new sbyte[] {100}),
|
||||
/* NxS[ 54] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 55] */ new Table(0, 7, 55, new sbyte[] {-1, 55, 55, 55, 55, 55,
|
||||
-1}),
|
||||
/* NxS[ 55] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 56] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 57] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 58] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 59] */ new Table(9, 1, -1, new sbyte[] {60}),
|
||||
/* NxS[ 60] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 59] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 60] */ new Table(9, 1, -1, new sbyte[] {61}),
|
||||
/* NxS[ 61] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 62] */ new Table(1, 1, -1, new sbyte[] {65}),
|
||||
/* NxS[ 63] */ new Table(4, 1, -1, new sbyte[] {104}),
|
||||
/* NxS[ 64] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 65] */ new Table(0, 7, 65, new sbyte[] {-1, 65, 65, 65, 65, 65,
|
||||
/* NxS[ 62] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 63] */ new Table(1, 1, -1, new sbyte[] {66}),
|
||||
/* NxS[ 64] */ new Table(4, 1, -1, new sbyte[] {106}),
|
||||
/* NxS[ 65] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 66] */ new Table(0, 7, 66, new sbyte[] {-1, 66, 66, 66, 66, 66,
|
||||
-1}),
|
||||
/* NxS[ 66] */ new Table(40, 36, 25, new sbyte[] {26, 25, 24, 25, 25, 27,
|
||||
/* NxS[ 67] */ new Table(40, 36, 25, new sbyte[] {26, 25, 24, 25, 25, 27,
|
||||
28, 2, -1, 1, 2, 3, 4, -1, -1, 5, 6, 7, 8, 9, 10, 11,
|
||||
12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 24}),
|
||||
/* NxS[ 67] */ new Table(45, 4, 67, new sbyte[] {31, 67, 67, -1}),
|
||||
/* NxS[ 68] */ new Table(26, 17, -1, new sbyte[] {33, 33, -1, -1, -1, -1,
|
||||
/* NxS[ 68] */ new Table(45, 4, 68, new sbyte[] {31, 68, 68, -1}),
|
||||
/* NxS[ 69] */ new Table(26, 17, -1, new sbyte[] {33, 33, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 33}),
|
||||
/* NxS[ 69] */ new Table(20, 23, -1, new sbyte[] {70, 70, -1, -1, -1, -1,
|
||||
/* NxS[ 70] */ new Table(20, 23, -1, new sbyte[] {71, 71, -1, -1, -1, -1,
|
||||
32, 32, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
32}),
|
||||
/* NxS[ 70] */ new Table(26, 17, -1, new sbyte[] {32, 32, -1, -1, -1, -1,
|
||||
/* NxS[ 71] */ new Table(26, 17, -1, new sbyte[] {32, 32, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 32}),
|
||||
/* NxS[ 71] */ new Table(27, 1, -1, new sbyte[] {34}),
|
||||
/* NxS[ 72] */ new Table(28, 9, -1, new sbyte[] {73, -1, -1, -1, 74, -1,
|
||||
-1, -1, 75}),
|
||||
/* NxS[ 73] */ new Table(29, 1, -1, new sbyte[] {89}),
|
||||
/* NxS[ 74] */ new Table(36, 1, -1, new sbyte[] {80}),
|
||||
/* NxS[ 75] */ new Table(39, 1, -1, new sbyte[] {76}),
|
||||
/* NxS[ 76] */ new Table(30, 1, -1, new sbyte[] {77}),
|
||||
/* NxS[ 77] */ new Table(28, 1, -1, new sbyte[] {78}),
|
||||
/* NxS[ 78] */ new Table(22, 1, -1, new sbyte[] {79}),
|
||||
/* NxS[ 79] */ new Table(22, 1, -1, new sbyte[] {37}),
|
||||
/* NxS[ 80] */ new Table(37, 1, -1, new sbyte[] {81}),
|
||||
/* NxS[ 81] */ new Table(36, 1, -1, new sbyte[] {82}),
|
||||
/* NxS[ 82] */ new Table(28, 1, -1, new sbyte[] {83}),
|
||||
/* NxS[ 83] */ new Table(38, 1, -1, new sbyte[] {84}),
|
||||
/* NxS[ 84] */ new Table(28, 1, -1, new sbyte[] {85}),
|
||||
/* NxS[ 85] */ new Table(35, 1, -1, new sbyte[] {86}),
|
||||
/* NxS[ 86] */ new Table(36, 1, -1, new sbyte[] {87}),
|
||||
/* NxS[ 87] */ new Table(22, 1, -1, new sbyte[] {88}),
|
||||
/* NxS[ 88] */ new Table(22, 1, -1, new sbyte[] {38}),
|
||||
/* NxS[ 89] */ new Table(30, 1, -1, new sbyte[] {90}),
|
||||
/* NxS[ 90] */ new Table(31, 1, -1, new sbyte[] {91}),
|
||||
/* NxS[ 91] */ new Table(28, 1, -1, new sbyte[] {92}),
|
||||
/* NxS[ 92] */ new Table(32, 1, -1, new sbyte[] {93}),
|
||||
/* NxS[ 72] */ new Table(27, 1, -1, new sbyte[] {34}),
|
||||
/* NxS[ 73] */ new Table(28, 9, -1, new sbyte[] {74, -1, -1, -1, 75, -1,
|
||||
-1, -1, 76}),
|
||||
/* NxS[ 74] */ new Table(29, 1, -1, new sbyte[] {90}),
|
||||
/* NxS[ 75] */ new Table(36, 1, -1, new sbyte[] {81}),
|
||||
/* NxS[ 76] */ new Table(39, 1, -1, new sbyte[] {77}),
|
||||
/* NxS[ 77] */ new Table(30, 1, -1, new sbyte[] {78}),
|
||||
/* NxS[ 78] */ new Table(28, 1, -1, new sbyte[] {79}),
|
||||
/* NxS[ 79] */ new Table(22, 1, -1, new sbyte[] {80}),
|
||||
/* NxS[ 80] */ new Table(22, 1, -1, new sbyte[] {37}),
|
||||
/* NxS[ 81] */ new Table(37, 1, -1, new sbyte[] {82}),
|
||||
/* NxS[ 82] */ new Table(36, 1, -1, new sbyte[] {83}),
|
||||
/* NxS[ 83] */ new Table(28, 1, -1, new sbyte[] {84}),
|
||||
/* NxS[ 84] */ new Table(38, 1, -1, new sbyte[] {85}),
|
||||
/* NxS[ 85] */ new Table(28, 1, -1, new sbyte[] {86}),
|
||||
/* NxS[ 86] */ new Table(35, 1, -1, new sbyte[] {87}),
|
||||
/* NxS[ 87] */ new Table(36, 1, -1, new sbyte[] {88}),
|
||||
/* NxS[ 88] */ new Table(22, 1, -1, new sbyte[] {89}),
|
||||
/* NxS[ 89] */ new Table(22, 1, -1, new sbyte[] {38}),
|
||||
/* NxS[ 90] */ new Table(30, 1, -1, new sbyte[] {91}),
|
||||
/* NxS[ 91] */ new Table(31, 1, -1, new sbyte[] {92}),
|
||||
/* NxS[ 92] */ new Table(28, 1, -1, new sbyte[] {93}),
|
||||
/* NxS[ 93] */ new Table(32, 1, -1, new sbyte[] {94}),
|
||||
/* NxS[ 94] */ new Table(33, 1, -1, new sbyte[] {95}),
|
||||
/* NxS[ 95] */ new Table(34, 1, -1, new sbyte[] {96}),
|
||||
/* NxS[ 96] */ new Table(35, 1, -1, new sbyte[] {97}),
|
||||
/* NxS[ 97] */ new Table(22, 1, -1, new sbyte[] {98}),
|
||||
/* NxS[ 98] */ new Table(22, 1, -1, new sbyte[] {39}),
|
||||
/* NxS[ 99] */ new Table(0, 7, 99, new sbyte[] {-1, 99, 53, 99, 99, 99,
|
||||
/* NxS[ 94] */ new Table(32, 1, -1, new sbyte[] {95}),
|
||||
/* NxS[ 95] */ new Table(33, 1, -1, new sbyte[] {96}),
|
||||
/* NxS[ 96] */ new Table(34, 1, -1, new sbyte[] {97}),
|
||||
/* NxS[ 97] */ new Table(35, 1, -1, new sbyte[] {98}),
|
||||
/* NxS[ 98] */ new Table(22, 1, -1, new sbyte[] {99}),
|
||||
/* NxS[ 99] */ new Table(22, 1, -1, new sbyte[] {39}),
|
||||
/* NxS[ 100] */ new Table(45, 4, 100, new sbyte[] {53, 100, 100, -1}),
|
||||
/* NxS[ 101] */ new Table(0, 7, 101, new sbyte[] {-1, 101, 54, 101, 101, 101,
|
||||
-1}),
|
||||
/* NxS[ 100] */ new Table(2, 1, 56, new sbyte[] {57}),
|
||||
/* NxS[ 101] */ new Table(8, 1, 58, new sbyte[] {59}),
|
||||
/* NxS[ 102] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 103] */ new Table(1, 3, 61, new sbyte[] {62, 61, 63}),
|
||||
/* NxS[ 104] */ new Table(0, 7, 104, new sbyte[] {-1, 104, 64, 104, 104, 104,
|
||||
/* NxS[ 102] */ new Table(2, 1, 57, new sbyte[] {58}),
|
||||
/* NxS[ 103] */ new Table(8, 1, 59, new sbyte[] {60}),
|
||||
/* NxS[ 104] */ new Table(0, 0, -1, null),
|
||||
/* NxS[ 105] */ new Table(1, 3, 62, new sbyte[] {63, 62, 64}),
|
||||
/* NxS[ 106] */ new Table(0, 7, 106, new sbyte[] {-1, 106, 65, 106, 106, 106,
|
||||
-1}),
|
||||
};
|
||||
|
||||
|
|
@ -2097,6 +2099,12 @@ yylval = new Union();
|
|||
return (int)Tokens.tkHex;
|
||||
break;
|
||||
case 53:
|
||||
yylval = new Union();
|
||||
currentLexLocation = CurrentLexLocation;
|
||||
yylval.stn = parsertools.create_format_string_const(yytext,currentLexLocation);
|
||||
return (int)Tokens.tkFormatStringLiteral;
|
||||
break;
|
||||
case 54:
|
||||
if (parsertools.build_tree_for_formatter)
|
||||
break;
|
||||
|
||||
|
|
@ -2152,36 +2160,36 @@ if (parsertools.build_tree_for_formatter)
|
|||
Defines.Remove(directiveparam);
|
||||
}
|
||||
break;
|
||||
case 54:
|
||||
case 55:
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
case 55:
|
||||
case 56:
|
||||
yylval = new Union(); yylval.op = new op_type_node(Operators.AssignmentDivision); return (int)Tokens.tkDivEqual;
|
||||
break;
|
||||
case 56:
|
||||
case 57:
|
||||
{
|
||||
}
|
||||
break;
|
||||
case 57:
|
||||
BEGIN(INITIAL);
|
||||
break;
|
||||
case 58:
|
||||
case 59:
|
||||
{
|
||||
}
|
||||
break;
|
||||
case 60:
|
||||
BEGIN(INITIAL);
|
||||
break;
|
||||
case 61:
|
||||
case 62:
|
||||
case 63:
|
||||
case 59:
|
||||
case 60:
|
||||
{
|
||||
}
|
||||
break;
|
||||
case 61:
|
||||
BEGIN(INITIAL);
|
||||
break;
|
||||
case 62:
|
||||
case 63:
|
||||
case 64:
|
||||
{
|
||||
}
|
||||
break;
|
||||
case 65:
|
||||
parsertools.DivideDirectiveOn(yytext,out directivename,out directiveparam);
|
||||
parsertools.CheckDirectiveParams(directivename,directiveparam); // directivename in UPPERCASE!
|
||||
if (directivename == "IFDEF")
|
||||
|
|
@ -2213,7 +2221,7 @@ parsertools.DivideDirectiveOn(yytext,out directivename,out directiveparam);
|
|||
BEGIN(INITIAL);
|
||||
}
|
||||
break;
|
||||
case 65:
|
||||
case 66:
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ INTNUM {Digit}+
|
|||
FLOATNUM {INTNUM}\.{INTNUM}
|
||||
EXPNUM ({INTNUM}\.)?{INTNUM}[eE][+\-]?{INTNUM}
|
||||
STRINGNUM \'([^\'\n]|\'\')*\'
|
||||
FORMATSTRINGNUM \$\'([^\'\n]|\'\')*\'
|
||||
HEXNUM ${HexDigit}+
|
||||
SHARPCHARNUM #{Digit}+
|
||||
OLDDIRECTIVE #{ID}
|
||||
|
|
@ -448,6 +449,13 @@ UNICODEARROW \x890
|
|||
return (int)Tokens.tkStringLiteral;
|
||||
}
|
||||
|
||||
{FORMATSTRINGNUM} {
|
||||
yylval = new Union();
|
||||
currentLexLocation = CurrentLexLocation;
|
||||
yylval.stn = parsertools.create_format_string_const(yytext,currentLexLocation);
|
||||
return (int)Tokens.tkFormatStringLiteral;
|
||||
}
|
||||
|
||||
{SHARPCHARNUM} {
|
||||
yylval = new Union();
|
||||
currentLexLocation = CurrentLexLocation;
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@
|
|||
%token <op> tkAssign tkPlusEqual tkMinusEqual tkMultEqual tkDivEqual tkMinus tkPlus tkSlash tkStar tkStarStar tkEqual tkGreater tkGreaterEqual tkLower tkLowerEqual
|
||||
%token <op> tkNotEqual tkCSharpStyleOr tkArrow tkOr tkXor tkAnd tkDiv tkMod tkShl tkShr tkNot tkAs tkIn tkIs tkImplicit tkExplicit tkAddressOf tkDeref
|
||||
%token <id> tkDirectiveName tkIdentifier
|
||||
%token <stn> tkStringLiteral tkAsciiChar
|
||||
%token <stn> tkStringLiteral tkFormatStringLiteral tkAsciiChar
|
||||
%token <id> tkAbstract tkForward tkOverload tkReintroduce tkOverride tkVirtual tkExtensionMethod
|
||||
%token <ex> tkInteger tkFloat tkHex
|
||||
|
||||
|
|
@ -3317,6 +3317,17 @@ literal
|
|||
{
|
||||
$$ = NewLiteral($1 as literal_const_line);
|
||||
}
|
||||
| tkFormatStringLiteral
|
||||
{
|
||||
if (parsertools.build_tree_for_formatter)
|
||||
{
|
||||
$$ = $1 as string_const;
|
||||
}
|
||||
else
|
||||
{
|
||||
$$ = NewFormatString($1 as string_const);
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
literal_list
|
||||
|
|
|
|||
|
|
@ -411,7 +411,16 @@ namespace PascalABCSavParser
|
|||
lt.source_context = sc;
|
||||
return lt;
|
||||
}
|
||||
|
||||
|
||||
public literal create_format_string_const(string text, SourceContext sc)
|
||||
{
|
||||
literal lt;
|
||||
text = ReplaceSpecialSymbols(text.Substring(2, text.Length - 3));
|
||||
lt = new string_const(text);
|
||||
lt.source_context = sc;
|
||||
return lt;
|
||||
}
|
||||
|
||||
public procedure_definition lambda(function_lambda_definition _function_lambda_definition)
|
||||
{
|
||||
procedure_definition _func_def = new procedure_definition();
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -64,6 +64,13 @@ namespace PascalABCCompiler.Errors
|
|||
{
|
||||
}
|
||||
}
|
||||
public class bad_format_string : SyntaxError
|
||||
{
|
||||
public bad_format_string(string _file_name, SourceContext _source_context, syntax_tree_node _node) :
|
||||
base(PascalABCSavParser.StringResources.Get("BAD_FORMAT_STRING"), _file_name, _source_context, _node)
|
||||
{
|
||||
}
|
||||
}
|
||||
public class PABCNETUnexpectedToken : SyntaxError
|
||||
{
|
||||
private string _message;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using PascalABCCompiler.SyntaxTree;
|
|||
using PascalABCSavParser;
|
||||
using PascalABCCompiler.ParserTools;
|
||||
using PascalABCCompiler.Errors;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace GPPGParserScanner
|
||||
{
|
||||
|
|
@ -380,6 +381,86 @@ namespace GPPGParserScanner
|
|||
return lcl.literals[0];
|
||||
return lcl;
|
||||
}
|
||||
|
||||
public expression NewFormatString(string_const str)
|
||||
{
|
||||
try
|
||||
{
|
||||
method_call mc = new method_call();
|
||||
mc.dereferencing_value = new dot_node(new ident("string", str.source_context), new ident("Format", str.source_context), str.source_context);
|
||||
mc.parameters = new expression_list();
|
||||
string[] arr = Regex.Split(str.Value, @"\{[\w\d._]+\}");
|
||||
Match match = Regex.Match(str.Value, @"\{[\w\d._]+\}");
|
||||
List<string> vars = new List<string>();
|
||||
Dictionary<string, int> var_offsets = new Dictionary<string, int>();
|
||||
while (match.Success)
|
||||
{
|
||||
string s = match.Value.Replace("{", "").Replace("}", "");
|
||||
vars.Add(s);
|
||||
var_offsets.Add(s, match.Index);
|
||||
match = match.NextMatch();
|
||||
}
|
||||
if (vars.Count == 0)
|
||||
{
|
||||
parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str));
|
||||
return str;
|
||||
}
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < arr.Length; i++)
|
||||
{
|
||||
sb.Append(arr[i]);
|
||||
if (i < arr.Length - 1)
|
||||
sb.Append("{" + i + "}");
|
||||
}
|
||||
mc.parameters.Add(new string_const(sb.ToString(), str.source_context), str.source_context);
|
||||
foreach (string s in vars)
|
||||
{
|
||||
SourceContext sc = new SourceContext(str.source_context);
|
||||
sc.begin_position.column_num += var_offsets[s] + 2;
|
||||
sc.end_position.column_num = sc.begin_position.column_num + s.Length;
|
||||
string[] words = s.Split('.');
|
||||
dot_node dn = null;
|
||||
ident id = null;
|
||||
int offset = 0;
|
||||
foreach (string word in words)
|
||||
{
|
||||
if (string.IsNullOrEmpty(word) || char.IsDigit(word[0]))
|
||||
{
|
||||
parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str));
|
||||
return str;
|
||||
}
|
||||
if (id == null)
|
||||
{
|
||||
id = new ident(word, sc);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (dn == null)
|
||||
{
|
||||
dn = new dot_node(id, new ident(word, sc), sc);
|
||||
}
|
||||
else
|
||||
{
|
||||
dn = new dot_node(dn, new ident(word, sc), sc);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (dn != null)
|
||||
mc.parameters.Add(dn, sc);
|
||||
else
|
||||
mc.parameters.Add(id, sc);
|
||||
}
|
||||
|
||||
mc.source_context = str.source_context;
|
||||
return mc;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str));
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
public var_def_statement NewVarOrIdentifier(ident identifier, named_type_reference fptype, LexLocation loc)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -210,6 +210,10 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
{
|
||||
return _line_num;
|
||||
}
|
||||
set
|
||||
{
|
||||
_line_num = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int column_num
|
||||
|
|
@ -218,6 +222,10 @@ namespace PascalABCCompiler.SyntaxTree
|
|||
{
|
||||
return _column_num;
|
||||
}
|
||||
set
|
||||
{
|
||||
_column_num = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
11
TestSuite/formatstring1.pas
Normal file
11
TestSuite/formatstring1.pas
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
type
|
||||
TRec = record
|
||||
a: integer;
|
||||
end;
|
||||
|
||||
begin
|
||||
var x: TRec;
|
||||
x.a := 2;
|
||||
var s := $'Hello {x.a}';
|
||||
assert(s = 'Hello 2');
|
||||
end.
|
||||
9
TestSuite/formatstring2.pas
Normal file
9
TestSuite/formatstring2.pas
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
begin
|
||||
var a := 2;
|
||||
var b := 3;
|
||||
var c := 4;
|
||||
var s := $'Hello {a}';
|
||||
assert(s = 'Hello 2');
|
||||
s := $'{a},{b},{c}';
|
||||
assert(s = '2,3,4');
|
||||
end.
|
||||
11
TestSuite/formatter_tests/input/formatstring1.pas
Normal file
11
TestSuite/formatter_tests/input/formatstring1.pas
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
type
|
||||
TRec = record
|
||||
a: integer;
|
||||
end;
|
||||
|
||||
begin
|
||||
var x: TRec;
|
||||
x.a := 2;
|
||||
var s := $'Hello {x.a}';
|
||||
assert(s = 'Hello 2');
|
||||
end.
|
||||
9
TestSuite/formatter_tests/input/formatstring2.pas
Normal file
9
TestSuite/formatter_tests/input/formatstring2.pas
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
begin
|
||||
var a := 2;
|
||||
var b := 3;
|
||||
var c := 4;
|
||||
var s := $'Hello {a}';
|
||||
assert(s = 'Hello 2');
|
||||
s := $'{a},{b},{c}';
|
||||
assert(s = '2,3,4');
|
||||
end.
|
||||
|
|
@ -60,3 +60,4 @@ USING_UNLOCAL_FOR_VARIABLE=Cycle counter variable should be declared in for cycl
|
|||
USING_UNLOCAL_FOREACH_VARIABLE=Cycle counter variable should be declared in foreach cycle
|
||||
OVERLOAD_IS_NOT_USED=overload is not used in PascalABC.NET
|
||||
ONLY_BASE_ASSIGNMENT_FOR_TUPLE=Tuple allows only base assignment :=
|
||||
BAD_FORMAT_STRING=Interpolated string has invalid format
|
||||
|
|
|
|||
|
|
@ -59,3 +59,4 @@ USING_UNLOCAL_FOR_VARIABLE=Параметр цикла for в PascalABC.NET до
|
|||
USING_UNLOCAL_FOREACH_VARIABLE=Параметр цикла foreach должен описываться в заголовке цикла
|
||||
OVERLOAD_IS_NOT_USED=overload не используется в PascalABC.NET
|
||||
ONLY_BASE_ASSIGNMENT_FOR_TUPLE=Для кортежа допустимо только обычное присваивание :=
|
||||
BAD_FORMAT_STRING=Встречена неправильная форматная строка
|
||||
|
|
|
|||
Loading…
Reference in a new issue