on master help sign in
tidy up parser library documentation
commitbc92430e0d634e6e966a24718f850284ef29c3bb authormartinbaker <git29f185@martinb.com> dateThu 2 Jan 2020, 11:18 (7 years ago) parentaf2766c
5 files changed+163−140
docs/image/parserModules.png docs/image/parserModules.svg+62−62 docs/parserLibrary/introduction.rst+4−4 docs/parserLibrary/lexer.rst+5−6 docs/parserLibrary/parser.rst+92−68
docs/image/parserModules.png

Binary file not shown.

docs/image/parserModules.svg+62−62
@@ -318,7 +318,7 @@
318318 inkscape:stockid="Arrow1Mend">
319319 <path
320320 transform="scale(0.4) rotate(180) translate(10,0)"
321− style="fill-rule:evenodd;stroke:#0000ff;stroke-width:1pt;stroke-opacity:1;fill:#0000ff;fill-opacity:1"
321+ style="fill-rule:evenodd;stroke:#ff0000;stroke-width:1pt;stroke-opacity:1;fill:#ff0000;fill-opacity:1"
322322 d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
323323 id="path1001" />
324324 </marker>
@@ -334,7 +334,7 @@
334334 <path
335335 id="path995"
336336 d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
337− style="fill-rule:evenodd;stroke:#0000ff;stroke-width:1pt;stroke-opacity:1;fill:#0000ff;fill-opacity:1"
337+ style="fill-rule:evenodd;stroke:#ff0000;stroke-width:1pt;stroke-opacity:1;fill:#ff0000;fill-opacity:1"
338338 transform="scale(0.4) rotate(180) translate(10,0)" />
339339 </marker>
340340 <marker
@@ -348,7 +348,7 @@
348348 inkscape:collect="always">
349349 <path
350350 transform="scale(0.4) rotate(180) translate(10,0)"
351− style="fill-rule:evenodd;stroke:#0000ff;stroke-width:1pt;stroke-opacity:1;fill:#0000ff;fill-opacity:1"
351+ style="fill-rule:evenodd;stroke:#ff0000;stroke-width:1pt;stroke-opacity:1;fill:#ff0000;fill-opacity:1"
352352 d="M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z "
353353 id="path989" />
354354 </marker>
@@ -436,13 +436,13 @@
436436 inkscape:pageshadow="2"
437437 inkscape:zoom="1"
438438 inkscape:cx="368.33949"
439− inkscape:cy="617.07597"
439+ inkscape:cy="547.05121"
440440 inkscape:document-units="mm"
441441 inkscape:current-layer="layer1"
442442 showgrid="false"
443443 inkscape:window-width="1800"
444444 inkscape:window-height="1011"
445− inkscape:window-x="0"
445+ inkscape:window-x="86"
446446 inkscape:window-y="0"
447447 inkscape:window-maximized="0"
448448 inkscape:snap-nodes="false" />
@@ -585,11 +585,11 @@
585585 id="text931"
586586 y="218.41846"
587587 x="36.512497"
588− style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:0.26458332"
588+ style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:0.26458332;"
589589 xml:space="preserve"
590590 inkscape:export-xdpi="61.120499"
591591 inkscape:export-ydpi="61.120499"><tspan
592− style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#0000ff;stroke-width:0.26458332"
592+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#ff0000;stroke-width:0.26458332;"
593593 y="218.41846"
594594 x="36.512497"
595595 id="tspan929"
@@ -615,11 +615,11 @@
615615 height="6.3500061"
616616 width="43.656254"
617617 id="rect937"
618− style="opacity:1;vector-effect:none;fill:none;fill-opacity:0.97596154;fill-rule:evenodd;stroke:#0000ff;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
618+ style="opacity:1;vector-effect:none;fill:none;fill-opacity:0.97596154;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
619619 <rect
620620 inkscape:export-ydpi="61.120499"
621621 inkscape:export-xdpi="61.120499"
622− style="opacity:1;vector-effect:none;fill:none;fill-opacity:0.97596154;fill-rule:evenodd;stroke:#0000ff;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
622+ style="opacity:1;vector-effect:none;fill:none;fill-opacity:0.97596154;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
623623 id="rect939"
624624 width="42.862495"
625625 height="6.8791728"
@@ -650,7 +650,7 @@
650650 inkscape:export-ydpi="61.120499"
651651 inkscape:export-xdpi="61.120499"
652652 xml:space="preserve"
653− style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:0.26458332"
653+ style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:0.26458332;"
654654 x="23.220526"
655655 y="251.01649"
656656 id="text971"><tspan
@@ -658,9 +658,9 @@
658658 id="tspan969"
659659 x="23.220526"
660660 y="251.01649"
661− style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#0000ff;stroke-width:0.26458332">module Text.Lexer.Core</tspan></text>
661+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#ff0000;stroke-width:0.26458332;">module Text.Lexer.Core</tspan></text>
662662 <rect
663− style="opacity:1;vector-effect:none;fill:none;fill-opacity:0.97596154;fill-rule:evenodd;stroke:#0000ff;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
663+ style="opacity:1;vector-effect:none;fill:none;fill-opacity:0.97596154;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
664664 id="rect973"
665665 width="47.889587"
666666 height="6.3500061"
@@ -669,7 +669,7 @@
669669 inkscape:export-xdpi="61.120499"
670670 inkscape:export-ydpi="61.120499" />
671671 <path
672− style="fill:none;stroke:#0000ff;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker991)"
672+ style="fill:none;stroke:#ff0000;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker991)"
673673 d="m 48.369316,228.83873 0.04943,-6.71548"
674674 id="path975"
675675 inkscape:connector-curvature="0"
@@ -680,11 +680,11 @@
680680 id="text979"
681681 y="241.96643"
682682 x="23.283329"
683− style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:0.26458332"
683+ style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:0.26458332;"
684684 xml:space="preserve"
685685 inkscape:export-xdpi="61.120499"
686686 inkscape:export-ydpi="61.120499"><tspan
687− style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#0000ff;stroke-width:0.26458332"
687+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#ff0000;stroke-width:0.26458332;"
688688 y="241.96643"
689689 x="23.283329"
690690 id="tspan977"
@@ -697,12 +697,12 @@
697697 height="6.2469702"
698698 width="43.853985"
699699 id="rect981"
700− style="opacity:1;vector-effect:none;fill:none;fill-opacity:0.97596154;fill-rule:evenodd;stroke:#0000ff;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
700+ style="opacity:1;vector-effect:none;fill:none;fill-opacity:0.97596154;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1" />
701701 <text
702702 inkscape:export-ydpi="61.120499"
703703 inkscape:export-xdpi="61.120499"
704704 xml:space="preserve"
705− style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:0.26458332"
705+ style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:0.26458332;"
706706 x="23.18244"
707707 y="233.68523"
708708 id="text985"><tspan
@@ -710,9 +710,9 @@
710710 id="tspan983"
711711 x="23.18244"
712712 y="233.68523"
713− style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#0000ff;stroke-width:0.26458332">module Text.Token</tspan></text>
713+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#ff0000;stroke-width:0.26458332;">module Text.Token</tspan></text>
714714 <rect
715− style="opacity:1;vector-effect:none;fill:none;fill-opacity:0.97596154;fill-rule:evenodd;stroke:#0000ff;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
715+ style="opacity:1;vector-effect:none;fill:none;fill-opacity:0.97596154;fill-rule:evenodd;stroke:#ff0000;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
716716 id="rect987"
717717 width="39.011257"
718718 height="5.9464455"
@@ -727,9 +727,9 @@
727727 inkscape:connector-curvature="0"
728728 id="path993"
729729 d="M 62.998384,237.01083 62.846037,221.92147"
730− style="fill:none;stroke:#0000ff;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker997)" />
730+ style="fill:#ff0000;stroke:#ff0000;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker997)" />
731731 <path
732− style="fill:none;stroke:#0000ff;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker1003)"
732+ style="fill:#ff0000;stroke:#ff0000;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker1003)"
733733 d="M 67.336659,246.29272 67.083422,221.71969"
734734 id="path999"
735735 inkscape:connector-curvature="0"
@@ -758,9 +758,9 @@
758758 id="text1019"
759759 y="218.94762"
760760 x="96.837494"
761− style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:0.26458332"
761+ style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:0.26458332;"
762762 xml:space="preserve"><tspan
763− style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#0000ff;stroke-width:0.26458332"
763+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#ff0000;stroke-width:0.26458332;"
764764 y="218.94762"
765765 x="96.837494"
766766 id="tspan1017"
@@ -932,22 +932,22 @@
932932 sodipodi:nodetypes="cc" />
933933 <text
934934 id="text950"
935− y="99.410255"
936− x="145.19345"
935+ y="104.70191"
936+ x="22.426785"
937937 style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:0.26458332"
938938 xml:space="preserve"
939939 inkscape:export-xdpi="61.120499"
940940 inkscape:export-ydpi="61.120499"><tspan
941941 style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#0000ff;stroke-width:0.26458332"
942− y="99.410255"
943− x="145.19345"
942+ y="104.70191"
943+ x="22.426785"
944944 id="tspan948"
945945 sodipodi:role="line">module Core.Core</tspan></text>
946946 <rect
947947 inkscape:export-ydpi="61.120499"
948948 inkscape:export-xdpi="61.120499"
949− y="94.912086"
950− x="143.60594"
949+ y="100.20374"
950+ x="20.839275"
951951 height="9.7895899"
952952 width="47.889587"
953953 id="rect952"
@@ -957,57 +957,57 @@
957957 inkscape:export-xdpi="61.120499"
958958 xml:space="preserve"
959959 style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:0.26458332"
960− x="145.72261"
961− y="103.11442"
960+ x="22.955944"
961+ y="108.40608"
962962 id="text956"><tspan
963963 sodipodi:role="line"
964964 id="tspan954"
965− x="145.72261"
966− y="103.11442"
965+ x="22.955944"
966+ y="108.40608"
967967 style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:3.52777767px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#000000;stroke-width:0.26458332">error messages</tspan></text>
968968 <text
969969 inkscape:export-ydpi="61.120499"
970970 inkscape:export-xdpi="61.120499"
971971 xml:space="preserve"
972972 style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:0.26458332"
973− x="83.81012"
974− y="78.243584"
973+ x="79.312202"
974+ y="92.266502"
975975 id="text960"><tspan
976976 sodipodi:role="line"
977977 id="tspan958"
978− x="83.81012"
979− y="78.243584"
978+ x="79.312202"
979+ y="92.266502"
980980 style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#0000ff;stroke-width:0.26458332">module Core.CompileExpr</tspan></text>
981981 <rect
982982 style="opacity:1;vector-effect:none;fill:none;fill-opacity:0.97596154;fill-rule:evenodd;stroke:#0000ff;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0;stroke-opacity:1"
983983 id="rect962"
984984 width="61.912495"
985985 height="18.785419"
986− x="82.22261"
987− y="73.745415"
986+ x="77.724693"
987+ y="87.768333"
988988 inkscape:export-xdpi="61.120499"
989989 inkscape:export-ydpi="61.120499" />
990990 <text
991991 id="text966"
992− y="81.947746"
993− x="84.339279"
992+ y="95.970665"
993+ x="79.841362"
994994 style="font-style:normal;font-weight:normal;font-size:3.52777767px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:0.26458332"
995995 xml:space="preserve"
996996 inkscape:export-xdpi="61.120499"
997997 inkscape:export-ydpi="61.120499"><tspan
998998 style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:3.52777767px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#000000;stroke-width:0.26458332"
999− y="81.947746"
1000− x="84.339279"
999+ y="95.970665"
1000+ x="79.841362"
10011001 sodipodi:role="line"
10021002 id="tspan968">Representation of expressions ready</tspan><tspan
10031003 style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:3.52777767px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#000000;stroke-width:0.26458332"
1004− y="86.357468"
1005− x="84.339279"
1004+ y="100.38039"
1005+ x="79.841362"
10061006 sodipodi:role="line"
10071007 id="tspan974">for compiling: CExp</tspan><tspan
10081008 style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:3.52777767px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#000000;stroke-width:0.26458332"
1009− y="90.767189"
1010− x="84.339279"
1009+ y="104.79011"
1010+ x="79.841362"
10111011 sodipodi:role="line"
10121012 id="tspan972">Type erased, explicit case trees</tspan></text>
10131013 <text
@@ -1047,22 +1047,22 @@
10471047 sodipodi:role="line">command line options</tspan></text>
10481048 <text
10491049 id="text988"
1050− y="106.82006"
1051− x="22.69136"
1050+ y="89.886726"
1051+ x="22.162193"
10521052 style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:0.26458332"
10531053 xml:space="preserve"
10541054 inkscape:export-xdpi="61.120499"
10551055 inkscape:export-ydpi="61.120499"><tspan
10561056 style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#0000ff;stroke-width:0.26458332"
1057− y="106.82006"
1058− x="22.69136"
1057+ y="89.886726"
1058+ x="22.162193"
10591059 id="tspan986"
10601060 sodipodi:role="line">module Idris.Error</tspan></text>
10611061 <rect
10621062 inkscape:export-ydpi="61.120499"
10631063 inkscape:export-xdpi="61.120499"
1064− y="102.32182"
1065− x="21.103861"
1064+ y="85.388489"
1065+ x="20.574694"
10661066 height="9.5250101"
10671067 width="37.835419"
10681068 id="rect990"
@@ -1072,17 +1072,17 @@
10721072 inkscape:export-xdpi="61.120499"
10731073 xml:space="preserve"
10741074 style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:1.25;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#0000ff;fill-opacity:1;stroke:none;stroke-width:0.26458332"
1075− x="23.220528"
1076− y="110.52423"
1075+ x="22.69136"
1076+ y="93.590897"
10771077 id="text994"><tspan
10781078 sodipodi:role="line"
10791079 id="tspan992"
1080− x="23.220528"
1081− y="110.52423"
1080+ x="22.69136"
1081+ y="93.590897"
10821082 style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:3.52777767px;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#000000;stroke-width:0.26458332">perror</tspan></text>
10831083 <path
10841084 style="fill:none;stroke:#0000ff;stroke-width:0.70555556;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#marker1000)"
1085− d="m 142.54761,98.087086 c -7.32197,0.078 -68.613479,2.584834 -83.608332,4.234734"
1085+ d="m 66.876776,99.410007 c -0.17822,-10.50534 -0.880145,-7.9985 -7.143748,-8.99444"
10861086 id="path996"
10871087 inkscape:connector-curvature="0"
10881088 inkscape:export-xdpi="61.120499"
@@ -1105,7 +1105,7 @@
11051105 inkscape:export-ydpi="61.120499" />
11061106 <text
11071107 xml:space="preserve"
1108− style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:0.40000001;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
1108+ style="font-style:normal;font-weight:normal;font-size:10.58333302px;line-height:0.40000001;font-family:sans-serif;letter-spacing:0px;word-spacing:0px;fill:#ff0000;fill-opacity:1;stroke:none;stroke-width:0.26458332;"
11091109 x="158.75"
11101110 y="226.09137"
11111111 id="text1473"
@@ -1115,16 +1115,16 @@
11151115 id="tspan1471"
11161116 x="158.75"
11171117 y="226.09137"
1118− style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;line-height:0.40000001;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#000000;stroke-width:0.26458332">'text' modules are</tspan><tspan
1118+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;line-height:0.40000001;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#ff0000;stroke-width:0.26458332;">'text' modules are</tspan><tspan
11191119 sodipodi:role="line"
11201120 x="158.75"
11211121 y="230.92491"
1122− style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;line-height:0.40000001;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#000000;stroke-width:0.26458332"
1122+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;line-height:0.40000001;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#ff0000;stroke-width:0.26458332;"
11231123 id="tspan1475">also in Idris 1</tspan><tspan
11241124 sodipodi:role="line"
11251125 x="158.75"
11261126 y="235.75845"
1127− style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;line-height:0.40000001;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#000000;stroke-width:0.26458332"
1127+ style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333311px;line-height:0.40000001;font-family:sans-serif;-inkscape-font-specification:'sans-serif Bold';fill:#ff0000;stroke-width:0.26458332;"
11281128 id="tspan1477">library.</tspan></text>
11291129 <path
11301130 inkscape:connector-curvature="0"
docs/parserLibrary/introduction.rst+4−4
@@ -52,13 +52,13 @@ Idris 2 has at least 3 compilers:
5252 PTerm (and eventually TT structure).
5353- REPL - compiles input from the command line.
5454
55−The following diagram is my attempt to work out how the modules in Idris 2 fit together.
55+The following diagram is my first attempt to work out how some of the modules in
56+Idris 2 fit together (with a few of the dependencies between them shown). The
57+Idris 1 library is based on the modules at the bottom of the diagram (shown
58+in red).
5659
5760.. image:: ../image/parserModules.png
5861 :width: 460px
5962 :height: 496px
6063 :alt: diagram illustrating these stages of lexer and parser
6164
62−
63−
64−
docs/parserLibrary/lexer.rst+5−6
@@ -26,8 +26,7 @@ In order to construct this list of tokens we need:
2626- A way to recognise the tokens in the input string.
2727- A way to construct these individual tokens.
2828
29−This is given by the TokenMap. This is a mapping from lexers to the tokens
30−they produce. This is a list of pairs:
29+This is given by the TokenMap which is a list of pairs containing this information:
3130
3231.. code-block:: idris
3332
@@ -108,7 +107,7 @@ If a recogniser does not consume input there is a danger of an infinite loop.
108107To prevent this the recogniser is dependent on a boolean called 'consumes' which
109108is true if the recogniser is guaranteed to consume at least one character.
110109
111−The constructors of Recognise allow us to ensure that, event though parts of
110+The constructors of Recognise allow us to ensure that, even though parts of
112111the recogniser may not consume, overall the recogniser will consume.
113112
114113Since 'Recognise True' is more common than 'Recognise False' it is convenient to
@@ -133,12 +132,12 @@ when the indent decreases.
133132
134133This topic needs to be more fully expanded here. Until someone does that, a
135134possible way to get more information is to see how it is done in Idris 2
136−_`here`: https://github.com/edwinb/Idris2/blob/master/src/Parser/Lexer.idr
135+: https://github.com/edwinb/Idris2/blob/master/src/Parser/Lexer.idr
137136
138137Simple Expression Example for Lexer
139138-----------------------------------
140139
141−On this page we will implement a lexer to lex a very simple expression as
140+On this page we will implement a lexer to 'lex' a very simple expression as
142141a running example, on the next page, we will go on to implement a parser for it.
143142
144143First import the lexer and parser code:
@@ -268,7 +267,7 @@ input string as parameters:
268267 Int,
269268 String)
270269
271−The lexer uses potentially infinite data structures. It has recursive arguments (codata type) so code is lazy. In the example the indexes have not been computed but we can
270+The lexer uses potentially infinite data structures. It has recursive arguments (codata type) so code is lazy. In the output above the indexes have not been computed but we can
272271pick out the tokens:
273272
274273- (Number 1)
docs/parserLibrary/parser.rst+92−68
@@ -12,14 +12,14 @@ To run our parser we call 'parse'. This requires a Grammar and the output from t
1212
1313If successful this returns 'Right' with a pair of
1414
15−- the parse result
16−- the unparsed tokens (the remaining input)
15+- the parse result.
16+- the unparsed tokens (the remaining input).
1717
1818otherwise it returns 'Left' with the error message.
1919
2020So we need to define the Grammar for our parser, this is done using the following
21−'Grammar' data structure, this is a combinator structure similar in principle to the
22−recogniser combinator for the lexer which was discussed on the previous page.
21+'Grammar' data structure. This is a combinator structure, similar in principle to the
22+recogniser combinator for the lexer, which was discussed on the previous page.
2323
2424As with the Recogniser the Grammar type is dependent on a boolean 'consumes'
2525value which allows us to ensure that complicated Grammar structures will always
@@ -71,28 +71,31 @@ Parser Example
7171On the previous page we implemented a lexer to 'lex' a very simple expression, on
7272this page we will go on to implement a parser for this running example.
7373
74−Expressed in Backus–Naur form (BNF) the syntax we are aiming at is something
75−like this:
74+.. list-table::
7675
77−.. code-block:: idris
76+ * - Expressed in Backus–Naur form (BNF) the syntax we are aiming at is something
77+ like this:
78+ - .. code-block:: idris
7879
79− <expr> ::= <integer literal>
80+ <expr> ::= <integer literal>
8081 | <expr>'+'<expr>
8182 | <expr>'-'<expr>
8283 | <expr>'*'<expr>
8384 | '('<expr>')'
8485
85− <integer literal> ::= <digit>|<integer literal><digit>
86+ <integer literal> ::= <digit>|<integer literal><digit>
8687
87−To start, here is a Grammar to parse an integer literal (that is, a sequence of
88−numbers).
88+.. list-table::
8989
90−.. code-block:: idris
90+ * - To start, here is a Grammar to parse an integer literal (that is, a
91+ sequence of numbers).
9192
92− export
93− intLiteral : Rule Integer
94− intLiteral
95− = terminal (\x => case tok x of
93+ - .. code-block:: idris
94+
95+ export
96+ intLiteral : Rule Integer
97+ intLiteral
98+ = terminal (\x => case tok x of
9699 Number i => Just i
97100 _ => Nothing)
98101
@@ -137,33 +140,41 @@ successful, this is because we are not specifically checking for end-of-file.
137140 (Integer, List (TokenData ExpressionToken))
138141 *parserEx>
139142
140−The 'intLiteral' function above uses the 'terminal' function to construct
141−the grammar, this is defined here
143+.. list-table::
144+
145+ * - The 'intLiteral' function above uses the 'terminal' function to
146+ construct the grammar
147+ - .. code-block:: idris
148+
149+ ||| Succeeds if running the predicate on the
150+ ||| next token returns Just x, returning x.
151+ ||| Otherwise fails.
152+ export
153+ terminal : (tok -> Maybe a) -> Grammar tok True a
154+ terminal = Terminal
155+
156+This is defined here
142157: https://github.com/idris-lang/Idris-dev/blob/master/libs/contrib/Text/Parser/Core.idr
143158Idris 2 uses a slightly different version which stores an error message like
144159"Expected integer literal" which can be output if the rule fails
145160: https://github.com/edwinb/Idris2/blob/master/src/Text/Parser/Core.idr
146161
147−.. code-block:: idris
148−
149− ||| Succeeds if running the predicate on the next token returns Just x,
150− ||| returning x. Otherwise fails.
151− export
152− terminal : (tok -> Maybe a) -> Grammar tok True a
153− terminal = Terminal
162+.. list-table::
154163
155−The 'terminal' function is also used to construct the other elements of the
156−grammar that we require, for instance, opening parenthesis:
164+ * - The 'terminal' function is also used to construct the other
165+ elements of the grammar that we require, for instance,
166+ opening parenthesis:
157167
158−.. code-block:: idris
168+ - .. code-block:: idris
159169
160− openParen : Rule Integer
161− openParen = terminal (\x => case tok x of
170+ openParen : Rule Integer
171+ openParen = terminal (\x => case tok x of
162172 OParen => Just 0
163173 _ => Nothing)
164174
165175Integer value is not really relevant for parenthesis so '0' is used as
166176a default value.
177+
167178As before, we can test this out with a function like this:
168179
169180.. code-block:: idris
@@ -236,42 +247,49 @@ token lists are not:
236247 OParen]) : Either (ParseError (TokenData ExpressionToken))
237248 (Integer, List (TokenData ExpressionToken))
238249
239−The closing parenthesis is constructed in the same way.
250+.. list-table::
240251
241−.. code-block:: idris
252+ * - The closing parenthesis is constructed in the same way.
253+
254+ - .. code-block:: idris
242255
243− closeParen : Rule Integer
244− closeParen = terminal (\x => case tok x of
256+ closeParen : Rule Integer
257+ closeParen = terminal (\x => case tok x of
245258 CParen => Just 0
246259 _ => Nothing)
247260
248−Now we can generate a Grammar for an expression inside parenthesis like this.
261+.. list-table::
249262
250−.. code-block:: idris
263+ * - Now we can generate a Grammar for an expression inside parenthesis like this.
264+
265+ - .. code-block:: idris
251266
252− paren : Rule Integer -> Rule Integer
253− paren exp = openParen *> exp <* closeParen
267+ paren : Rule Integer -> Rule Integer
268+ paren exp = openParen *> exp <* closeParen
254269
255270The use of '*>' and '<*' instead of '<*>' is an easy way to use the integer
256271value from the inner expression.
257272
258−Now for the operations, in this case: '+', '-' and '*'.
259−The syntax we require is that operators like '+' are infix operators, which
260−would require a definition like this:
273+.. list-table::
261274
262−.. code-block:: idris
275+ * - Now for the operations, in this case: '+', '-' and '*'.
276+ The syntax we require is that operators like '+' are infix operators, which
277+ would require a definition like this:
263278
264− expr = (add expr (op "+") expr)
279+ - .. code-block:: idris
280+
281+ expr = (add expr (op "+") expr)
265282
266283This is a potentially infinite structure which is not total.
267−In order to work up to this gradually I will start with prefix operators (sometimes known as Polish notation)
268−then modify later for infix operators.
284+In order to work up to this gradually I will start with prefix operators (sometimes known as Polish notation) then modify later for infix operators.
269285
270−So prefix operators would have this sort of form:
286+.. list-table::
271287
272−.. code-block:: idris
288+ * - So prefix operators would have this sort of form:
273289
274− expr = (add (op "+") expr expr)
290+ - .. code-block:: idris
291+
292+ expr = (add (op "+") expr expr)
275293
276294where 'op' is defined like this:
277295
@@ -284,19 +302,21 @@ where 'op' is defined like this:
284302 (Operator s1) => if s==s1 then Just 0 else Nothing
285303 _ => Nothing)
286304
287−and 'add' is defined like this:
305+.. list-table::
288306
289−.. code-block:: idris
307+ * - and 'add' is defined like this:
290308
291− addInt : Integer -> Integer -> Integer
292− addInt a b = a+b
309+ - .. code-block:: idris
293310
294− export
295− add : Grammar tok c1 Integer ->
296− Grammar tok c2 Integer ->
297− Grammar tok c3 Integer ->
298− Grammar tok ((c1 || c2) || c3) Integer
299− add x y z = map addInt (x *> y) <*> z
311+ addInt : Integer -> Integer -> Integer
312+ addInt a b = a+b
313+
314+ export
315+ add : Grammar tok c1 Integer ->
316+ Grammar tok c2 Integer ->
317+ Grammar tok c3 Integer ->
318+ Grammar tok ((c1 || c2) || c3) Integer
319+ add x y z = map addInt (x *> y) <*> z
300320
301321Where:
302322
@@ -343,22 +363,26 @@ partial as it is a potentially infinite structure and so not total.
343363 <|> (mult (op "*") expr expr)
344364 <|> intLiteral <|> (paren expr)
345365
346−To make the testing easier we can use this function:
366+.. list-table::
347367
348−.. code-block:: idris
368+ * - To make the testing easier we can use this function:
349369
350− partial
351− test : String -> Either (ParseError (TokenData ExpressionToken))
370+ - .. code-block:: idris
371+
372+ partial
373+ test : String -> Either (ParseError (TokenData ExpressionToken))
352374 (Integer, List (TokenData ExpressionToken))
353− test s = parse expr (fst (lex expressionTokens s))
375+ test s = parse expr (fst (lex expressionTokens s))
354376
355−First test a valid (prefix) expression:
377+.. list-table::
356378
357−.. code-block:: idris
379+ * - First test a valid (prefix) expression:
380+
381+ - .. code-block:: idris
358382
359− *parserEx> test "+1*6(4)"
360− Right (25,
361− []) : Either (ParseError (TokenData ExpressionToken))
383+ *parserEx> test "+1*6(4)"
384+ Right (25,
385+ []) : Either (ParseError (TokenData ExpressionToken))
362386 (Integer, List (TokenData ExpressionToken))
363387
364388Then an invalid syntax: