diff 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
line wrap: on
line diff
--- a/modules/parser.tp	Thu Apr 16 08:46:35 2015 -0700
+++ b/modules/parser.tp	Fri Apr 17 17:50:47 2015 -0700
@@ -756,6 +756,18 @@
 	} yield: {
 		ast symbol: Name
 	}
+	
+	typedsym <- matchOne: [
+		match: Sym . hws . "(" . ws . Type . ws .  ")" where: {
+			Sym <- match: symexpr
+			//TODO: Define full type syntax
+			Type <- match: symexpr
+		} yield: {
+			ast symbol: (Sym name) withType: (option value: Type)
+		}
+		symexpr
+	]
+	
 
 	namepart <- match: hws . Symbol . ":" where: {
 		Symbol <- match: symexpr
@@ -857,7 +869,7 @@
 
 	assignment <- match: ws . Symbol . hws . "<-" . Expr where: {
 		Symbol <- matchOne: [
-			symexpr
+			typedsym
 			opsym
 		]
 		Expr <- match: expr
@@ -906,17 +918,30 @@
 	} yield: {
 		Pre . Initial . Rest
 	}
+	
+	typedarg <- match: Name . TypeInfo where: {
+		Name <- match: argname
+		TypeInfo <- matchOne: [
+			match: hws . "(" . ws . Type . ws . ")" where: {
+				//TODO: Define full type syntax
+				Type <- match: symexpr
+			} yield: { option value: Type }
+			match: "" yield: { option none }
+		]
+	} yield: {
+		ast symbol: Name withType: TypeInfo
+	}
 
 	lambda <- match: hws . Arglist . hws . "{" . ws . Exprs . "}" where: {
 		Arglist <- matchOne: [
 			match: ":" . First . Rest where: {
-				First <- match: symexpr
-				Rest <- zeroPlus: argname
+				First <- match: typedsym
+				Rest <- zeroPlus: typedarg
 			} yield: {
 				if: (Rest length) = 0 {
 					Rest <- []
 				}
-				":" . (First name) | Rest
+				":" . First | Rest
 			}
 			match: "" yield: { [] }
 		]