changeset 132:1f238280047f

Some work on expression parsing in new parser
author Mike Pavone <pavone@retrodev.com>
date Fri, 05 Nov 2010 01:23:25 -0400
parents 0a4682be2db2
children e1911b2fd5cc
files lex.rhope parse.rhope
diffstat 2 files changed, 114 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/lex.rhope	Fri Nov 05 02:43:34 2010 +0000
+++ b/lex.rhope	Fri Nov 05 01:23:25 2010 -0400
@@ -170,7 +170,29 @@
 			{
 				next list <- Val[token list]
 			}{
-				next list <- [token list]Append[Token["Symbol", trimmed, trimmed]]
+				If[[trimmed]=["?"]]
+				{
+					token type <- "Arg Placeholder"
+				}{
+					If[[trimmed]=["~"]]
+					{
+						token type <- "Block Reference"
+					}{
+						If[[trimmed]Ends With[">>"]]
+						{
+							next list <- [token list]Append[Token["Field Get", trimmed, Trim[[trimmed]Slice[ [[trimmed]Length]-[2] ], " \t\r\n"] ]]
+						}{
+							If[[trimmed]Ends With["<<"]]
+							{
+								next list <- [token list]Append[Token["Field Set", trimmed, Trim[[trimmed]Slice[ [[trimmed]Length]-[2] ], " \t\r\n"] ]]
+							}{
+								token type <- "Symbol"
+							}
+							
+						}
+					}
+				}
+				next list <- [token list]Append[Token[token type, trimmed, trimmed]]
 			}
 			out <- [token worker]Call[simple tokens, next list]
 		}
@@ -181,7 +203,7 @@
 
 Lex[text:out]
 {
-	simple tokens <- [[[[[[[[[[[Dictionary[]
+	simple tokens <- [[[[[[[[[[Dictionary[]
 		]Set["{", "Block Begin"]
 		]Set["}", "Block End"]
 		]Set["(", "List Begin"]
@@ -191,7 +213,7 @@
 		]Set[",", "List Separator"]
 		]Set[":", "Name Separator"]
 		]Set["@", "Method Separator"]
-		]Set["`", "Binary Operation"]
 		]Set["\n", "Newline"]
 	out <- _Lex[text, [text]Slice[0], simple tokens, ()]
 }
+
--- a/parse.rhope	Fri Nov 05 02:43:34 2010 +0000
+++ b/parse.rhope	Fri Nov 05 01:23:25 2010 -0400
@@ -86,37 +86,42 @@
 		]Append[ ["\n\tBlocks:\t"]Append[ [[String[[statement]Blocks >>]]Split["\n"]]Join["\n\t"] ] ]
 }
 
-Blueprint Worker Expression
+Blueprint Worker Call
 {
 	Worker
 	Blueprint
 	Arguments
 }
 
-String@Worker Expression[exp:out]
+Worker Call[worker,blueprint:out]
 {
-	out <- ["Worker Expression\n\tWorker:\t"]Append[[exp]Worker >>]
+	out <- [[[Build[Worker Call()]]Worker <<[worker]]Blueprint <<[blueprint]]Arguments <<[()]
 }
 
-Blueprint Global Expression
+String@Worker Call[exp:out]
+{
+	out <- ["Worker Call\n\tWorker:\t"]Append[[exp]Worker >>]
+}
+
+Blueprint Global Reference
 {
 	Store
 	Variable
 }
 
-Blueprint Pipe Expression
+Blueprint Pipe Value
 {
 	Name
 }
 
-Pipe Expression[name:out]
+Pipe Value[name:out]
 {
-	out <- [Build[Pipe Expression()]]Name <<[name]
+	out <- [Build[Pipe Value()]]Name <<[name]
 }
 
-String@Pipe Expression[pipe:out]
+String@Pipe Value[pipe:out]
 {
-	out <- ["Pipe Expression\n\tName:\t"]Append[[pipe]Name >>]
+	out <- ["Pipe Value\n\tName:\t"]Append[[pipe]Name >>]
 }
 
 Blueprint Block
@@ -134,22 +139,81 @@
 	out <- Fold[_String Seq[?], "Block", [block]Tree >>]
 }
 
-Blueprint Field Expression
+Blueprint Field Call
 {
 	Name
 	Set?
+	Arguments
+}
+
+Field Call[name,set?:out]
+{
+	out <- [[[Build[Field Call()]]Name <<[name]]Set? <<[set?]]Arguments <<[()]
 }
 
-Field Expression[name,set?:out]
+Expression[tokens,current:out,out index,none]
 {
-	out <- [[Build[Field Expression()]]Name <<[name]]Set? <<[set?]
+	token <- [tokens]Index[current]
+	[token]Type Match["Symbol"]
+	{
+		,end stream <- [tokens]Next[current]
+		{
+			after <- [tokens]Index[~]
+			[after]Type Match["Args Begin"]
+			{
+				
+			}{
+				
+			}
+		}
+	}{
+		[token]Type Match[("Field Get","Field Set")]
+		{
+			[token]Type Match["Field Set"]
+			{ set? <- Yes }
+			{ set? <- No }
+			Field Call[[token]Text >>, set?]
+		}{
+			[token]Type Match["Args Begin"]
+			{
+			
+			}{
+				[token]Type Match["List Begin"]
+				{
+				
+				}{
+					[token]Type Match[("String Literal","Numeric Literal")]
+					{
+					
+					}{
+						[token]Type Match["Newline"]
+						{
+							,none <- [tokens]Next[current]
+							{ out, out index <- Expression[tokens, ~] }
+						}{
+							none, unexpected token <- [token]Type Match["Block End"]
+						}
+					}
+				}
+			}
+		}
+	}
 }
+	
 
 Body[node,tokens,current,depth:out,out index, done]
 {
 	Print[["Body: Depth="]Append[String[depth]]]
 	If[[depth] > [0]]
 	{
+		//symbol list = Symbol [List Separator symbol list]
+		//value = String Literal | Number Literal | List Literal | Symbol | Block Reference | expression
+		//call = [Args Begin arg list Args End]Symbol[Args Begin arg list Args End]
+		//arg list = value | Arg Placeholder [List Separator arg list]
+		//block = Block Begin [expressions] Block End
+		//blocks = block [blocks]
+		//expressions = expression [expressions]
+		//expression = [symbol list Assignment] call | value blocks | Newline
 		token <- [tokens]Index[current]
 		[token]Type Match["Block Begin"]
 		{
@@ -455,7 +519,7 @@
 		}
 		
 	}{
-		[token]Type Match[("Newline","Block Comment","Line Comment")]
+		[token]Type Match["Newline"]
 		{
 			next nodes <- Val[nodes]
 			next index <- Val[current]
@@ -471,12 +535,23 @@
 	}
 }
 
+NotComment[token:out]
+{
+	[token]Type Match[("Block Comment","Line Comment")]
+	{
+		out <- No
+	}{
+		out <- Yes
+	}
+}
+
 Parse[tokens:out]
 {
 	[tokens]First
 	{
-		out <- Top Level[tokens, ~, ()]
+		out <- Top Level[Filter[tokens, NotComment[?]], ~, ()]
 	}{
 		out <- ()
 	}
 }
+