diff --git a/examples/test/misc/hello_world.das b/examples/test/misc/hello_world.das index 46171eb62..1cf428c55 100644 --- a/examples/test/misc/hello_world.das +++ b/examples/test/misc/hello_world.das @@ -365,6 +365,21 @@ def test_typeinfo( arg : int ) { debug(c); } +///////////////// +// string builder + +[export] +def test_string_builder ( arg,arg2:int ) { + let a = ""; + debug(a); + let b = "hello, world!"; + debug(b); + let c = "arg={arg}\n"; + debug(c); + let d = "{arg} + {arg2} = {arg+arg2}"; + debug(d); +} + /////// // main diff --git a/src/parser/ds2_parser.cpp b/src/parser/ds2_parser.cpp index 88de6b70d..e84eb377b 100644 --- a/src/parser/ds2_parser.cpp +++ b/src/parser/ds2_parser.cpp @@ -1006,83 +1006,83 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_int16 yyrline[] = { - 0, 524, 524, 525, 530, 531, 532, 533, 534, 535, - 536, 537, 538, 539, 540, 541, 542, 546, 552, 553, - 554, 558, 559, 563, 581, 582, 583, 584, 588, 592, - 597, 606, 614, 630, 635, 643, 643, 682, 700, 704, - 707, 711, 717, 726, 729, 735, 736, 740, 744, 745, - 749, 752, 758, 764, 767, 773, 774, 778, 779, 780, - 789, 790, 794, 795, 801, 802, 803, 804, 805, 809, - 815, 821, 827, 835, 845, 854, 861, 862, 863, 864, - 865, 866, 870, 875, 883, 884, 885, 889, 890, 891, - 892, 893, 894, 895, 896, 902, 905, 911, 914, 920, - 921, 922, 926, 939, 957, 960, 968, 979, 990, 1001, - 1004, 1011, 1015, 1022, 1023, 1027, 1028, 1029, 1033, 1036, - 1043, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, - 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, - 1066, 1067, 1068, 1069, 1070, 1071, 1072, 1073, 1074, 1075, - 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, - 1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, - 1096, 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, - 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, - 1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, - 1126, 1127, 1128, 1129, 1130, 1135, 1153, 1154, 1155, 1159, - 1165, 1165, 1182, 1186, 1197, 1210, 1211, 1212, 1213, 1214, - 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, - 1225, 1226, 1227, 1231, 1236, 1242, 1248, 1249, 1253, 1257, - 1264, 1265, 1276, 1280, 1283, 1291, 1291, 1291, 1297, 1300, - 1304, 1308, 1315, 1321, 1325, 1329, 1332, 1335, 1343, 1346, - 1354, 1360, 1361, 1362, 1366, 1367, 1371, 1372, 1376, 1381, - 1389, 1395, 1407, 1410, 1416, 1416, 1416, 1419, 1419, 1419, - 1424, 1424, 1424, 1432, 1432, 1432, 1438, 1448, 1459, 1474, - 1477, 1483, 1484, 1491, 1502, 1503, 1504, 1508, 1509, 1510, - 1511, 1515, 1520, 1528, 1529, 1533, 1540, 1544, 1550, 1551, - 1552, 1553, 1554, 1555, 1556, 1560, 1561, 1562, 1563, 1564, - 1565, 1566, 1567, 1568, 1569, 1570, 1571, 1572, 1573, 1574, - 1575, 1576, 1577, 1578, 1582, 1589, 1601, 1606, 1616, 1620, - 1627, 1630, 1630, 1630, 1635, 1635, 1635, 1648, 1652, 1656, - 1661, 1668, 1668, 1668, 1675, 1679, 1688, 1692, 1695, 1701, - 1702, 1703, 1704, 1705, 1706, 1707, 1708, 1709, 1710, 1711, - 1712, 1713, 1714, 1715, 1716, 1717, 1718, 1719, 1720, 1721, - 1722, 1723, 1724, 1725, 1726, 1727, 1728, 1729, 1730, 1731, - 1732, 1733, 1734, 1735, 1736, 1742, 1743, 1744, 1745, 1746, - 1759, 1760, 1761, 1762, 1763, 1764, 1765, 1766, 1767, 1768, - 1769, 1770, 1773, 1776, 1777, 1780, 1780, 1780, 1783, 1788, - 1792, 1796, 1796, 1796, 1801, 1804, 1808, 1808, 1808, 1813, - 1816, 1817, 1818, 1819, 1820, 1821, 1822, 1823, 1824, 1826, - 1830, 1834, 1835, 1836, 1837, 1838, 1839, 1840, 1844, 1848, - 1852, 1856, 1860, 1864, 1868, 1872, 1876, 1883, 1884, 1888, - 1889, 1890, 1894, 1895, 1899, 1900, 1901, 1905, 1906, 1910, - 1921, 1924, 1924, 1943, 1942, 1956, 1955, 1971, 1980, 1990, - 1991, 1995, 1998, 2007, 2008, 2012, 2015, 2018, 2034, 2043, - 2044, 2048, 2051, 2054, 2068, 2069, 2073, 2079, 2085, 2088, - 2092, 2101, 2102, 2103, 2107, 2108, 2112, 2119, 2124, 2133, - 2139, 2150, 2153, 2158, 2169, 2172, 2172, 2192, 2193, 2197, - 2198, 2199, 2203, 2206, 2206, 2224, 2228, 2235, 2238, 2251, - 2268, 2269, 2270, 2275, 2275, 2301, 2305, 2306, 2307, 2311, - 2321, 2324, 2330, 2335, 2330, 2350, 2351, 2355, 2356, 2360, - 2366, 2367, 2371, 2372, 2373, 2377, 2380, 2386, 2391, 2386, - 2405, 2412, 2417, 2426, 2432, 2443, 2444, 2445, 2446, 2447, - 2448, 2449, 2450, 2451, 2452, 2453, 2454, 2455, 2456, 2457, - 2458, 2459, 2460, 2461, 2462, 2463, 2464, 2465, 2466, 2467, - 2468, 2469, 2473, 2474, 2475, 2476, 2477, 2478, 2479, 2480, - 2484, 2495, 2499, 2506, 2518, 2525, 2534, 2539, 2549, 2562, - 2562, 2562, 2575, 2579, 2586, 2590, 2594, 2598, 2605, 2608, - 2626, 2627, 2628, 2629, 2630, 2630, 2630, 2634, 2639, 2646, - 2646, 2653, 2657, 2661, 2666, 2671, 2676, 2681, 2685, 2689, - 2694, 2698, 2702, 2707, 2707, 2707, 2713, 2720, 2720, 2720, - 2725, 2725, 2725, 2731, 2731, 2731, 2736, 2740, 2740, 2740, - 2745, 2745, 2745, 2754, 2758, 2758, 2758, 2763, 2763, 2763, - 2772, 2776, 2776, 2776, 2781, 2781, 2781, 2790, 2790, 2790, - 2796, 2796, 2796, 2805, 2808, 2819, 2835, 2840, 2845, 2835, - 2870, 2875, 2881, 2870, 2906, 2911, 2916, 2906, 2946, 2947, - 2948, 2949, 2950, 2954, 2961, 2968, 2974, 2980, 2987, 2994, - 3000, 3010, 3018, 3023, 3030, 3031, 3035, 3035, 3035, 3043, - 3043, 3043, 3050, 3050, 3050, 3057, 3057, 3057, 3068, 3074, - 3080, 3086, 3086, 3086, 3096, 3104, 3104, 3104, 3114, 3114, - 3114, 3124, 3124, 3124, 3134, 3142, 3142, 3142, 3150, 3157, - 3157, 3157, 3167, 3170, 3176, 3184, 3192, 3200, 3213, 3214, - 3218, 3219, 3224, 3227, 3230 + 0, 527, 527, 528, 533, 534, 535, 536, 537, 538, + 539, 540, 541, 542, 543, 544, 545, 549, 555, 556, + 557, 561, 562, 566, 584, 585, 586, 587, 591, 595, + 600, 609, 617, 633, 638, 646, 646, 685, 703, 707, + 710, 714, 720, 729, 732, 738, 739, 743, 747, 748, + 752, 755, 761, 767, 770, 776, 777, 781, 782, 783, + 792, 793, 797, 798, 804, 805, 806, 807, 808, 812, + 818, 824, 830, 838, 848, 857, 864, 865, 866, 867, + 868, 869, 873, 878, 886, 887, 888, 892, 893, 894, + 895, 896, 897, 898, 899, 905, 908, 914, 917, 923, + 924, 925, 929, 942, 960, 963, 971, 982, 993, 1004, + 1007, 1014, 1018, 1025, 1026, 1030, 1031, 1032, 1036, 1039, + 1046, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, + 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, + 1069, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, + 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, + 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, + 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, + 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, + 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, + 1129, 1130, 1131, 1132, 1133, 1138, 1156, 1157, 1158, 1162, + 1168, 1168, 1185, 1189, 1200, 1213, 1214, 1215, 1216, 1217, + 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226, 1227, + 1228, 1229, 1230, 1234, 1239, 1245, 1251, 1252, 1256, 1260, + 1267, 1268, 1279, 1283, 1286, 1294, 1294, 1294, 1300, 1303, + 1307, 1311, 1318, 1324, 1328, 1332, 1335, 1338, 1346, 1349, + 1357, 1363, 1364, 1365, 1369, 1370, 1374, 1375, 1379, 1384, + 1392, 1398, 1410, 1413, 1419, 1419, 1419, 1422, 1422, 1422, + 1427, 1427, 1427, 1435, 1435, 1435, 1441, 1451, 1462, 1477, + 1480, 1486, 1487, 1494, 1505, 1506, 1507, 1511, 1512, 1513, + 1514, 1518, 1523, 1531, 1532, 1536, 1543, 1547, 1553, 1554, + 1555, 1556, 1557, 1558, 1559, 1563, 1564, 1565, 1566, 1567, + 1568, 1569, 1570, 1571, 1572, 1573, 1574, 1575, 1576, 1577, + 1578, 1579, 1580, 1581, 1585, 1592, 1604, 1609, 1619, 1623, + 1630, 1633, 1633, 1633, 1638, 1638, 1638, 1651, 1655, 1659, + 1664, 1671, 1671, 1671, 1678, 1682, 1691, 1695, 1698, 1704, + 1705, 1706, 1707, 1708, 1709, 1710, 1711, 1712, 1713, 1714, + 1715, 1716, 1717, 1718, 1719, 1720, 1721, 1722, 1723, 1724, + 1725, 1726, 1727, 1728, 1729, 1730, 1731, 1732, 1733, 1734, + 1735, 1736, 1737, 1738, 1739, 1745, 1746, 1747, 1748, 1749, + 1762, 1763, 1764, 1765, 1766, 1767, 1768, 1769, 1770, 1771, + 1772, 1773, 1776, 1779, 1780, 1783, 1783, 1783, 1786, 1791, + 1795, 1799, 1799, 1799, 1804, 1807, 1811, 1811, 1811, 1816, + 1819, 1820, 1821, 1822, 1823, 1824, 1825, 1826, 1827, 1829, + 1833, 1837, 1838, 1839, 1840, 1841, 1842, 1843, 1847, 1851, + 1855, 1859, 1863, 1867, 1871, 1875, 1879, 1886, 1887, 1891, + 1892, 1893, 1897, 1898, 1902, 1903, 1904, 1908, 1909, 1913, + 1924, 1927, 1927, 1946, 1945, 1959, 1958, 1974, 1983, 1993, + 1994, 1998, 2001, 2010, 2011, 2015, 2018, 2021, 2037, 2046, + 2047, 2051, 2054, 2057, 2071, 2072, 2076, 2082, 2088, 2091, + 2095, 2104, 2105, 2106, 2110, 2111, 2115, 2122, 2127, 2136, + 2142, 2153, 2156, 2161, 2172, 2175, 2175, 2195, 2196, 2200, + 2201, 2202, 2206, 2209, 2209, 2227, 2231, 2238, 2241, 2254, + 2271, 2272, 2273, 2278, 2278, 2304, 2308, 2309, 2310, 2314, + 2324, 2327, 2333, 2338, 2333, 2353, 2354, 2358, 2359, 2363, + 2369, 2370, 2374, 2375, 2376, 2380, 2383, 2389, 2394, 2389, + 2408, 2415, 2420, 2429, 2435, 2446, 2447, 2448, 2449, 2450, + 2451, 2452, 2453, 2454, 2455, 2456, 2457, 2458, 2459, 2460, + 2461, 2462, 2463, 2464, 2465, 2466, 2467, 2468, 2469, 2470, + 2471, 2472, 2476, 2477, 2478, 2479, 2480, 2481, 2482, 2483, + 2487, 2498, 2502, 2509, 2521, 2528, 2537, 2542, 2552, 2565, + 2565, 2565, 2578, 2582, 2589, 2593, 2597, 2601, 2608, 2611, + 2629, 2630, 2631, 2632, 2633, 2633, 2633, 2637, 2642, 2649, + 2649, 2656, 2660, 2664, 2669, 2674, 2679, 2684, 2688, 2692, + 2697, 2701, 2705, 2710, 2710, 2710, 2716, 2723, 2723, 2723, + 2728, 2728, 2728, 2734, 2734, 2734, 2739, 2743, 2743, 2743, + 2748, 2748, 2748, 2757, 2761, 2761, 2761, 2766, 2766, 2766, + 2775, 2779, 2779, 2779, 2784, 2784, 2784, 2793, 2793, 2793, + 2799, 2799, 2799, 2808, 2811, 2822, 2838, 2843, 2848, 2838, + 2873, 2878, 2884, 2873, 2909, 2914, 2919, 2909, 2949, 2950, + 2951, 2952, 2953, 2957, 2964, 2971, 2977, 2983, 2990, 2997, + 3003, 3013, 3021, 3026, 3033, 3034, 3038, 3038, 3038, 3046, + 3046, 3046, 3053, 3053, 3053, 3060, 3060, 3060, 3071, 3077, + 3083, 3089, 3089, 3089, 3099, 3107, 3107, 3107, 3117, 3117, + 3117, 3127, 3127, 3127, 3137, 3145, 3145, 3145, 3153, 3160, + 3160, 3160, 3170, 3173, 3179, 3187, 3195, 3203, 3216, 3217, + 3221, 3222, 3227, 3230, 3233 }; #endif @@ -5401,19 +5401,19 @@ YYLTYPE yylloc = yyloc_default; break; case 24: /* character_sequence: STRING_CHARACTER */ - { (yyval.s) = new string(); *(yyval.s) += (yyvsp[0].ch); } + { (yyval.s) = new string(); *(yyval.s) += (yyvsp[0].ch); } break; case 25: /* character_sequence: STRING_CHARACTER_ESC */ - { (yyval.s) = new string(); *(yyval.s) += "\\\\"; } + { (yyval.s) = new string(); *(yyval.s) += "\\\\"; } break; case 26: /* character_sequence: character_sequence STRING_CHARACTER */ - { (yyval.s) = (yyvsp[-1].s); *(yyvsp[-1].s) += (yyvsp[0].ch); } + { (yyval.s) = (yyvsp[-1].s); *(yyvsp[-1].s) += (yyvsp[0].ch); } break; case 27: /* character_sequence: character_sequence STRING_CHARACTER_ESC */ - { (yyval.s) = (yyvsp[-1].s); *(yyvsp[-1].s) += "\\\\"; } + { (yyval.s) = (yyvsp[-1].s); *(yyvsp[-1].s) += "\\\\"; } break; case 28: /* string_constant: "start of the string" character_sequence "end of the string" */ @@ -5429,7 +5429,7 @@ YYLTYPE yylloc = yyloc_default; break; case 30: /* string_builder_body: string_builder_body character_sequence */ - { + { bool err; auto esconst = unescapeString(*(yyvsp[0].s),&err); if ( err ) das2_yyerror(scanner,"invalid escape sequence",tokAt(scanner,(yylsp[-1])), CompilationError::invalid_escape_sequence); @@ -5441,7 +5441,7 @@ YYLTYPE yylloc = yyloc_default; break; case 31: /* string_builder_body: string_builder_body "{" expr "}" */ - { + { auto se = ExpressionPtr((yyvsp[-1].pExpression)); static_cast((yyvsp[-3].pExpression))->elements.push_back(se); (yyval.pExpression) = (yyvsp[-3].pExpression); diff --git a/src/parser/ds2_parser.output b/src/parser/ds2_parser.output index 644f05ad0..ed5933ebf 100644 --- a/src/parser/ds2_parser.output +++ b/src/parser/ds2_parser.output @@ -13,7 +13,6 @@ Terminals unused in grammar State 464 conflicts: 1 shift/reduce State 471 conflicts: 1 shift/reduce State 640 conflicts: 1 shift/reduce -State 814 conflicts: 2 shift/reduce Grammar @@ -23141,9 +23140,7 @@ State 814 STRING_CHARACTER shift, and go to state 211 STRING_CHARACTER_ESC shift, and go to state 212 - STRING_CHARACTER [reduce using rule 29 (string_builder_body)] - STRING_CHARACTER_ESC [reduce using rule 29 (string_builder_body)] - $default reduce using rule 29 (string_builder_body) + $default reduce using rule 29 (string_builder_body) State 815 diff --git a/src/parser/ds2_parser.ypp b/src/parser/ds2_parser.ypp index a1c8afe10..89faf17bf 100644 --- a/src/parser/ds2_parser.ypp +++ b/src/parser/ds2_parser.ypp @@ -518,6 +518,9 @@ %nonassoc '$' '@' %nonassoc COLCOL +%right STRING_CHARACTER STRING_CHARACTER_ESC +%right BEGIN_STRING_EXPR END_STRING_EXPR + %% program @@ -578,10 +581,10 @@ module_declaration ; character_sequence - : STRING_CHARACTER[char] { $$ = new string(); *$$ += $char; } - | STRING_CHARACTER_ESC { $$ = new string(); *$$ += "\\\\"; } - | character_sequence[elem] STRING_CHARACTER[char] { $$ = $elem; *$elem += $char; } - | character_sequence[elem] STRING_CHARACTER_ESC { $$ = $elem; *$elem += "\\\\"; } + : STRING_CHARACTER[char] { $$ = new string(); *$$ += $char; } + | STRING_CHARACTER_ESC { $$ = new string(); *$$ += "\\\\"; } + | character_sequence[elem] STRING_CHARACTER[char] %prec STRING_CHARACTER { $$ = $elem; *$elem += $char; } + | character_sequence[elem] STRING_CHARACTER_ESC %prec STRING_CHARACTER { $$ = $elem; *$elem += "\\\\"; } ; string_constant @@ -594,7 +597,7 @@ string_builder_body $$->at = LineInfo(yyextra->g_FileAccessStack.back(), yylloc.first_column,yylloc.first_line,yylloc.last_column,yylloc.last_line); } - | string_builder_body[sb] character_sequence[sconst] { + | string_builder_body[sb] character_sequence[sconst] %prec STRING_CHARACTER { bool err; auto esconst = unescapeString(*$sconst,&err); if ( err ) das2_yyerror(scanner,"invalid escape sequence",tokAt(scanner,@sb), CompilationError::invalid_escape_sequence); @@ -603,7 +606,7 @@ string_builder_body static_cast($sb)->elements.push_back(sc); $$ = $sb; } - | string_builder_body[sb] BEGIN_STRING_EXPR expr[subexpr] END_STRING_EXPR { + | string_builder_body[sb] BEGIN_STRING_EXPR expr[subexpr] END_STRING_EXPR %prec BEGIN_STRING_EXPR { auto se = ExpressionPtr($subexpr); static_cast($sb)->elements.push_back(se); $$ = $sb; diff --git a/src/parser/ds_parser.cpp b/src/parser/ds_parser.cpp index e6be26999..19d9a6dd2 100644 --- a/src/parser/ds_parser.cpp +++ b/src/parser/ds_parser.cpp @@ -1047,93 +1047,93 @@ static const yytype_uint8 yytranslate[] = /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */ static const yytype_int16 yyrline[] = { - 0, 534, 534, 535, 540, 541, 542, 543, 544, 545, - 546, 547, 548, 549, 550, 551, 552, 556, 562, 563, - 564, 568, 569, 573, 591, 592, 593, 594, 598, 602, - 607, 616, 624, 640, 645, 653, 653, 692, 722, 726, - 727, 728, 732, 735, 739, 745, 754, 757, 763, 764, - 768, 772, 773, 777, 780, 786, 792, 795, 801, 802, - 806, 807, 808, 817, 818, 822, 823, 823, 829, 830, - 831, 832, 833, 837, 843, 843, 849, 849, 855, 863, - 873, 882, 882, 889, 890, 891, 892, 893, 894, 898, - 903, 911, 912, 913, 917, 918, 919, 920, 921, 922, - 923, 924, 930, 933, 939, 942, 948, 949, 950, 954, - 967, 985, 988, 996, 1007, 1018, 1029, 1032, 1039, 1043, - 1050, 1051, 1055, 1056, 1057, 1061, 1064, 1071, 1075, 1076, - 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, - 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, - 1097, 1098, 1099, 1100, 1101, 1102, 1103, 1104, 1105, 1106, - 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, - 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, - 1127, 1128, 1129, 1130, 1131, 1132, 1133, 1134, 1135, 1136, - 1137, 1138, 1139, 1140, 1141, 1142, 1143, 1144, 1145, 1146, - 1147, 1148, 1149, 1150, 1151, 1152, 1153, 1154, 1155, 1156, - 1157, 1158, 1163, 1181, 1182, 1183, 1187, 1193, 1193, 1210, - 1214, 1225, 1234, 1246, 1247, 1248, 1249, 1250, 1251, 1252, - 1253, 1254, 1255, 1256, 1257, 1258, 1259, 1260, 1261, 1262, - 1263, 1264, 1265, 1266, 1270, 1275, 1281, 1287, 1298, 1299, - 1303, 1304, 1308, 1312, 1319, 1319, 1319, 1325, 1325, 1325, - 1334, 1368, 1371, 1374, 1377, 1383, 1384, 1395, 1399, 1402, - 1410, 1410, 1410, 1413, 1419, 1422, 1426, 1430, 1437, 1443, - 1447, 1451, 1454, 1457, 1465, 1468, 1471, 1479, 1482, 1490, - 1493, 1496, 1504, 1510, 1511, 1512, 1516, 1517, 1521, 1522, - 1526, 1531, 1539, 1545, 1551, 1560, 1572, 1575, 1581, 1581, - 1581, 1584, 1584, 1584, 1589, 1589, 1589, 1597, 1597, 1597, - 1603, 1613, 1624, 1637, 1647, 1658, 1673, 1676, 1682, 1683, - 1690, 1701, 1702, 1703, 1707, 1708, 1709, 1710, 1714, 1719, - 1727, 1728, 1732, 1737, 1744, 1751, 1751, 1760, 1761, 1762, - 1763, 1764, 1765, 1766, 1770, 1771, 1772, 1773, 1774, 1775, - 1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, - 1786, 1787, 1788, 1792, 1793, 1794, 1795, 1800, 1801, 1802, - 1803, 1804, 1805, 1806, 1807, 1808, 1809, 1810, 1811, 1812, - 1813, 1814, 1815, 1816, 1821, 1828, 1840, 1845, 1855, 1859, - 1866, 1869, 1869, 1869, 1874, 1874, 1874, 1887, 1891, 1895, - 1900, 1907, 1907, 1907, 1914, 1918, 1927, 1931, 1934, 1940, - 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950, - 1951, 1952, 1953, 1954, 1955, 1956, 1957, 1958, 1959, 1960, - 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, - 1971, 1972, 1973, 1974, 1975, 1981, 1982, 1983, 1984, 1985, - 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, - 2008, 2009, 2012, 2015, 2016, 2019, 2019, 2019, 2022, 2027, - 2031, 2035, 2035, 2035, 2040, 2043, 2047, 2047, 2047, 2052, - 2055, 2056, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2065, - 2069, 2070, 2075, 2079, 2080, 2081, 2082, 2083, 2084, 2085, - 2089, 2093, 2097, 2101, 2105, 2109, 2113, 2117, 2121, 2128, - 2129, 2130, 2134, 2135, 2136, 2140, 2141, 2145, 2146, 2147, - 2151, 2152, 2156, 2167, 2170, 2170, 2189, 2188, 2203, 2202, - 2215, 2224, 2233, 2243, 2244, 2248, 2251, 2260, 2261, 2265, - 2268, 2271, 2287, 2296, 2297, 2301, 2304, 2307, 2321, 2322, - 2326, 2332, 2338, 2341, 2345, 2351, 2360, 2361, 2362, 2366, - 2367, 2371, 2378, 2383, 2392, 2398, 2409, 2412, 2417, 2422, - 2430, 2441, 2444, 2444, 2464, 2465, 2469, 2470, 2471, 2475, - 2478, 2478, 2497, 2500, 2503, 2518, 2537, 2538, 2539, 2544, - 2544, 2570, 2571, 2575, 2576, 2576, 2580, 2581, 2582, 2586, - 2596, 2601, 2596, 2613, 2618, 2613, 2633, 2634, 2638, 2639, - 2643, 2649, 2650, 2654, 2655, 2656, 2660, 2663, 2669, 2674, - 2669, 2688, 2695, 2700, 2709, 2715, 2726, 2727, 2728, 2729, - 2730, 2731, 2732, 2733, 2734, 2735, 2736, 2737, 2738, 2739, - 2740, 2741, 2742, 2743, 2744, 2745, 2746, 2747, 2748, 2749, - 2750, 2751, 2752, 2756, 2757, 2758, 2759, 2760, 2761, 2762, - 2763, 2767, 2778, 2782, 2789, 2801, 2808, 2817, 2822, 2825, - 2838, 2838, 2838, 2851, 2855, 2862, 2866, 2873, 2874, 2875, - 2876, 2877, 2892, 2898, 2898, 2898, 2902, 2907, 2914, 2914, - 2921, 2925, 2929, 2934, 2939, 2944, 2949, 2953, 2957, 2962, - 2966, 2970, 2975, 2975, 2975, 2981, 2988, 2988, 2988, 2993, - 2993, 2993, 2999, 2999, 2999, 3004, 3008, 3008, 3008, 3013, - 3013, 3013, 3022, 3026, 3026, 3026, 3031, 3031, 3031, 3040, - 3044, 3044, 3044, 3049, 3049, 3049, 3058, 3058, 3058, 3064, - 3064, 3064, 3073, 3076, 3087, 3103, 3103, 3108, 3113, 3103, - 3138, 3138, 3143, 3149, 3138, 3174, 3174, 3179, 3184, 3174, - 3214, 3215, 3216, 3217, 3218, 3222, 3229, 3236, 3242, 3248, - 3255, 3262, 3268, 3278, 3286, 3291, 3298, 3299, 3304, 3305, - 3309, 3310, 3314, 3315, 3319, 3320, 3321, 3325, 3326, 3327, - 3331, 3332, 3336, 3342, 3349, 3357, 3364, 3372, 3381, 3381, - 3381, 3389, 3389, 3389, 3396, 3396, 3396, 3403, 3403, 3403, - 3414, 3417, 3423, 3437, 3443, 3449, 3455, 3455, 3455, 3465, - 3470, 3477, 3485, 3490, 3497, 3497, 3497, 3507, 3507, 3507, - 3517, 3517, 3517, 3527, 3535, 3535, 3535, 3543, 3550, 3550, - 3550, 3560, 3565, 3572, 3575, 3581, 3589, 3598, 3606, 3614, - 3627, 3628, 3632, 3633, 3638, 3641, 3644, 3647, 3650, 3653 + 0, 537, 537, 538, 543, 544, 545, 546, 547, 548, + 549, 550, 551, 552, 553, 554, 555, 559, 565, 566, + 567, 571, 572, 576, 594, 595, 596, 597, 601, 605, + 610, 619, 627, 643, 648, 656, 656, 695, 725, 729, + 730, 731, 735, 738, 742, 748, 757, 760, 766, 767, + 771, 775, 776, 780, 783, 789, 795, 798, 804, 805, + 809, 810, 811, 820, 821, 825, 826, 826, 832, 833, + 834, 835, 836, 840, 846, 846, 852, 852, 858, 866, + 876, 885, 885, 892, 893, 894, 895, 896, 897, 901, + 906, 914, 915, 916, 920, 921, 922, 923, 924, 925, + 926, 927, 933, 936, 942, 945, 951, 952, 953, 957, + 970, 988, 991, 999, 1010, 1021, 1032, 1035, 1042, 1046, + 1053, 1054, 1058, 1059, 1060, 1064, 1067, 1074, 1078, 1079, + 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, + 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, + 1100, 1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, + 1110, 1111, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, + 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, + 1130, 1131, 1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, + 1140, 1141, 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149, + 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1159, + 1160, 1161, 1166, 1184, 1185, 1186, 1190, 1196, 1196, 1213, + 1217, 1228, 1237, 1249, 1250, 1251, 1252, 1253, 1254, 1255, + 1256, 1257, 1258, 1259, 1260, 1261, 1262, 1263, 1264, 1265, + 1266, 1267, 1268, 1269, 1273, 1278, 1284, 1290, 1301, 1302, + 1306, 1307, 1311, 1315, 1322, 1322, 1322, 1328, 1328, 1328, + 1337, 1371, 1374, 1377, 1380, 1386, 1387, 1398, 1402, 1405, + 1413, 1413, 1413, 1416, 1422, 1425, 1429, 1433, 1440, 1446, + 1450, 1454, 1457, 1460, 1468, 1471, 1474, 1482, 1485, 1493, + 1496, 1499, 1507, 1513, 1514, 1515, 1519, 1520, 1524, 1525, + 1529, 1534, 1542, 1548, 1554, 1563, 1575, 1578, 1584, 1584, + 1584, 1587, 1587, 1587, 1592, 1592, 1592, 1600, 1600, 1600, + 1606, 1616, 1627, 1640, 1650, 1661, 1676, 1679, 1685, 1686, + 1693, 1704, 1705, 1706, 1710, 1711, 1712, 1713, 1717, 1722, + 1730, 1731, 1735, 1740, 1747, 1754, 1754, 1763, 1764, 1765, + 1766, 1767, 1768, 1769, 1773, 1774, 1775, 1776, 1777, 1778, + 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, + 1789, 1790, 1791, 1795, 1796, 1797, 1798, 1803, 1804, 1805, + 1806, 1807, 1808, 1809, 1810, 1811, 1812, 1813, 1814, 1815, + 1816, 1817, 1818, 1819, 1824, 1831, 1843, 1848, 1858, 1862, + 1869, 1872, 1872, 1872, 1877, 1877, 1877, 1890, 1894, 1898, + 1903, 1910, 1910, 1910, 1917, 1921, 1930, 1934, 1937, 1943, + 1944, 1945, 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953, + 1954, 1955, 1956, 1957, 1958, 1959, 1960, 1961, 1962, 1963, + 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, 1972, 1973, + 1974, 1975, 1976, 1977, 1978, 1984, 1985, 1986, 1987, 1988, + 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, + 2011, 2012, 2015, 2018, 2019, 2022, 2022, 2022, 2025, 2030, + 2034, 2038, 2038, 2038, 2043, 2046, 2050, 2050, 2050, 2055, + 2058, 2059, 2060, 2061, 2062, 2063, 2064, 2065, 2066, 2068, + 2072, 2073, 2078, 2082, 2083, 2084, 2085, 2086, 2087, 2088, + 2092, 2096, 2100, 2104, 2108, 2112, 2116, 2120, 2124, 2131, + 2132, 2133, 2137, 2138, 2139, 2143, 2144, 2148, 2149, 2150, + 2154, 2155, 2159, 2170, 2173, 2173, 2192, 2191, 2206, 2205, + 2218, 2227, 2236, 2246, 2247, 2251, 2254, 2263, 2264, 2268, + 2271, 2274, 2290, 2299, 2300, 2304, 2307, 2310, 2324, 2325, + 2329, 2335, 2341, 2344, 2348, 2354, 2363, 2364, 2365, 2369, + 2370, 2374, 2381, 2386, 2395, 2401, 2412, 2415, 2420, 2425, + 2433, 2444, 2447, 2447, 2467, 2468, 2472, 2473, 2474, 2478, + 2481, 2481, 2500, 2503, 2506, 2521, 2540, 2541, 2542, 2547, + 2547, 2573, 2574, 2578, 2579, 2579, 2583, 2584, 2585, 2589, + 2599, 2604, 2599, 2616, 2621, 2616, 2636, 2637, 2641, 2642, + 2646, 2652, 2653, 2657, 2658, 2659, 2663, 2666, 2672, 2677, + 2672, 2691, 2698, 2703, 2712, 2718, 2729, 2730, 2731, 2732, + 2733, 2734, 2735, 2736, 2737, 2738, 2739, 2740, 2741, 2742, + 2743, 2744, 2745, 2746, 2747, 2748, 2749, 2750, 2751, 2752, + 2753, 2754, 2755, 2759, 2760, 2761, 2762, 2763, 2764, 2765, + 2766, 2770, 2781, 2785, 2792, 2804, 2811, 2820, 2825, 2828, + 2841, 2841, 2841, 2854, 2858, 2865, 2869, 2876, 2877, 2878, + 2879, 2880, 2895, 2901, 2901, 2901, 2905, 2910, 2917, 2917, + 2924, 2928, 2932, 2937, 2942, 2947, 2952, 2956, 2960, 2965, + 2969, 2973, 2978, 2978, 2978, 2984, 2991, 2991, 2991, 2996, + 2996, 2996, 3002, 3002, 3002, 3007, 3011, 3011, 3011, 3016, + 3016, 3016, 3025, 3029, 3029, 3029, 3034, 3034, 3034, 3043, + 3047, 3047, 3047, 3052, 3052, 3052, 3061, 3061, 3061, 3067, + 3067, 3067, 3076, 3079, 3090, 3106, 3106, 3111, 3116, 3106, + 3141, 3141, 3146, 3152, 3141, 3177, 3177, 3182, 3187, 3177, + 3217, 3218, 3219, 3220, 3221, 3225, 3232, 3239, 3245, 3251, + 3258, 3265, 3271, 3281, 3289, 3294, 3301, 3302, 3307, 3308, + 3312, 3313, 3317, 3318, 3322, 3323, 3324, 3328, 3329, 3330, + 3334, 3335, 3339, 3345, 3352, 3360, 3367, 3375, 3384, 3384, + 3384, 3392, 3392, 3392, 3399, 3399, 3399, 3406, 3406, 3406, + 3417, 3420, 3426, 3440, 3446, 3452, 3458, 3458, 3458, 3468, + 3473, 3480, 3488, 3493, 3500, 3500, 3500, 3510, 3510, 3510, + 3520, 3520, 3520, 3530, 3538, 3538, 3538, 3546, 3553, 3553, + 3553, 3563, 3568, 3575, 3578, 3584, 3592, 3601, 3609, 3617, + 3630, 3631, 3635, 3636, 3641, 3644, 3647, 3650, 3653, 3656 }; #endif @@ -6479,19 +6479,19 @@ YYLTYPE yylloc = yyloc_default; break; case 24: /* character_sequence: STRING_CHARACTER */ - { (yyval.s) = new string(); *(yyval.s) += (yyvsp[0].ch); } + { (yyval.s) = new string(); *(yyval.s) += (yyvsp[0].ch); } break; case 25: /* character_sequence: STRING_CHARACTER_ESC */ - { (yyval.s) = new string(); *(yyval.s) += "\\\\"; } + { (yyval.s) = new string(); *(yyval.s) += "\\\\"; } break; case 26: /* character_sequence: character_sequence STRING_CHARACTER */ - { (yyval.s) = (yyvsp[-1].s); *(yyvsp[-1].s) += (yyvsp[0].ch); } + { (yyval.s) = (yyvsp[-1].s); *(yyvsp[-1].s) += (yyvsp[0].ch); } break; case 27: /* character_sequence: character_sequence STRING_CHARACTER_ESC */ - { (yyval.s) = (yyvsp[-1].s); *(yyvsp[-1].s) += "\\\\"; } + { (yyval.s) = (yyvsp[-1].s); *(yyvsp[-1].s) += "\\\\"; } break; case 28: /* string_constant: "start of the string" character_sequence "end of the string" */ @@ -6507,7 +6507,7 @@ YYLTYPE yylloc = yyloc_default; break; case 30: /* string_builder_body: string_builder_body character_sequence */ - { + { bool err; auto esconst = unescapeString(*(yyvsp[0].s),&err); if ( err ) das_yyerror(scanner,"invalid escape sequence",tokAt(scanner,(yylsp[-1])), CompilationError::invalid_escape_sequence); @@ -6519,7 +6519,7 @@ YYLTYPE yylloc = yyloc_default; break; case 31: /* string_builder_body: string_builder_body "{" expr "}" */ - { + { auto se = ExpressionPtr((yyvsp[-1].pExpression)); static_cast((yyvsp[-3].pExpression))->elements.push_back(se); (yyval.pExpression) = (yyvsp[-3].pExpression); diff --git a/src/parser/ds_parser.output b/src/parser/ds_parser.output index 453158c28..7a2821a1a 100644 --- a/src/parser/ds_parser.output +++ b/src/parser/ds_parser.output @@ -11,7 +11,6 @@ State 520 conflicts: 2 shift/reduce State 522 conflicts: 2 shift/reduce State 628 conflicts: 1 shift/reduce State 849 conflicts: 1 shift/reduce -State 938 conflicts: 2 shift/reduce State 1050 conflicts: 1 shift/reduce State 1163 conflicts: 1 shift/reduce State 1439 conflicts: 1 shift/reduce @@ -29807,9 +29806,7 @@ State 938 STRING_CHARACTER shift, and go to state 222 STRING_CHARACTER_ESC shift, and go to state 223 - STRING_CHARACTER [reduce using rule 29 (string_builder_body)] - STRING_CHARACTER_ESC [reduce using rule 29 (string_builder_body)] - $default reduce using rule 29 (string_builder_body) + $default reduce using rule 29 (string_builder_body) State 939 diff --git a/src/parser/ds_parser.ypp b/src/parser/ds_parser.ypp index 591881ec8..a5e237855 100644 --- a/src/parser/ds_parser.ypp +++ b/src/parser/ds_parser.ypp @@ -528,6 +528,9 @@ %nonassoc '$' '@' %nonassoc COLCOL +%right STRING_CHARACTER STRING_CHARACTER_ESC +%right BEGIN_STRING_EXPR END_STRING_EXPR + %% program @@ -588,10 +591,10 @@ module_declaration ; character_sequence - : STRING_CHARACTER[char] { $$ = new string(); *$$ += $char; } - | STRING_CHARACTER_ESC { $$ = new string(); *$$ += "\\\\"; } - | character_sequence[elem] STRING_CHARACTER[char] { $$ = $elem; *$elem += $char; } - | character_sequence[elem] STRING_CHARACTER_ESC { $$ = $elem; *$elem += "\\\\"; } + : STRING_CHARACTER[char] { $$ = new string(); *$$ += $char; } + | STRING_CHARACTER_ESC { $$ = new string(); *$$ += "\\\\"; } + | character_sequence[elem] STRING_CHARACTER[char] %prec STRING_CHARACTER { $$ = $elem; *$elem += $char; } + | character_sequence[elem] STRING_CHARACTER_ESC %prec STRING_CHARACTER { $$ = $elem; *$elem += "\\\\"; } ; string_constant @@ -604,7 +607,7 @@ string_builder_body $$->at = LineInfo(yyextra->g_FileAccessStack.back(), yylloc.first_column,yylloc.first_line,yylloc.last_column,yylloc.last_line); } - | string_builder_body[sb] character_sequence[sconst] { + | string_builder_body[sb] character_sequence[sconst] %prec STRING_CHARACTER { bool err; auto esconst = unescapeString(*$sconst,&err); if ( err ) das_yyerror(scanner,"invalid escape sequence",tokAt(scanner,@sb), CompilationError::invalid_escape_sequence); @@ -613,7 +616,7 @@ string_builder_body static_cast($sb)->elements.push_back(sc); $$ = $sb; } - | string_builder_body[sb] BEGIN_STRING_EXPR expr[subexpr] END_STRING_EXPR { + | string_builder_body[sb] BEGIN_STRING_EXPR expr[subexpr] END_STRING_EXPR %prec BEGIN_STRING_EXPR { auto se = ExpressionPtr($subexpr); static_cast($sb)->elements.push_back(se); $$ = $sb;