diff parse.rhope @ 131:0a4682be2db2

Modify lexer and new parser to work in compiler
author Mike Pavone <pavone@retrodev.com>
date Fri, 05 Nov 2010 02:43:34 +0000
parents a4d2d633a356
children 1f238280047f
line wrap: on
line diff
--- a/parse.rhope	Fri Nov 05 02:42:45 2010 +0000
+++ b/parse.rhope	Fri Nov 05 02:43:34 2010 +0000
@@ -8,12 +8,12 @@
 
 Error[msg,text:out]
 {
-	out <- [[[Build["Error"]]Message <<[msg]]Line << [ [[text]Line >>]+[1] ]]Column << [ [[text]Column >>]+[1] ]
+	out <- [[[Build[Error()]]Message <<[msg]]Line << [ [[text]Line >>]+[1] ]]Column << [ [[text]Column >>]+[1] ]
 }
 
-To String@Error[error:out]
+String@Error[error:out]
 {
-	out <- [[[[[error]Message >>]Append[" on line "]]Append[[error]Line >>]]Append[" at column "]]Append[[error]Column >>]
+	out <- [[[[[error]Message >>]Append[" on line "]]Append[String[[error]Line >>]]]Append[" at column "]]Append[String[[error]Column >>]]
 }
 
 Blueprint PImport Node
@@ -23,7 +23,12 @@
 
 PImport Node[file:out]
 {
-	out <- [Build["PImport Node"]]File <<[file]
+	out <- [Build[PImport Node()]]File <<[file]
+}
+
+String@PImport Node[node:out]
+{
+	out <- ["Import: "]Append[[node]File >>]
 }
 
 Blueprint Worker Node
@@ -38,7 +43,7 @@
 Add Node Input@Worker Node[node,input:out]
 {
 	Print["Add Node Input"]
-	Print[["Input: "]Append[To String[input]]]
+	Print[["Input: "]Append[String[input]]]
 	out <- [node]Inputs <<[[[node]Inputs >>]Append[input]]
 }
 
@@ -47,6 +52,15 @@
 	out <- [node]Outputs <<[[[node]Outputs >>]Append[output]]
 }
 
+String@Worker Node[node:out]
+{
+	out <- [[[[["Worker: "]Append[[node]Name >>]
+		]Append[ ["\n\tBlueprint:\t"]Append[String[[node]Blueprint >>]] ]
+		]Append[ ["\n\tInputs: \t"]Append[[[node]Inputs >>]Join[", "]] ]
+		]Append[ ["\n\tOutputs:\t"]Append[[[node]Outputs >>]Join[", "]] ]
+		]Append[ ["\n\tTree:   \t"]Append[ [[String[[node]Tree >>]]Split["\n"]]Join["\n\t"] ] ]
+}
+
 Blueprint Statement
 {
 	Expression
@@ -56,7 +70,7 @@
 
 Statement[expression,assignments:out]
 {
-	out <- [[[Build["Statement"]]Expression <<[expression]]Assignments <<[assignments]]Blocks <<[()]
+	out <- [[[Build[Statement()]]Expression <<[expression]]Assignments <<[assignments]]Blocks <<[()]
 }
 
 Add Block@Statement[statement,block:out]
@@ -64,6 +78,14 @@
 	out <- [statement]Blocks <<[ [[statement]Blocks >>]Append[block] ]
 }
 
+String@Statement[statement:out]
+{
+	out <- [[["Statement\n\tExpression:\t"
+		]Append[ [[String[[statement]Expression >>]]Split["\n"]]Join["\n\t"] ]
+		]Append[ ["\n\tAssignments:\t"]Append[[[statement]Assignments >>]Join[", "]] ]
+		]Append[ ["\n\tBlocks:\t"]Append[ [[String[[statement]Blocks >>]]Split["\n"]]Join["\n\t"] ] ]
+}
+
 Blueprint Worker Expression
 {
 	Worker
@@ -71,6 +93,11 @@
 	Arguments
 }
 
+String@Worker Expression[exp:out]
+{
+	out <- ["Worker Expression\n\tWorker:\t"]Append[[exp]Worker >>]
+}
+
 Blueprint Global Expression
 {
 	Store
@@ -84,7 +111,12 @@
 
 Pipe Expression[name:out]
 {
-	out <- [Build["Pipe Expression"]]Name <<[name]
+	out <- [Build[Pipe Expression()]]Name <<[name]
+}
+
+String@Pipe Expression[pipe:out]
+{
+	out <- ["Pipe Expression\n\tName:\t"]Append[[pipe]Name >>]
 }
 
 Blueprint Block
@@ -94,7 +126,12 @@
 
 Block[:out]
 {
-	out <- [Build["Block"]]Tree <<[()]
+	out <- [Build[Block()]]Tree <<[()]
+}
+
+String@Block[block:out]
+{
+	out <- Fold[_String Seq[?], "Block", [block]Tree >>]
 }
 
 Blueprint Field Expression
@@ -105,12 +142,12 @@
 
 Field Expression[name,set?:out]
 {
-	out <- [[Build["Field Expression"]]Name <<[name]]Set? <<[set?]
+	out <- [[Build[Field Expression()]]Name <<[name]]Set? <<[set?]
 }
 
 Body[node,tokens,current,depth:out,out index, done]
 {
-	Print[["Body: Depth="]Append[depth]]
+	Print[["Body: Depth="]Append[String[depth]]]
 	If[[depth] > [0]]
 	{
 		token <- [tokens]Index[current]
@@ -147,7 +184,7 @@
 	}
 	Val[end stream]
 	{
-		Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+		Print[String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 	}
 }
 
@@ -166,7 +203,7 @@
 	}
 	Val[end stream]
 	{
-		Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+		Print[String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 	}
 }
 
@@ -188,14 +225,14 @@
 				{
 					out,out index, done <- Outputs[node, tokens, next]
 				}{
-					Print[To String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+					Print[String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 				}
 			}
 		}
 	}
 	Val[end stream]
 	{
-		Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+		Print[String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 	}
 }
 
