changeset 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 f237d0cae58b
children 023c29e1f595
files modules/ast.tp modules/parser.tp
diffstat 2 files changed, 41 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/modules/ast.tp	Thu Apr 16 08:46:35 2015 -0700
+++ b/modules/ast.tp	Fri Apr 17 17:50:47 2015 -0700
@@ -103,13 +103,18 @@
 				}
 			}
 		}
-
-		symbol <- :_name {
+		
+		symbol:withType <- :_name :_type {
 			#{
 				nodeType <- { _symbol }
+				type <- _type
 				name <- _name
 				stringIndent <- :indent {
-					name
+					_type value: :type {
+						name . " (" . type . ")"
+					} none: {
+						name
+					}
 				}
 				string <- {
 					stringIndent: ""
@@ -120,6 +125,10 @@
 			}
 		}
 
+		symbol <- :_name {
+			symbol: _name withType: (option none)
+		}
+
 		funcall:withArgs:hasReceiver? <- :_tocall :_args :_receiver? {
 			#{
 				nodeType <- { _call }
--- 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: { [] }
 		]