changeset 4:0c5f24b4f69d

Handle blueprints in new parser
author Mike Pavone <pavone@retrodev.com>
date Wed, 29 Apr 2009 23:59:13 -0400
parents 73e978d590c7
children a4d2d633a356
files parse.rhope
diffstat 1 files changed, 61 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/parse.rhope	Wed Apr 29 02:58:03 2009 -0400
+++ b/parse.rhope	Wed Apr 29 23:59:13 2009 -0400
@@ -243,19 +243,77 @@
 	out,out index, done <- Before Inputs[[[[[Build["Worker Node"]]Name <<[name]]Inputs <<[()]]Outputs <<[()]]Tree <<[()], tokens, current]
 }
 
+Skip Nodes[toskip, stop, tokens, current:out]
+{
+	token <- [tokens]Index[current]
+	next <- [tokens]Next[current]
+	{
+		[token]Type Match[stop]
+		{
+			out <- Val[next]
+		}{
+			[token]Type Match[toskip]
+			{
+				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[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]]
+	}
+}
+
 Blueprint PBlueprint Node
 {
 	Name
 	Fields
 }
 
+Fields[node,tokens,current:out,out index,done]
+{
+	token <- [tokens]Index[current]
+	next <- [tokens]Next[current]
+	{
+		[token]Type Match["Symbol"]
+		{
+			out,out index,done <- Fields[[node]Add BField[[token]Text >>], tokens, next]
+		}{
+			[token]Type Match["Block End"]
+			{
+				out <- Val[node]
+				out index <- Val[next]
+			}{
+				[token]Type Match[("Newline","Line Comment","Block Comment")]
+				{
+					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 >>]]]
+				}
+			}
+		}
+	}{
+		[token]Type Match["Block End"]
+		{
+			out <- Val[node]
+			done <- Yes
+		}{
+			Print[To 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]
 {
-	out <- [[Build["PBlueprint Node"]]Name <<[name]]Fields <<[()]
-	out index <- current
-	//TODO: Parse rest of blueprint definition
+	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]
 }
 
+Add BField@PBlueprint Node[node,field:out]
+{
+	out <- [node]Fields <<[[[node]Fields >>]Append[field]]
+}
 
 Top Level[tokens, current, nodes:out]
 {