Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Pfeiffer committed Nov 20, 2018
1 parent 8ec3e62 commit fd012eb
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions lib/syntaxtree.gi
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,30 @@ function()
# More generically (and prettier) maybe
# using method selection and overloading + (or *), 'or'?
DOC := rec( NIL := rec( type := "NIL" )
, CONCAT := function(d1, d2) return rec( type := ":<>", d1 := d1, d2 := d2 ); end
, NEST := function(i,x) return rec(type := "NEST", indent := i, doc := x ); end
, TEXT := function(s) return rec(type := "TEXT", text := s); end
, CONCAT := {d1,d2} -> rec( type := ":<>"
, d1 := d1
, d2 := d2 )
, NEST := {i,x} -> rec( type := "NEST"
, indent := i
, doc := x )
, TEXT := s -> rec( type := "TEXT"
, text := s )
, LINE := rec( type := "LINE" )
, ALT := function(d1, d2) return rec( type := ":<|>", d1 := d1, d2 := d2 ); end );
, ALT := {d1,d2} -> rec( type := ":<|>"
, d1 := d1
, d2 := d2 ) );

Doc := rec( Nil := rec( type := "Nil" )
, Text := function(s, d) return rec( type := "Text", text := s, doc := d ); end
, Line := function(i, d) return rec( type := "Line", indent := i, doc := d ); end );
, Text := {s,d} -> rec( type := "Text"
, text := s
, doc := d )
, Line := {i,d} -> rec( type := "Line"
, indent := i
, doc := d ) );


group := function(doc)
return rec( type := ":<|>"
, d1 := flatten(doc)
, d2 := doc );
end;
group := doc -> rec( type := ":<|>"
, d1 := flatten(doc)
, d2 := doc );

flatten := function(doc)
if doc.type = "NIL" then
Expand Down Expand Up @@ -333,7 +341,8 @@ function()
,")")
, DOC.TEXT("local")
, folddoc(DOC.CONCAT, List(expr.locnams, DOC.TEXT))
, folddoc(DOC.CONCAT, List(expr.stats, compiler.compile)) ];
, folddoc(DOC.CONCAT, compiler.compile(expr.stats))
];
end;

compiler.T_OR := compile_record;
Expand Down

0 comments on commit fd012eb

Please sign in to comment.