package lambdapi
All checked builds pass sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>
Proof assistant for the λΠ-calculus modulo rewriting
Install
dune-project
Dependency
Authors
Maintainers
Sources
lambdapi-4.0.0.tbz
sha256=0e2e73e0ea0c674f1263bf85ed3453ed3d6084d38eea29974a03ba9e382d29d7
sha512=2831db57fcd09206687a92fc9ee7d363e87bcec5167949e9c8161d41c63d5887b9f3556bfd63a7a9a0c12e5a5dc61a397baf4f496ebdb2a2fce122142c05e7a1
doc/src/lambdapi.parsing/lpParser.ml.html
Source file lpParser.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 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 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 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 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 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884open Lplib open Common open Pos open Logger open Syntax open Core open LpLexer open Lexing open Sedlexing open OneLookaheadCellLexbuf let log = Logger.make 'n' "pars" "parsing" let log = log.pp (* token management *) let tokens = function | [] -> "" | s::l -> List.fold_left (fun acc s -> acc^", "^String.add_quotes s) s l let string_of_token = let q = String.add_quotes in let (||) a b = a^", "^b in function | EOF -> "end of file" | ABORT -> q"abort" | ADMIT -> q"admit" | ADMITTED -> q"admitted" | ALL_HYPS -> q"all_hyps" | APPLY -> q"apply" | ARROW -> q"→" | AS -> q"as" | ASSERT _ -> q"assert" || q"assertnot" | ASSIGN -> q"≔" | ASSOCIATIVE -> q"associative" | ASSUME -> q"assume" | ASSUMPTION -> q"assumption" | BACKQUOTE -> q"`" | BEGIN -> q"begin" | BUILTIN -> q"builtin" | CHANGE -> q"change" | COERCE_RULE -> q"coerce_rule" | COLON -> q":" | COMMA -> q"," | COMMUTATIVE -> q"commutative" | COMPUTE -> q"compute" | CONSTANT -> q"constant" | DEBUG -> q"debug" | DEBUG_FLAGS _ -> "debug flags" | DOT -> q"." | END -> q"end" | EQUIV -> q"≡" | EVAL -> q"eval" | EXISTS -> q"exists" (* only in Rocq *) | FAIL -> q"fail" | FIRST_HYP -> q"first_hyp" | FLAG -> q"flag" | FLOAT _ -> q"float" | FOCUS -> q"focus" | FORALL -> q"forall" (* only in Rocq *) | FUN -> q"fun" (* only in Rocq *) | GENERALIZE -> q"generalize" | HAVE -> q"have" | HOOK_ARROW -> q"↪" | IN -> q"in" | INDUCTION -> q"induction" | INDUCTIVE -> q"inductive" | INFIX -> q"infix" | INJECTIVE -> q"injective" | INT _ -> q"integer" | LAMBDA -> q"λ" | LET -> q"let" | L_CU_BRACKET -> q"{" | L_PAREN -> q"(" | L_SQ_BRACKET -> q"[" | NOTATION -> q"notation" | OPAQUE -> q"opaque" | OPEN -> q"open" | ORELSE -> q"orelse" | PI -> q"Π" | POSTFIX -> q"postfix" | PREFIX -> q"prefix" | PRINT -> q"print" | PRIVATE -> q"private" | PROOFTERM -> q"proofterm" | PROTECTED -> q"protected" | PROVER -> q"prover" | PROVER_TIMEOUT -> q"prover_timeout" | QID _ -> "qualified identifier" | QID_EXPL _ -> "@-prefixed qualified identifier" | QINT _ -> "qualified integer" | QUANTIFIER -> q"quantifier" | REFINE -> q"refine" | REFLEXIVITY -> q"reflexivity" | REMOVE -> q"remove" | REPEAT -> q"repeat" | REQUIRE -> q"require" | REWRITE -> q"rewrite" | RULE -> q"rule" | R_CU_BRACKET -> q"}" | R_PAREN -> q")" | R_SQ_BRACKET -> q"]" | SEARCH -> q"search" | SEQUENTIAL -> q"sequential" | SEMICOLON -> q";" | SET -> q"set" | SIDE _ -> q"left" || q"right" | SIMPLIFY -> q"simplify" | SOLVE -> q"solve" | STRINGLIT _ -> "string literal" | SWITCH false -> q"off" | SWITCH true -> q"on" || q"off" | SYMBOL -> q"symbol" | SYMMETRY -> q"symmetry" | THICKARROW -> q"=>" (* only in Rocq *) | TRY -> q"try" | TURNSTILE -> q"⊢" | TYPE_QUERY -> q"type" | TYPE_TERM -> q"TYPE" | UID _ -> "non-qualified identifier" | UID_EXPL _ -> "@-prefixed non-qualified identifier" | UID_META _ -> "?-prefixed metavariable number" | UID_PATT _ -> "$-prefixed non-qualified identifier" | UNDERSCORE -> q"_" | UNIF_RULE -> q"unif_rule" | VBAR -> q"|" | VERBOSE -> q"verbose" | WHY3 -> q"why3" | WITH -> q"with" let string_of_tokens = List.fold_left (fun s t -> s^", "^string_of_token t) let pp_token ppf t = Base.string ppf (string_of_token t) let match_token tok patt = match patt,tok with | ASSERT _, ASSERT _ | DEBUG_FLAGS _, DEBUG_FLAGS _ | FLOAT _, FLOAT _ | INT _, INT _ | QID _, QID _ | QID_EXPL _, QID_EXPL _ | QINT _ , QINT _ | SIDE _, SIDE _ | STRINGLIT _, STRINGLIT _ | SWITCH false, SWITCH false | SWITCH true, SWITCH _ | UID _, UID _ | UID_EXPL _, UID_EXPL _ | UID_META _, UID_META _ | UID_PATT _ , UID_PATT _ -> true | t1,t2 -> t1=t2 let match_guard patts lb = List.exists (match_token (current_token lb)) patts let err_msg lb (msg:string) (tokens:token list): string = if msg <> "" then if String.starts_with ~prefix:"Expected: " msg then msg else "Expected: " ^ msg else match tokens with | [] -> assert false | t::ts -> "Expected: " ^ string_of_tokens (string_of_token t) (ts @ get_expected_tokens lb) ^ "." let loc_err_msg lb (msg:string) (tokens:token list) : strloc = Pos.make_pos (current_pos lb) (err_msg lb msg tokens) let expected lb (msg:string) (tokens:token list) : 'a = syntax_error (current_pos lb) (err_msg lb msg tokens) (* building positions and terms *) let extend_pos lb (lps:position * position) : 'a -> 'a loc = let p1 = fst lps and p2 = fst (current_pos lb) in let p2 = if p2.pos_cnum > p2.pos_bol then {p2 with pos_cnum = p2.pos_cnum - 1} else p2 in (*if log_enabled() then log "extend_pos %s %a -> %a" s Pos.pp_lexing lps Pos.pp_lexing lps2;*) make_pos (p1,p2) let qid_of_path (lps: position * position): string list -> (string list * string) loc = function | [] -> assert false | id::mp -> make_pos lps (List.rev mp, id) let make_abst lb (pos1:position) (ps:p_params list) (t:p_term) (pos2:position) : p_term = if ps = [] then t else extend_pos lb (*__FUNCTION__*) (pos1,pos2) (P_Abst(ps,t)) let make_prod lb (pos1:position) (ps:p_params list) (t:p_term) (pos2:position) :p_term = if ps = [] then t else extend_pos lb (*__FUNCTION__*) (pos1,pos2) (P_Prod(ps,t)) let ident_of_term pos1 {elt; _} = match elt with | P_Iden({elt=([], x); pos}, _) -> Pos.make pos x | _ -> LpLexer.syntax_error pos1 "Not an unqualified identifier." (* generic parsing functions *) let consume (token:token) (lb:'token lexbuf): unit = if current_token lb = token then consume_token lb else expected lb "" [token] let prefix (token:token) (elt:'token lexbuf -> 'a) (lb:'token lexbuf): 'a = consume token lb; elt lb let opt (tk : 'token) (lb:'token lexbuf) : bool = if log_enabled() then log "%s" __FUNCTION__; if current_token lb = tk then (consume_token lb; true) else (set_expected_tokens lb [tk]; false) let list (guard: 'token list) (elt:'token lexbuf -> 'a) (lb:'token lexbuf) : 'a list = if log_enabled() then log "%s" __FUNCTION__; let acc = ref [] in while match_guard guard lb do acc := elt lb :: !acc done ; set_expected_tokens lb guard; List.rev !acc let list_with_sep (guard: 'token list) (elt:'token lexbuf -> 'a) (sep:'token) (lb:'token lexbuf) : 'a list = if log_enabled() then log "%s" __FUNCTION__; let acc = ref [] in let guard = ref guard in let el = ref elt in while match_guard !guard lb do acc := !el lb :: !acc ; guard := [sep] ; el := prefix sep elt done ; set_expected_tokens lb !guard ; List.rev !acc (** [UnfinishedProof] is raised when a proof is syntactically broken. It takes as arguments: a located error message [strloc], a [p_symbol] data structure containing the data of the declared symbol the proof is about, but with the field [p_sym_prf] containing only the prefix of the proof that is syntactically correct, and the position [popt] of the symbol command (until where the error occurred). It is raised by the second function [command] (the one that is exported) in case a command is not terminated by a semicolon, or by the function [proof_end] when the current token is not a valid proof end token (this includes any syntax error in the middle of a proof script, e.g. an error in the name of a tactic keyword). In the second case, it is raised with [popt=None] and a [p_symbol] whose only meaningful field is [p_sym_prf]. The other fields are updated later as follows. The function [proof_term] catches it and raises it again right away after updating [p_symbol] with the correct [p_sym_trm] in case a term has been given. The function [symbol] catches it and raises it again right away after updating all the other fields of [p_symbol]. The first function [command] catches it and raises it again right away after updating [popt]. *) exception UnfinishedProof of strloc * Syntax.p_symbol * popt let unfinished_proof l lb msg expected_tokens = let pe = Pos.make_pos (current_pos lb) Syntax.P_proof_end in let sym = (* fields other than [p_sym_prf] will be updated later *) { p_sym_mod = []; p_sym_kw = None; p_sym_nam = Pos.none "" ; p_sym_arg = []; p_sym_typ = None; p_sym_trm = None; p_sym_def = false ; p_sym_prf = Some(l,pe) } in raise (UnfinishedProof(loc_err_msg lb msg expected_tokens, sym, None)) let list_with_sep_or_termin (guard: 'token list) (elt:'a list ref -> 'token lexbuf -> 'a) (sep:'token) (lb:'token lexbuf) : 'a list = if log_enabled() then log "%s" __FUNCTION__; let acc = ref [] in let match_sep = ref false in while match_guard (if !match_sep then [sep] else guard) lb do if !match_sep then (consume sep lb; match_sep := false) else (acc := elt acc lb :: !acc; match_sep := true) done ; set_expected_tokens lb (if !match_sep then [sep] else guard) ; List.rev !acc let nelist (guard: 'token list) (elt:'token lexbuf -> 'a) (lb:'token lexbuf) : 'a list = if log_enabled() then log "%s" __FUNCTION__; let x = elt lb in x :: list guard elt lb let nelist_with_sep (elt:'token lexbuf -> 'a) (sep:'token) (lb:'token lexbuf) : 'a list = if log_enabled() then log "%s" __FUNCTION__; let a = elt lb in let acc = list [sep] (prefix sep elt) lb in a::acc (* parsing functions *) let consume_STRINGLIT (lb:'token lexbuf): string = match current_token lb with | STRINGLIT s -> consume_token lb; s | _ -> expected lb "" [STRINGLIT""] let consume_SWITCH (lb:'token lexbuf): bool = match current_token lb with | SWITCH b -> consume_token lb; b | _ -> expected lb "" [SWITCH true] let consume_INT (lb:'token lexbuf): string = match current_token lb with | INT s -> consume_token lb; s | _ -> expected lb "" [INT""] let qid (lb:'token lexbuf): (string list * string) loc = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | UID s -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 ([], s) | QID p -> let pos1 = current_pos lb in consume_token lb; qid_of_path pos1 p | _ -> expected lb "" [UID"";QID[]] let qid_or_regexp (lb:'token lexbuf): (string list * string) loc = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | UID s -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 ([], s) | QID p -> let pos1 = current_pos lb in consume_token lb; qid_of_path pos1 p | STRINGLIT s -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 ([], s) | _ -> expected lb "" [UID"";QID[];STRINGLIT""] let qid_expl (lb:'token lexbuf): (string list * string) loc = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | UID_EXPL s -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 ([], s) | QID_EXPL p -> let pos1 = current_pos lb in consume_token lb; qid_of_path pos1 p | _ -> expected lb "" [UID_EXPL"";QID_EXPL[]] let uid (lb:'token lexbuf): string loc = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | UID s -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 s | _ -> expected lb "" [UID""] let sym_name (lb:'token lexbuf): string loc = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | INT s -> syntax_error (current_pos lb) "Forbidden symbol name." | UID s -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 s | _ -> expected lb "" [UID""] let param_tks = [UID"";UNDERSCORE] let param (lb:'token lexbuf): string loc option = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | UID s -> let pos1 = current_pos lb in consume_token lb; Some (make_pos pos1 s) | UNDERSCORE -> consume_token lb; None | _ -> expected lb "" param_tks let int (lb:'token lexbuf): string = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | INT s -> consume_token lb; s | _ -> expected lb "" [INT""] let float_or_int (lb:'token lexbuf): string = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | INT s | FLOAT s -> consume_token lb; s | _ -> expected lb "" [FLOAT"";INT""] let path_tks = [QID[]] let path (lb:'token lexbuf): string list loc = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | QID p -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 (List.rev p) | _ -> expected lb "" path_tks let proof_end_tks = [END;ABORT;ADMITTED] let print (lb:'token lexbuf): print = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | SEMICOLON | ABORT | ADMITTED | END -> Goal | UID s -> let pos1 = current_pos lb in consume_token lb; Symbol(make_pos pos1 ([],s)) | QID p -> let pos1 = current_pos lb in consume_token lb; Symbol(qid_of_path pos1 p) | STRINGLIT s -> consume_token lb; String (String.remove_quotes s) | UNIF_RULE -> consume_token lb; Unif_rule | COERCE_RULE -> consume_token lb; Coerce_rule | VERBOSE -> consume_token lb; Verbose | DEBUG -> consume_token lb; Debug | FLAG -> consume_token lb; Flag | PROVER -> consume_token lb; Prover | PROVER_TIMEOUT -> consume_token lb; Prover_timeout | BUILTIN -> consume_token lb; Builtin | NOTATION -> consume_token lb; Notation | _ -> expected lb "" ([UID"";QID[];STRINGLIT"";UNIF_RULE;COERCE_RULE;VERBOSE; DEBUG;FLAG;PROVER;PROVER_TIMEOUT;BUILTIN;NOTATION;SEMICOLON] @ proof_end_tks) let term_id (lb:'token lexbuf): p_term = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | UID _ | QID _ -> let i = qid lb in {i with elt=P_Iden(i, false)} | UID_EXPL _ | QID_EXPL _ -> let i = qid_expl lb in {i with elt=P_Iden(i, true)} | _ -> expected lb "" [UID"";QID[];UID_EXPL"";QID_EXPL[]] (* commands *) (* [req] tells whether the command starts with the [require] keyword: [require [private] open] loads the modules and opens them ([P_require]), while a bare [[private] open] only opens modules that are already loaded ([P_open]). For a bare open, the position of the "open" keyword is recorded in the AST (a "private" modifier, like modifiers of symbol declarations, is not part of the keyword). *) let open_ (req:bool) (priv:bool) (lb:'token lexbuf) : p_command_aux = if log_enabled() then log "%s" __FUNCTION__; let kw_pos = Some(locate (current_pos lb)) in consume OPEN lb; let ps = nelist path_tks path lb in if req then P_require(Some priv,ps) else P_open(kw_pos,priv,ps) let rec symbol (p_sym_mod:p_modifier list) (lb:'token lexbuf): p_command_aux = if log_enabled() then log "%s" __FUNCTION__; let p_sym_kw = Some(locate (current_pos lb)) in consume SYMBOL lb; let p_sym_nam = sym_name lb in let p_sym_arg = list params_tks params lb in begin match current_token lb with | COLON -> consume_token lb; let p_sym_typ = Some(term lb) in begin match current_token lb with | BEGIN -> consume_token lb; let p_sym_prf = None in let p_sym_def = false in let sym = {p_sym_mod; p_sym_kw; p_sym_nam; p_sym_arg; p_sym_typ; p_sym_trm=None; p_sym_def; p_sym_prf} in let p_sym_prf = try Some(proof lb) with UnfinishedProof(m, s, _) -> let sym = {sym with p_sym_prf = s.p_sym_prf} in raise (UnfinishedProof(m, sym, None)) in P_symbol {sym with p_sym_prf} | ASSIGN -> consume_token lb; let p_sym_trm, p_sym_prf = None, None in let p_sym_def = true in let sym = {p_sym_mod; p_sym_kw; p_sym_nam; p_sym_arg; p_sym_typ; p_sym_trm; p_sym_def; p_sym_prf} in let p_sym_trm, p_sym_prf = try term_proof lb with UnfinishedProof(m, s, _) -> let sym = {sym with p_sym_trm=s.p_sym_trm ; p_sym_prf=s.p_sym_prf} in raise (UnfinishedProof(m, sym, None)) in P_symbol({sym with p_sym_trm; p_sym_prf}) | SEMICOLON -> let p_sym_trm = None in let p_sym_def = false in let p_sym_prf = None in let sym = {p_sym_mod; p_sym_kw; p_sym_nam; p_sym_arg; p_sym_typ; p_sym_trm; p_sym_def; p_sym_prf} in P_symbol(sym) | _ -> expected lb "" [BEGIN;ASSIGN;SEMICOLON] end | ASSIGN -> consume_token lb; let p_sym_trm, p_sym_prf = None, None in let p_sym_def = true in let p_sym_typ = None in let sym = {p_sym_mod; p_sym_kw; p_sym_nam; p_sym_arg; p_sym_typ; p_sym_trm; p_sym_def; p_sym_prf} in let p_sym_trm, p_sym_prf = try term_proof lb with UnfinishedProof(m, s, _) -> let sym = {sym with p_sym_trm=s.p_sym_trm ; p_sym_prf=s.p_sym_prf} in raise (UnfinishedProof(m, sym, None)) in P_symbol({sym with p_sym_trm; p_sym_prf}) | _ -> expected lb "" [COLON;ASSIGN] end and inductive_cmd (p_sym_mod:p_modifier list) (lb:'token lexbuf) : p_command_aux = if log_enabled() then log "%s" __FUNCTION__; let xs = list params_tks params lb in match current_token lb with | INDUCTIVE -> let kw_pos = Some(locate (current_pos lb)) in consume INDUCTIVE lb; let i = inductive lb in let is = list [WITH] (prefix WITH inductive) lb in P_inductive(kw_pos,p_sym_mod,xs,i::is) | _ -> expected lb "" [L_PAREN;L_SQ_BRACKET;INDUCTIVE] and command (lb:'token lexbuf) : p_command = if log_enabled() then log "%s" __FUNCTION__; let pos1 = current_pos lb in let p_sym_mod = list modifier_tks modifier lb in try begin match p_sym_mod with | [{elt=P_opaq;_}] -> begin match current_token lb with | UID _ | QID _ -> let i = qid lb in extend_pos lb (*__FUNCTION__*) pos1 (P_opaque i) | SYMBOL -> extend_pos lb (*__FUNCTION__*) pos1 (symbol p_sym_mod lb) | _ -> expected lb "" [UID"";QID[];SYMBOL] end | [{elt=P_expo Term.Privat;_}] -> begin match current_token lb with | OPEN -> extend_pos lb (*__FUNCTION__*) pos1 (open_ false true lb) | SYMBOL -> extend_pos lb (*__FUNCTION__*) pos1 (symbol p_sym_mod lb) | L_PAREN | L_SQ_BRACKET | INDUCTIVE -> extend_pos lb (*__FUNCTION__*) pos1 (inductive_cmd p_sym_mod lb) | _ -> expected lb "" [OPEN;SYMBOL;L_PAREN;L_SQ_BRACKET;INDUCTIVE] end | _::_ -> begin match current_token lb with | SYMBOL -> extend_pos lb (*__FUNCTION__*) pos1 (symbol p_sym_mod lb) | L_PAREN | L_SQ_BRACKET | INDUCTIVE -> extend_pos lb (*__FUNCTION__*) pos1 (inductive_cmd p_sym_mod lb) | _ -> expected lb "" [SYMBOL;L_PAREN;L_SQ_BRACKET;INDUCTIVE] end | [] -> begin match current_token lb with | REQUIRE -> consume_token lb; begin match current_token lb with | OPEN -> extend_pos lb (*__FUNCTION__*) pos1 (open_ true false lb) | PRIVATE -> consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 (open_ true true lb) | QID _ -> let ps = nelist path_tks path lb in begin match current_token lb with | AS -> let p = match ps with | [p] -> p | _ -> expected lb "a single module before \"as\"" [] in consume_token lb; let i = uid lb in extend_pos lb (*__FUNCTION__*) pos1 (P_require_as(p,i)) | _ -> set_expected_tokens lb [AS] ; extend_pos lb (*__FUNCTION__*) pos1 (P_require(None,ps)) end | _ -> expected lb "" [OPEN;PRIVATE;QID[]] end | OPEN -> extend_pos lb (*__FUNCTION__*) pos1 (open_ false false lb) | SYMBOL -> extend_pos lb (*__FUNCTION__*) pos1 (symbol p_sym_mod lb) | L_PAREN | L_SQ_BRACKET | INDUCTIVE -> extend_pos lb (*__FUNCTION__*) pos1 (inductive_cmd p_sym_mod lb) | RULE -> consume_token lb; let rs = list_with_sep (rule_tks ()) rule WITH lb in extend_pos lb (*__FUNCTION__*) pos1 (P_rules rs) | UNIF_RULE -> consume_token lb; let e = equation lb in consume HOOK_ARROW lb; consume L_SQ_BRACKET lb; let es = list_with_sep (equation_tks ()) equation SEMICOLON lb in consume R_SQ_BRACKET lb; (* FIXME: give sensible positions instead of Pos.none and P.appl. *) let equiv = P.qiden Sign.Ghost.path Unif_rule.equiv.sym_name in let cons = P.qiden Sign.Ghost.path Unif_rule.cons.sym_name in (* Note that, by definition of P.qiden, equiv is @≡. *) let mk_equiv (t, u) = P.appl (P.appl equiv (P.wrap t)) (P.wrap u) in let lhs = mk_equiv e in let es = List.rev_map mk_equiv es in let (en, es) = List.(hd es, tl es) in let cat e es = P.appl (P.appl cons e) es in let rhs = List.fold_right cat es en in let r = extend_pos lb (*__FUNCTION__*) pos1 (lhs, rhs) in extend_pos lb (*__FUNCTION__*) pos1 (P_unif_rule(r)) | COERCE_RULE -> consume_token lb; let r = rule lb in extend_pos lb (*__FUNCTION__*) pos1 (P_coercion r) | BUILTIN -> consume_token lb; begin let s = consume_STRINGLIT lb in consume ASSIGN lb; let s = String.remove_quotes s and i = qid lb in extend_pos lb (*__FUNCTION__*) pos1 (P_builtin(s,i)) end | NOTATION -> consume_token lb; let i = qid lb in let n = notation lb in extend_pos lb (*__FUNCTION__*) pos1 (P_notation(i,n)) | ASSERT _ | COMPUTE | DEBUG | FLAG | PRINT | PROOFTERM | PROVER | PROVER_TIMEOUT | SEARCH | TYPE_QUERY | VERBOSE -> let q = query lb in extend_pos lb (*__FUNCTION__*) pos1 (P_query(q)) | _ -> expected lb "command" (modifier_tks @ [REQUIRE;OPEN;SYMBOL;L_PAREN;L_SQ_BRACKET;INDUCTIVE;RULE;UNIF_RULE; COERCE_RULE;BUILTIN;NOTATION] @ (query_tks())) end end with UnfinishedProof(m, sym, _) -> let Pos.{pos; _} = extend_pos lb (*__FUNCTION__*) pos1 sym in raise (UnfinishedProof(m, sym, pos)) and inductive (lb:'token lexbuf): p_inductive = let pos0 = current_pos lb in let i = uid lb in let pos1 = current_pos lb in let ps = list params_tks params lb in consume COLON lb; let t = term lb in let pos2 = current_pos lb in let t = make_prod lb (fst pos1) ps t (snd pos2) in consume ASSIGN lb; begin match current_token lb with | UID _ -> let l = nelist_with_sep constructor VBAR lb in extend_pos lb (*__FUNCTION__*) pos0 (i,t,l) | VBAR -> let l = list [VBAR] (prefix VBAR constructor) lb in extend_pos lb (*__FUNCTION__*) pos0 (i,t,l) | SEMICOLON -> let l = [] in extend_pos lb (*__FUNCTION__*) pos0 (i,t,l) | _ -> expected lb "" [UID"";VBAR;SEMICOLON] end and constructor (lb:'token lexbuf): p_ident * p_term = let i = uid lb in let pos1 = current_pos lb in let ps = list params_tks params lb in consume COLON lb; let t = term lb in i, make_prod lb (fst pos1) ps t (snd (current_pos lb)) and modifier_tks = [SIDE Pratter.Left;ASSOCIATIVE;COMMUTATIVE;CONSTANT;INJECTIVE;OPAQUE; PRIVATE;PROTECTED;SEQUENTIAL] and modifier (lb:'token lexbuf): p_modifier = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | SIDE d -> let pos1 = current_pos lb in consume_token lb; consume ASSOCIATIVE lb; extend_pos lb (*__FUNCTION__*) pos1 (P_prop (Term.Assoc((d = Pratter.Left)))) | ASSOCIATIVE -> let pos1 = current_pos lb in consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 (P_prop (Term.Assoc false)) | COMMUTATIVE -> let pos1 = current_pos lb in consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 (P_prop Term.Commu) | CONSTANT -> let pos1 = current_pos lb in consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 (P_prop Term.Const) | INJECTIVE -> let pos1 = current_pos lb in consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 (P_prop Term.Injec) | OPAQUE -> let pos1 = current_pos lb in consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 P_opaq | PRIVATE -> let pos1 = current_pos lb in consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 (P_expo Term.Privat) | PROTECTED -> let pos1 = current_pos lb in consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 (P_expo Term.Protec) | SEQUENTIAL -> let pos1 = current_pos lb in consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 (P_mstrat Term.Sequen) | _ -> expected lb "" modifier_tks and notation (lb:'token lexbuf): string Term.notation = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | INFIX -> consume_token lb; begin match current_token lb with | SIDE d -> consume_token lb; let p = float_or_int lb in Term.Infix(d, p) | INT _ | FLOAT _ -> let p = float_or_int lb in Term.Infix(Pratter.Neither, p) | _ -> expected lb "" [SIDE Pratter.Left;INT"";FLOAT""] end | POSTFIX -> consume_token lb; let p = float_or_int lb in Term.Postfix p | PREFIX -> consume_token lb; let p = float_or_int lb in Term.Prefix p | QUANTIFIER -> consume_token lb; Term.Quant | _ -> expected lb "" [INFIX;POSTFIX;PREFIX;QUANTIFIER] and rule_tks () = term_tks and rule (lb:'token lexbuf): (p_term * p_term) loc = if log_enabled() then log "%s" __FUNCTION__; let pos1 = current_pos lb in let l = term lb in consume HOOK_ARROW lb; let r = term lb in extend_pos lb (*__FUNCTION__*) pos1 (l, r) and equation_tks () = term_tks and equation (lb:'token lexbuf): p_term * p_term = if log_enabled() then log "%s" __FUNCTION__; let l = term lb in consume EQUIV lb; let r = term lb in (l, r) (* queries *) and query_print lb p = let pos1 = current_pos lb in consume_token lb; begin match current_token lb with | SEMICOLON | ABORT | ADMITTED | END -> extend_pos lb (*__FUNCTION__*) pos1 (P_query_print p) | _ -> expected lb "" ([SEMICOLON] @ proof_end_tks) end and query_tks() = [ASSERT false;COMPUTE;DEBUG;FLAG;PRINT;PROOFTERM;PROVER; PROVER_TIMEOUT;TYPE_QUERY;VERBOSE;SEARCH] and query (lb:'token lexbuf): p_query = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | ASSERT b -> let pos1 = current_pos lb in consume_token lb; let ps = list params_tks params lb in consume TURNSTILE lb; let t = term lb in begin match current_token lb with | COLON -> consume_token lb; let a = term lb in let pos2 = current_pos lb in let t = make_abst lb (snd pos1) ps t (fst pos2) in let a = make_prod lb (snd pos1) ps a (fst pos2) in extend_pos lb (*__FUNCTION__*) pos1 (P_query_assert(b, P_assert_typing(t,a))) | EQUIV -> consume_token lb; let u = term lb in let pos2 = current_pos lb in let t = make_abst lb (snd pos1) ps t (fst pos2) in let u = make_abst lb (snd pos1) ps u (fst pos2) in extend_pos lb (*__FUNCTION__*) pos1 (P_query_assert(b, P_assert_conv(t, u))) | _ -> expected lb "" [COLON;EQUIV] end | COERCE_RULE -> query_print lb Coerce_rule | COMPUTE -> let pos1 = current_pos lb in consume_token lb; let t = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_query_normalize(t, {strategy=SNF; steps=None})) | DEBUG -> let pos1 = current_pos lb in consume_token lb; begin match current_token lb with | SEMICOLON | ABORT | ADMITTED | END -> extend_pos lb (*__FUNCTION__*) pos1 (P_query_print Debug) | DEBUG_FLAGS(b,s) -> consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 (P_query_debug(b,s)) | _ -> expected lb "" ([DEBUG_FLAGS(true,"");SEMICOLON] @ proof_end_tks) end | FLAG -> let pos1 = current_pos lb in consume_token lb; begin match current_token lb with | SEMICOLON | ABORT | ADMITTED | END -> extend_pos lb (*__FUNCTION__*) pos1 (P_query_print Flag) | STRINGLIT s -> consume_token lb; let b = consume_SWITCH lb in let s = String.remove_quotes s in extend_pos lb (*__FUNCTION__*) pos1 (P_query_flag(s,b)) | _ -> expected lb "" ([STRINGLIT"";SEMICOLON] @ proof_end_tks) end | NOTATION -> query_print lb Notation | PRINT -> let pos1 = current_pos lb in consume_token lb; let p = print lb in extend_pos lb (*__FUNCTION__*) pos1 (P_query_print p) | PROOFTERM -> let pos1 = current_pos lb in consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 P_query_proofterm | PROVER -> let pos1 = current_pos lb in consume_token lb; begin match current_token lb with | SEMICOLON | ABORT | ADMITTED | END -> extend_pos lb (*__FUNCTION__*) pos1 (P_query_print Prover) | STRINGLIT s -> consume_token lb; let s = String.remove_quotes s in extend_pos lb (*__FUNCTION__*) pos1 (P_query_prover s) | _ -> expected lb "" ([STRINGLIT"";SEMICOLON] @ proof_end_tks) end | PROVER_TIMEOUT -> let pos1 = current_pos lb in consume_token lb; begin match current_token lb with | SEMICOLON | ABORT | ADMITTED | END -> extend_pos lb (*__FUNCTION__*) pos1 (P_query_print Prover_timeout) | INT s -> consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 (P_query_prover_timeout s) | _ -> expected lb "" ([INT"";SEMICOLON] @ proof_end_tks) end | SEARCH -> let pos1 = current_pos lb in consume_token lb; let q = search lb in extend_pos lb (*__FUNCTION__*) pos1 (P_query_search q) | TYPE_QUERY -> let pos1 = current_pos lb in consume_token lb; let t = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_query_infer(t, {strategy=NONE; steps=None})) | UNIF_RULE -> query_print lb Unif_rule | VERBOSE -> let pos1 = current_pos lb in consume_token lb; begin match current_token lb with | SEMICOLON | ABORT | ADMITTED | END -> extend_pos lb (*__FUNCTION__*) pos1 (P_query_print Verbose) | INT s -> consume_token lb; extend_pos lb (*__FUNCTION__*) pos1 (P_query_verbose s) | _ -> expected lb "" ([INT"";SEMICOLON] @ proof_end_tks) end | _ -> expected lb "" (query_tks()) and term_proof (lb:'token lexbuf): p_term option * (p_proof * p_proof_end) option = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | BEGIN -> consume_token lb; let p = proof lb in None, Some p (* bterm *) | BACKQUOTE | PI | LAMBDA | LET (* aterm *) | UID _ | QID _ | UID_EXPL _ | QID_EXPL _ | UNDERSCORE | TYPE_TERM | UID_META _ | UID_PATT _ | L_PAREN | L_SQ_BRACKET | INT _ | QINT _ | STRINGLIT _ -> let t = term lb in if opt BEGIN lb then let p = try proof lb with UnfinishedProof(m, s, _) -> raise (UnfinishedProof(m, {s with p_sym_trm=Some t}, None)) in Some t, Some p else Some t, None | _ -> expected lb "term or proof" [] (* proofs *) and proof (lb:'token lexbuf): p_proof * p_proof_end = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | L_CU_BRACKET -> let l = nelist subproof_tks subproof lb in if current_token lb = SEMICOLON then consume_token lb; proof_end l lb (*queries*) | ASSERT _ | COMPUTE | DEBUG | FLAG | PRINT | PROOFTERM | PROVER | PROVER_TIMEOUT | SEARCH | TYPE_QUERY | VERBOSE (*tactics*) | ADMIT | ALL_HYPS | APPLY | ASSUME | CHANGE | EVAL | FAIL | FIRST_HYP | FOCUS | GENERALIZE | HAVE | INDUCTION | ORELSE | REFINE | REFLEXIVITY | REMOVE | REPEAT | REWRITE | SET | SIMPLIFY | SOLVE | SYMMETRY | TRY | WHY3 -> proof_end [steps lb] lb | END | ABORT | ADMITTED -> proof_end [] lb | _ -> unfinished_proof [[]] lb (string_of_tokens "subproof, tactic, query" proof_end_tks) [] and subproof_tks = [L_CU_BRACKET] and subproof (lb:'token lexbuf): p_proofstep list = if log_enabled() then log "%s" __FUNCTION__; consume L_CU_BRACKET lb; let l = steps lb in consume R_CU_BRACKET lb; l and steps (lb:'token lexbuf): p_proofstep list = if log_enabled() then log "%s" __FUNCTION__; let f acc lb = try step lb with SyntaxError(_,m) -> unfinished_proof [List.rev !acc] lb m.elt [] in list_with_sep_or_termin (step_tks()) f SEMICOLON lb and step_tks() = tactic_tks() and step (lb:'token lexbuf): p_proofstep = if log_enabled() then log "%s" __FUNCTION__; let t = tactic lb in let l = list subproof_tks subproof lb in Tactic(t, l) and proof_end (l:p_proof) (lb:'token lexbuf): p_proof * p_proof_end = if log_enabled() then log "%s" __FUNCTION__; l, match current_token lb with | ABORT -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 Syntax.P_proof_abort | ADMITTED -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 Syntax.P_proof_admitted | END -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 Syntax.P_proof_end | _ -> unfinished_proof l lb "" proof_end_tks and tactic_tks() = [ADMIT;ALL_HYPS;APPLY;ASSUME;ASSUMPTION;CHANGE;EVAL;FAIL;FIRST_HYP;FOCUS; GENERALIZE;HAVE;INDUCTION;ORELSE;REFINE;REFLEXIVITY;REMOVE;REPEAT;REWRITE; SET;SIMPLIFY;SOLVE;SYMMETRY;TRY;WHY3] @ (query_tks()) and tactic (lb:'token lexbuf): p_tactic = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with (*queries*) | ASSERT _ | COMPUTE | DEBUG | FLAG | PRINT | PROOFTERM | PROVER | PROVER_TIMEOUT | SEARCH | TYPE_QUERY | VERBOSE -> let pos1 = current_pos lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_query (query lb)) | ADMIT -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 P_tac_admit | ALL_HYPS -> let pos1 = current_pos lb in consume_token lb; let t = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_all_hyps t) | APPLY -> let pos1 = current_pos lb in consume_token lb; let t = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_apply t) | ASSUME -> let pos1 = current_pos lb in consume_token lb; let xs = nelist params_tks param lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_assume xs) | ASSUMPTION -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 P_tac_assumption | CHANGE -> let pos1 = current_pos lb in consume_token lb; let t = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_change t) | EVAL -> let pos1 = current_pos lb in consume_token lb; let t = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_eval t) | FAIL -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 P_tac_fail | FIRST_HYP -> let pos1 = current_pos lb in consume_token lb; let t = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_first_hyp t) | FOCUS -> let pos1 = current_pos lb in consume_token lb; let n = consume_INT lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_focus n) | GENERALIZE -> let pos1 = current_pos lb in consume_token lb; let i = uid lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_generalize i) | HAVE -> let pos1 = current_pos lb in consume_token lb; let i = uid lb in consume COLON lb; let t = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_have(i,t)) | INDUCTION -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 P_tac_induction | ORELSE -> let pos1 = current_pos lb in consume_token lb; let t1 = tactic lb in let t2 = tactic lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_orelse(t1,t2)) | REFINE -> let pos1 = current_pos lb in consume_token lb; let t = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_refine t) | REFLEXIVITY -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 P_tac_refl | REMOVE -> let pos1 = current_pos lb in consume_token lb; let xs = nelist [UID""] uid lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_remove xs) | REPEAT -> let pos1 = current_pos lb in consume_token lb; let t = tactic lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_repeat t) | REWRITE -> let pos1 = current_pos lb in consume_token lb; begin match current_token lb with | SIDE d -> consume_token lb; if opt DOT lb then let p = rwpatt_bracket lb in let t = term lb in let b = d <> Pratter.Left in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_rewrite(b,Some p,t)) else let t = term lb in let b = d <> Pratter.Left in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_rewrite(b,None,t)) | DOT -> consume_token lb; let p = rwpatt_bracket lb in let t = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_rewrite(true,Some p,t)) | _ -> set_expected_tokens lb [SIDE Pratter.Left;DOT] ; let t = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_rewrite(true,None,t)) end | SET -> let pos1 = current_pos lb in consume_token lb; let i = uid lb in consume ASSIGN lb; let t = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_set(i,t)) | SIMPLIFY -> let pos1 = current_pos lb in consume_token lb; begin match current_token lb with | UID _ | QID _ -> extend_pos lb (*__FUNCTION__*) pos1 (P_tac_simpl(SimpSym(qid lb))) | RULE -> consume_token lb; consume (SWITCH false) lb; extend_pos lb (*__FUNCTION__*) pos1 (P_tac_simpl SimpBetaOnly) | _ -> set_expected_tokens lb [UID"";QID[];RULE]; extend_pos lb (*__FUNCTION__*) pos1 (P_tac_simpl SimpAll) end | SOLVE -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 P_tac_solve | SYMMETRY -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 P_tac_sym | TRY -> let pos1 = current_pos lb in consume_token lb; let t = tactic lb in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_try t) | WHY3 -> let pos1 = current_pos lb in consume_token lb; begin match current_token lb with | STRINGLIT s -> let s = String.remove_quotes s in extend_pos lb (*__FUNCTION__*) pos1 (P_tac_why3 (Some s)) | _ -> set_expected_tokens lb [STRINGLIT""] ; make_pos pos1 (P_tac_why3 None) end | _ -> expected lb "tactic or query" (tactic_tks()) and rwpatt_content (lb:'token lexbuf): p_rwpatt = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with (* bterm *) | BACKQUOTE | PI | LAMBDA | LET (* aterm *) | UID _ | QID _ | UID_EXPL _ | QID_EXPL _ | UNDERSCORE | TYPE_TERM | UID_META _ | UID_PATT _ | L_PAREN | L_SQ_BRACKET | INT _ | QINT _ | STRINGLIT _ -> let pos1 = current_pos lb in let t1 = term lb in begin match current_token lb with | IN -> consume_token lb; let t2 = term lb in if opt IN lb then let t3 = term lb in let x = ident_of_term pos1 t2 in extend_pos lb (*__FUNCTION__*) pos1 (Rw_TermInIdInTerm(t1,(x,t3))) else let x = ident_of_term pos1 t1 in extend_pos lb (*__FUNCTION__*) pos1 (Rw_IdInTerm(x,t2)) | AS -> consume_token lb; let t2 = term lb in consume IN lb; let t3 = term lb in let x = ident_of_term pos1 t2 in extend_pos lb (*__FUNCTION__*) pos1 (Rw_TermAsIdInTerm(t1,(x,t3))) | _ -> set_expected_tokens lb [IN;AS]; extend_pos lb (*__FUNCTION__*) pos1 (Rw_Term(t1)) end | IN -> let pos1 = current_pos lb in consume_token lb; let t1 = term lb in if opt IN lb then let t2 = term lb in let x = ident_of_term pos1 t1 in extend_pos lb (*__FUNCTION__*) pos1 (Rw_InIdInTerm(x,t2)) else extend_pos lb (*__FUNCTION__*) pos1 (Rw_InTerm(t1)) | _ -> expected lb (string_of_tokens "term" [IN]) [] and rwpatt_bracket (lb:'token lexbuf): p_rwpatt = if log_enabled() then log "%s" __FUNCTION__; consume L_SQ_BRACKET lb; let p = rwpatt_content lb in consume R_SQ_BRACKET lb; (*add info on opening bracket*) p and rwpatt (lb:'token lexbuf): p_rwpatt = if log_enabled() then log "%s" __FUNCTION__; consume DOT lb; rwpatt_bracket lb (* terms *) and params_tks = [L_PAREN;L_SQ_BRACKET;UID"";UNDERSCORE] and params (lb:'token lexbuf): p_params = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | L_PAREN -> consume_token lb; let ps = nelist param_tks param lb in begin match current_token lb with | COLON -> consume_token lb; let typ = term lb in consume R_PAREN lb; ps, Some typ, false | R_PAREN -> consume_token lb; ps, None, false | _ -> expected lb "" [COLON;R_PAREN] end | L_SQ_BRACKET -> consume_token lb; let ps = nelist param_tks param lb in begin match current_token lb with | COLON -> consume_token lb; let typ = term lb in consume R_SQ_BRACKET lb; ps, Some typ, true | R_SQ_BRACKET -> consume_token lb; ps, None, true | _ -> expected lb "" [COLON;R_SQ_BRACKET] end | UID _ | UNDERSCORE -> let x = param lb in [x], None, false | _ -> expected lb "" params_tks and term_tks = [BACKQUOTE;(*EXISTS;FORALL;FUN;*)PI;LAMBDA;LET; UID"";QID[];UID_EXPL"";QID_EXPL[];UNDERSCORE; TYPE_TERM;UID_META 0;UID_PATT"";L_PAREN;L_SQ_BRACKET; INT"";QINT([],"");STRINGLIT""] and term (lb:'token lexbuf): p_term = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with (* bterm *) | BACKQUOTE | EXISTS (* only in Rocq *) | FORALL (* only in Rocq *) | FUN (* only in Rocq *) | PI | LAMBDA | LET -> bterm lb (* aterm *) | UID _ | QID _ | UID_EXPL _ | QID_EXPL _ | UNDERSCORE | TYPE_TERM | UID_META _ | UID_PATT _ | L_PAREN | L_SQ_BRACKET | INT _ | QINT _ | STRINGLIT _ -> let pos1 = current_pos lb in let h = aterm lb in app pos1 h lb | _ -> expected lb "term" term_tks and app (pos1:position * position) (t: p_term) (lb:'token lexbuf): p_term = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with (* aterm *) | UID _ | QID _ | UID_EXPL _ | QID_EXPL _ | UNDERSCORE | TYPE_TERM | UID_META _ | UID_PATT _ | L_PAREN | L_SQ_BRACKET | INT _ | QINT _ | STRINGLIT _ -> let u = aterm lb in app pos1 (extend_pos lb (*__FUNCTION__*) pos1 (P_Appl(t,u))) lb (* bterm *) | BACKQUOTE | PI | LAMBDA | LET -> let u = bterm lb in extend_pos lb (*__FUNCTION__*) pos1 (P_Appl(t,u)) (* other cases *) | ARROW -> consume_token lb; let u = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_Arro(t,u)) | _ -> t and bterm (lb:'token lexbuf): p_term = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | BACKQUOTE -> let pos1 = current_pos lb in consume_token lb; let q = term_id lb in let b = binder lb in let b = extend_pos lb (*__FUNCTION__*) pos1 (P_Abst(fst b, snd b)) in extend_pos lb (*__FUNCTION__*) pos1 (P_Appl(q, b)) | EXISTS -> (* only in Rocq *) let pos1 = current_pos lb in consume_token lb; let b = rocqbinder lb COMMA in let f = fun bin res -> extend_pos lb pos1 (P_Appl( extend_pos lb pos1 (P_Iden(extend_pos lb pos1 ([],"∃"), false)), extend_pos lb pos1 (P_Abst([bin], res)))) in (List.fold_right f (fst b) (snd b)) | FORALL -> (* only in Rocq *) let pos1 = current_pos lb in consume_token lb; let b = rocqbinder lb COMMA in extend_pos lb (*__FUNCTION__*) pos1 (P_Prod(fst b, snd b)) | PI -> let pos1 = current_pos lb in consume_token lb; let b = binder lb in extend_pos lb (*__FUNCTION__*) pos1 (P_Prod(fst b, snd b)) | LAMBDA -> let pos1 = current_pos lb in consume_token lb; let b = binder lb in extend_pos lb (*__FUNCTION__*) pos1 (P_Abst(fst b, snd b)) | FUN -> (* only in Rocq *) let pos1 = current_pos lb in consume_token lb; let b = rocqbinder lb THICKARROW in extend_pos lb (*__FUNCTION__*) pos1 (P_Abst(fst b, snd b)) | LET -> let pos1 = current_pos lb in consume_token lb; let x = uid lb in let a = list params_tks params lb in begin match current_token lb with | COLON -> consume_token lb; let b = Some (term lb) in consume ASSIGN lb; let t = term lb in consume IN lb; let u = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_LLet(x, a, b, t, u)) | ASSIGN -> let b = None in consume ASSIGN lb; let t = term lb in consume IN lb; let u = term lb in extend_pos lb (*__FUNCTION__*) pos1 (P_LLet(x, a, b, t, u)) | _ -> expected lb "" [COLON;ASSIGN] end | _ -> expected lb "" [BACKQUOTE;PI;LAMBDA;LET(*;EXISTS;FORALL;FUN*)] and aterm (lb:'token lexbuf): p_term = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | UID _ | QID _ | UID_EXPL _ | QID_EXPL _ -> term_id lb | UNDERSCORE -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 P_Wild | TYPE_TERM -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 P_Type | UID_META s -> let pos1 = current_pos lb in consume_token lb; let i = make_pos pos1 s in if opt DOT lb then extend_pos lb (*__FUNCTION__*) pos1 (P_Meta(i,Array.of_list (env lb))) else {i with elt=P_Meta(i,[||])} | UID_PATT s -> let pos1 = current_pos lb in consume_token lb; let i = if s = "_" then None else Some(make_pos pos1 s) in if opt DOT lb then extend_pos lb (*__FUNCTION__*) pos1 (P_Patt(i, Some(Array.of_list (env lb)))) else make_pos pos1 (P_Patt(i, None)) | L_PAREN -> let pos1 = current_pos lb in consume_token lb; let t = term lb in consume R_PAREN lb; extend_pos lb (*__FUNCTION__*) pos1 (P_Wrap(t)) | L_SQ_BRACKET -> let pos1 = current_pos lb in consume_token lb; let t = term lb in consume R_SQ_BRACKET lb; extend_pos lb (*__FUNCTION__*) pos1 (P_Expl(t)) | INT n -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 (P_NLit([],n)) | QINT(p,n) -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 (P_NLit(p,n)) | STRINGLIT s -> let pos1 = current_pos lb in consume_token lb; make_pos pos1 (P_SLit s) | _ -> expected lb (string_of_tokens "identifier, integer or string literal, \ term between parentheses or square brackets" [TYPE_TERM;UNDERSCORE]) [] and env (lb:'token lexbuf): p_term list = if log_enabled() then log "%s" __FUNCTION__; consume L_SQ_BRACKET lb; let res = list_with_sep term_tks term SEMICOLON lb in consume R_SQ_BRACKET lb; res and binder (lb:'token lexbuf): p_params list * p_term = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | UID _ | UNDERSCORE -> let s = param lb in begin match current_token lb with | UID _ | UNDERSCORE | L_PAREN | L_SQ_BRACKET -> let ps = nelist params_tks params lb in consume COMMA lb; let p = [s], None, false in p::ps, term lb | COMMA -> consume_token lb; let p = [s], None, false in [p], term lb | COLON -> consume_token lb; let a = term lb in consume COMMA lb; let p = [s], Some a, false in [p], term lb | _ -> expected lb "" [UID"";UNDERSCORE;L_PAREN;L_SQ_BRACKET;COMMA;COLON] end | L_PAREN -> let ps = nelist params_tks params lb in consume COMMA lb; ps, term lb | L_SQ_BRACKET -> let ps = nelist params_tks params lb in consume COMMA lb; ps, term lb | _ -> expected lb "" [UID"";UNDERSCORE;L_PAREN;L_SQ_BRACKET] and rocqbinder (lb:'token lexbuf) (terminator:token): p_params list * p_term = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | UID _ | UNDERSCORE -> let s = param lb in begin match current_token lb with | UID _ | UNDERSCORE | L_PAREN -> let ps = list params_tks params lb in consume terminator lb; let p = [s], None, false in p::ps, term lb | COLON -> consume_token lb; let a = term lb in consume terminator lb; let p = [s], Some a, false in [p], term lb | _ -> if current_token lb = terminator then begin consume_token lb; let p = [s], None, false in [p], term lb end else expected lb "" [UID"";UNDERSCORE;L_PAREN;COLON;terminator] end | L_PAREN -> let ps = nelist params_tks params lb in consume terminator lb; ps, term lb | _ -> expected lb "" [UID"";UNDERSCORE;L_PAREN] (* search *) and generalize (lb:'token lexbuf): bool = if log_enabled() then log "%s" __FUNCTION__; opt GENERALIZE lb and relation (lb:'token lexbuf): relation option = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | UID "=" -> consume_token lb; Some Exact | UID ">" -> consume_token lb; Some Inside | UID ("≥"|">=") -> consume_token lb; None | _ -> expected lb (tokens[">";"=";"≥";">="]) [] and where (lb:'token lexbuf): bool * relation option = if log_enabled() then log "%s" __FUNCTION__; let r = relation lb in let g = generalize lb in g,r and asearch (lb:'token lexbuf): search = if log_enabled() then log "%s" __FUNCTION__; match current_token lb with | UID "name" -> consume_token lb; consume (UID "=") lb; QBase(QName (uid lb).elt) | TYPE_QUERY -> begin consume_token lb; match current_token lb with | UID ("≥"|">=") -> consume_token lb; let g = generalize lb in let t = term lb in QBase(QSearch(t,g,Some(QType None))) | _ -> expected lb (tokens["≥";">="]) [] end | UID "anywhere" -> begin consume_token lb; match current_token lb with | UID ("≥"|">=") -> consume_token lb; let g = generalize lb in let t = term lb in QBase(QSearch(t,g,None)) | _ -> expected lb (tokens["≥";">="]) [] end | RULE -> consume_token lb; let r = relation lb in let g = generalize lb in let t = term lb in QBase(QSearch(t,g,Some(QXhs(r,None)))) | UID "spine" -> consume_token lb; let r = relation lb in let g = generalize lb in let t = term lb in QBase(QSearch(t,g,Some(QType(Some(Spine r))))) | UID "concl" -> consume_token lb; let r = relation lb in let g = generalize lb in let t = term lb in QBase(QSearch(t,g,Some(QType(Some(Conclusion r))))) | UID "hyp" -> consume_token lb; let r = relation lb in let g = generalize lb in let t = term lb in QBase(QSearch(t,g,Some(QType(Some(Hypothesis r))))) | UID "lhs" -> consume_token lb; let r = relation lb in let g = generalize lb in let t = term lb in QBase(QSearch(t,g,Some(QXhs(r,Some Lhs)))) | UID "rhs" -> consume_token lb; let r = relation lb in let g = generalize lb in let t = term lb in QBase(QSearch(t,g,Some(QXhs(r,Some Rhs)))) | L_PAREN -> consume_token lb; let q = search lb in consume R_PAREN lb; q | _ -> expected lb (tokens["name";"anywhere";"rule";"lhs";"rhs";"type";"concl"; "hyp";"spine"]) [] and csearch (lb:'token lexbuf): search = if log_enabled() then log "%s" __FUNCTION__; let aq = asearch lb in let aqs = list [WITH] (prefix WITH asearch) lb in List.fold_left (fun x aq -> QOp(x,Intersect,aq)) aq aqs and ssearch (lb:'token lexbuf): search = if log_enabled() then log "%s" __FUNCTION__; let cq = csearch lb in let cqs = list [VBAR] (prefix VBAR csearch) lb in List.fold_left (fun x cq -> QOp(x,Union,cq)) cq cqs and search (lb:'token lexbuf): search = if log_enabled() then log "%s" __FUNCTION__; let q = ssearch lb in let qids = list [IN] (prefix IN qid_or_regexp) lb in List.fold_left (fun x qid -> let n = snd qid.elt in if String.is_string_literal n then QFilter(x,RegExp(String.remove_quotes n)) else QFilter(x,Path(Format.asprintf "%a" Pretty.qident qid))) q qids and alone_search (lb:'token lexbuf) : search = let res = search lb in if current_token lb = EOF then res else expected lb "" [VBAR; IN; WITH] let command (lb:'token lexbuf): p_command = if current_token lb = EOF then raise End_of_file else let c = command lb in match current_token lb with | SEMICOLON -> c | _ -> match c with | {elt=P_symbol sym; pos} -> (* In case of a symbol command, we raise [UnfinishedProof] so that users can see the goals in LSP editors. *) raise (UnfinishedProof(loc_err_msg lb "" [SEMICOLON], sym, pos)) | _ -> expected lb "" [SEMICOLON]
sectionYPositions = computeSectionYPositions($el), 10)"
x-init="setTimeout(() => sectionYPositions = computeSectionYPositions($el), 10)"
>