Mercurial > repos > rhope
view parse.rhope @ 75:0083b2f7b3c7
Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 06 Jul 2010 07:52:59 -0400 |
parents | a4d2d633a356 |
children | 0a4682be2db2 |
line wrap: on
line source
Blueprint Error { Message Line Column } Error[msg,text:out] { out <- [[[Build["Error"]]Message <<[msg]]Line << [ [[text]Line >>]+[1] ]]Column << [ [[text]Column >>]+[1] ] } To String@Error[error:out] { out <- [[[[[error]Message >>]Append[" on line "]]Append[[error]Line >>]]Append[" at column "]]Append[[error]Column >>] } Blueprint PImport Node { File } PImport Node[file:out] { out <- [Build["PImport Node"]]File <<[file] } Blueprint Worker Node { Name Blueprint Inputs Outputs Tree } Add Node Input@Worker Node[node,input:out] { Print["Add Node Input"] Print[["Input: "]Append[To String[input]]] out <- [node]Inputs <<[[[node]Inputs >>]Append[input]] } Add Node Output@Worker Node[node,output:out] { out <- [node]Outputs <<[[[node]Outputs >>]Append[output]] } Blueprint Statement { Expression Assignments Blocks } Statement[expression,assignments:out] { out <- [[[Build["Statement"]]Expression <<[expression]]Assignments <<[assignments]]Blocks <<[()] } Add Block@Statement[statement,block:out] { out <- [statement]Blocks <<[ [[statement]Blocks >>]Append[block] ] } Blueprint Worker Expression { Worker Blueprint Arguments } Blueprint Global Expression { Store Variable } Blueprint Pipe Expression { Name } Pipe Expression[name:out] { out <- [Build["Pipe Expression"]]Name <<[name] } Blueprint Block { Tree } Block[:out] { out <- [Build["Block"]]Tree <<[()] } Blueprint Field Expression { Name Set? } Field Expression[name,set?:out] { out <- [[Build["Field Expression"]]Name <<[name]]Set? <<[set?] } Body[node,tokens,current,depth:out,out index, done] { Print[["Body: Depth="]Append[depth]] If[[depth] > [0]] { token <- [tokens]Index[current] [token]Type Match["Block Begin"] { ,end stream <- [tokens]Next[current] { out,out index, done <- Body[node,tokens,~,[depth]+[1]] } }{ [token]Type Match["Block End"] { [tokens]Next[current] { out,out index, done <- Body[node,tokens,~,[depth]-[1]] }{ ,end stream <- If[[depth] = [1]] { Print["done"] out <- Val[node] done <- Yes } } }{ ,end stream <- [tokens]Next[current] { out,out index, done <- Body[node,tokens,~,depth] } } } }{ out <- node out index <- current } Val[end stream] { Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] } } Before Body[node,tokens,current:out,out index, done] { Print["Before body"] token <- [tokens]Index[current] next,end stream <- [tokens]Next[current] { [token]Type Match["Block Begin"] { out,out index, done <- Body[node,tokens,next,1] }{ out,out index, done <- Before Body[node,tokens,next] } } Val[end stream] { Print[To String[Error[["Unexpected end of stream after token of type "]Append[[token]Type >>], [token]Raw Text >>]]] } } Outputs[node,tokens,current:out,out index, done] { Print["outputs"] token <- [tokens]Index[current] next,end stream <- [tokens]Next[current] { [token]Type Match["Symbol"] { out,out index, done <- Outputs[[node]Add Node Output[[token]Text >>], tokens, next] }{ [token]Type Match["Args End"] { out,out index, done <- Before Body[node, tokens, next] }{ [token]Type Match[("List Separator","Block Comment","Line Comment","Newline")] { out,out index, done <- Outputs[node, tokens, next] }{ Print[To 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 >>]]] } } Inputs[node,tokens,current:out,out index, done] { Print["Inputs"] token <- [tokens]Index[current] next,end stream <- [tokens]Next[current] { [token]Type Match["Symbol"] { out,out index, done <- Inputs[[node]Add Node Input[[token]Text >>], tokens, next] }{ [token]Type Match["Name Separator"] { Print["in out sep"] out,out index, done <- Outputs[node, tokens, next] }{ [token]Type Match["Args End"] { out,out index, done <- Before Body[node, tokens, next] }{ [token]Type Match[("List Separator","Block Comment","Line Comment","Newline")] { out,out index,done <- Inputs[node, tokens, next] }{ Print[To 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 >>]]] } } Method[node,tokens,current:out,out index,done] { token <- [tokens]Index[current] next <- [tokens]Next[current] { [token]Type Match["Symbol"] { out,out index,done <- Before Inputs[[node]Blueprint <<[[token]Text >>], tokens, next] }{ [token]Type Match[("List Separator","Block Comment","Line Comment","Newline")] { out,out index,done <- Method[node, tokens, next] }{ Print[To 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 >>]]] } } //TODO: support method declarations Before Inputs[node, tokens, current:out, out index, done] { Print["Before Inputs"] token <- [tokens]Index[current] [token]Type Match["Args Begin"] { [tokens]Next[current] { 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 >>]]] } }{ [token]Type Match["Method Separator"] { [tokens]Next[current] { 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 >>]]] } }{ [token]Type Match[("Line Comment","Block Comment","Newline")] { continue <- Yes }{ Print[To String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]] } Val[continue] { [tokens]Next[current] { 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 >>]]] } } } } } 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] } 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] { 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] { token <- [tokens]Index[current] Print[[token]Type >>] [token]Type Match["Symbol"] { [[token]Text >>]After["Import "] { next nodes <- [nodes]Append[PImport Node[~]] next index <- Val[current] }{ blueprint name,worker name <- [~]After["Blueprint "] { [tokens]Next[current] { , next index <- PBlueprint Node[blueprint name, tokens, ~] { next nodes <- [nodes]Append[~] } {} { Print["done!"] out <- Val[next nodes] } }{ Print[To String[Error[["Unexpected end of stream after symbol "]Append[[token]Text >>], [token]Raw Text >>]]] } }{ [tokens]Next[current] { , next index <- Worker Node[worker name, tokens, ~] { next nodes <- [nodes]Append[~] } {} { Print["done!"] out <- Val[next nodes] } }{ Print[To String[Error[["Unexpected end of stream after symbol "]Append[[token]Text >>], [token]Raw Text >>]]] } } } }{ [token]Type Match[("Newline","Block Comment","Line Comment")] { next nodes <- Val[nodes] next index <- Val[current] }{ Print[To String[Error[["Unexpected token of type "]Append[[token]Type >>], [token]Raw Text >>]]] } } [tokens]Next[next index] { out <- Top Level[tokens, ~, next nodes] }{ out <- Val[next nodes] } } Parse[tokens:out] { [tokens]First { out <- Top Level[tokens, ~, ()] }{ out <- () } }