Mercurial > repos > tabletprog
comparison modules/parser.tp @ 358:27477c8c2823
Add support for simple type annotations in parser and update llhello sample with a possible new low-level dialect syntax leveraging those annotations
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 17 Apr 2015 17:50:47 -0700 |
parents | 9d93e65a34be |
children | 0b83f15e819d |
comparison
equal
deleted
inserted
replaced
357:f237d0cae58b | 358:27477c8c2823 |
---|---|
754 symexpr <- match: Name where: { | 754 symexpr <- match: Name where: { |
755 Name <- match: (onePlus: (charClass: "a-zA-Z_@!?")) . (zeroPlus: ((matchOne: [":" ""]) . (charClass: "a-zA-Z_@!?0-9"))) | 755 Name <- match: (onePlus: (charClass: "a-zA-Z_@!?")) . (zeroPlus: ((matchOne: [":" ""]) . (charClass: "a-zA-Z_@!?0-9"))) |
756 } yield: { | 756 } yield: { |
757 ast symbol: Name | 757 ast symbol: Name |
758 } | 758 } |
759 | |
760 typedsym <- matchOne: [ | |
761 match: Sym . hws . "(" . ws . Type . ws . ")" where: { | |
762 Sym <- match: symexpr | |
763 //TODO: Define full type syntax | |
764 Type <- match: symexpr | |
765 } yield: { | |
766 ast symbol: (Sym name) withType: (option value: Type) | |
767 } | |
768 symexpr | |
769 ] | |
770 | |
759 | 771 |
760 namepart <- match: hws . Symbol . ":" where: { | 772 namepart <- match: hws . Symbol . ":" where: { |
761 Symbol <- match: symexpr | 773 Symbol <- match: symexpr |
762 } yield: { | 774 } yield: { |
763 #{ | 775 #{ |
855 ast symbol: Name | 867 ast symbol: Name |
856 } | 868 } |
857 | 869 |
858 assignment <- match: ws . Symbol . hws . "<-" . Expr where: { | 870 assignment <- match: ws . Symbol . hws . "<-" . Expr where: { |
859 Symbol <- matchOne: [ | 871 Symbol <- matchOne: [ |
860 symexpr | 872 typedsym |
861 opsym | 873 opsym |
862 ] | 874 ] |
863 Expr <- match: expr | 875 Expr <- match: expr |
864 } yield: { | 876 } yield: { |
865 ast assign: Expr to: Symbol | 877 ast assign: Expr to: Symbol |
904 Initial <- onePlus: (charClass: "a-zA-Z_!?@") | 916 Initial <- onePlus: (charClass: "a-zA-Z_!?@") |
905 Rest <- zeroPlus: (charClass: "a-zA-Z_!?@0-9") | 917 Rest <- zeroPlus: (charClass: "a-zA-Z_!?@0-9") |
906 } yield: { | 918 } yield: { |
907 Pre . Initial . Rest | 919 Pre . Initial . Rest |
908 } | 920 } |
921 | |
922 typedarg <- match: Name . TypeInfo where: { | |
923 Name <- match: argname | |
924 TypeInfo <- matchOne: [ | |
925 match: hws . "(" . ws . Type . ws . ")" where: { | |
926 //TODO: Define full type syntax | |
927 Type <- match: symexpr | |
928 } yield: { option value: Type } | |
929 match: "" yield: { option none } | |
930 ] | |
931 } yield: { | |
932 ast symbol: Name withType: TypeInfo | |
933 } | |
909 | 934 |
910 lambda <- match: hws . Arglist . hws . "{" . ws . Exprs . "}" where: { | 935 lambda <- match: hws . Arglist . hws . "{" . ws . Exprs . "}" where: { |
911 Arglist <- matchOne: [ | 936 Arglist <- matchOne: [ |
912 match: ":" . First . Rest where: { | 937 match: ":" . First . Rest where: { |
913 First <- match: symexpr | 938 First <- match: typedsym |
914 Rest <- zeroPlus: argname | 939 Rest <- zeroPlus: typedarg |
915 } yield: { | 940 } yield: { |
916 if: (Rest length) = 0 { | 941 if: (Rest length) = 0 { |
917 Rest <- [] | 942 Rest <- [] |
918 } | 943 } |
919 ":" . (First name) | Rest | 944 ":" . First | Rest |
920 } | 945 } |
921 match: "" yield: { [] } | 946 match: "" yield: { [] } |
922 ] | 947 ] |
923 Exprs <- zeroPlus: expr | 948 Exprs <- zeroPlus: expr |
924 } yield: { | 949 } yield: { |