@@ -223,7 +260,7 @@
 					{
 						out,out index,done <- Inputs[node, tokens, next]
 					}{
-						Print[To String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+						Print[String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 					}
 				}
 			}
@@ -231,7 +268,7 @@
 	}
 	Val[end stream]
 	{
-		Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+		Print[String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 	}
 }
 
@@ -248,11 +285,11 @@
 			{
 				out,out index,done <- Method[node, tokens, next]
 			}{
-				Print[To String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+				Print[String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 			}
 		}
 	}{
-		Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+		Print[String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 	}
 }
 
@@ -267,7 +304,7 @@
 		{
 			out,out index, done <- Inputs[node, tokens, ~]
 		}{
-			Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+			Print[String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 		}
 	}{
 		[token]Type Match["Method Separator"]
@@ -276,14 +313,14 @@
 			{
 				out,out index,done <- Method[node, tokens, ~]
 			}{
-				Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+				Print[String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 			}
 		}{
 			[token]Type Match[("Line Comment","Block Comment","Newline")]
 			{
 				continue <- Yes
 			}{
-				Print[To String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+				Print[String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 			}
 			Val[continue]
 			{
@@ -291,7 +328,7 @@
 				{
 					out,out index, done <- Before Inputs[node, tokens, ~]
 				}{
-					Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+					Print[String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 				}
 			}
 		}
@@ -300,8 +337,8 @@
 
 Worker Node[name, tokens, current:out,out index, done]
 {
-	Print[["Worker: "]Append[To String[name]]]
-	out,out index, done <- Before Inputs[[[[[Build["Worker Node"]]Name <<[name]]Inputs <<[()]]Outputs <<[()]]Tree <<[()], tokens, current]
+	Print[["Worker: "]Append[String[name]]]
+	out,out index, done <- Before Inputs[[[[[[Build[Worker Node()]]Name <<[name]]Inputs <<[()]]Outputs <<[()]]Blueprint <<[No]]Tree <<[()], tokens, current]
 }
 
 Skip Nodes[toskip, stop, tokens, current:out]
@@ -317,11 +354,11 @@
 			{
 				out <- Skip Nodes[toskip, stop, tokens, next]
 			}{
-				Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+				Print[String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 			}
 		}
 	}{
-		Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+		Print[String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 	}
 }
 
@@ -349,7 +386,7 @@
 				{
 					out,out index,done <- Fields[node, tokens, next]
 				}{
-					Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+					Print[String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 				}
 			}
 		}
@@ -359,14 +396,14 @@
 			out <- Val[node]
 			done <- Yes
 		}{
-			Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+			Print[String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 		}
 	}
 }
 
 PBlueprint Node[name, tokens, current:out,out index,done]
 {
-	node <- [[Build["PBlueprint Node"]]Name <<[name]]Fields <<[()]
+	node <- [[Build[PBlueprint Node()]]Name <<[name]]Fields <<[()]
 	next <- Skip Nodes[("Newline","Block Comment","Comment"), "Block Begin", tokens, current]
 	out,out index,done <- Fields[node, tokens, next]
 }
@@ -399,7 +436,7 @@
 						out <- Val[next nodes]
 					}
 				}{
-					Print[To String[Error[["Unexpected end of stream after symbol "]Append[[token]Text >>], [token]Raw Text >>]]]
+					Print[String[Error[["Unexpected end of stream after symbol "]Append[[token]Text >>], [token]Raw Text >>]]]
 				}
 			}{
 				[tokens]Next[current]
@@ -412,7 +449,7 @@
 						out <- Val[next nodes]
 					}
 				}{
-					Print[To String[Error[["Unexpected end of stream after symbol "]Append[[token]Text >>], [token]Raw Text >>]]]
+					Print[String[Error[["Unexpected end of stream after symbol "]Append[[token]Text >>], [token]Raw Text >>]]]
 				}
 			}
 		}
@@ -423,7 +460,7 @@
 			next nodes <- Val[nodes]
 			next index <- Val[current]
 		}{
-			Print[To String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+			Print[String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
 		}
 	}
 	[tokens]Next[next index]