<> <> <> <> <<-- This program forms a stream oriented interface to a subset of the Parquet operations.>> <<-- It can generate rectangular arrays.>> <<>> <> < >> <> < >> <> [module, prevTile] _ Parquet.NewModule[technology]; prevRow _ prevTile; <<-- main body of module generator>> DO [token, ] _ IO.GetTokenRope[stream, BreakProc !IO.EndOfStream => {endOfFile _ TRUE; CONTINUE} ]; IF endOfFile THEN BEGIN <<-- pass result back to Parquet >> TerminalIO.WriteRope["Quilt done.\n"]; RETURN[module]; END; SELECT TRUE FROM (Rope.Equal[token, "$NEWROW", FALSE]) => newRow _ TRUE; (Rope.Fetch[token, 0] = '#) => BEGIN newOrient: Parquet.Orientation _ Parquet.IdentityOrient; FOR i: INT IN [1..Rope.Length[token]) DO badMessage: BOOL _ FALSE; SELECT Rope.Fetch[token, i] FROM <<-- remember that Parquet's rotations are counter-clockwise>> '= => newOrient _ Parquet.ComposeOrient[newOrient, orient]; '1 => newOrient _ Parquet.ComposeOrient[newOrient, Parquet.Rotate180]; '2 => newOrient _ Parquet.ComposeOrient[newOrient, Parquet.Rotate90]; '9 => newOrient _ Parquet.ComposeOrient[newOrient, Parquet.Rotate270]; 'x, 'X => newOrient _ Parquet.ComposeOrient[newOrient, Parquet.MirrorX]; 'y, 'Y => newOrient _ Parquet.ComposeOrient[newOrient, Parquet.MirrorY]; ENDCASE => BEGIN IF ~badMessage THEN BEGIN TerminalIO.WriteRope["Bad rotation specification: '"]; TerminalIO.WriteRope[token]; TerminalIO.WriteRope["' -- illegal characters ignored.\n"]; badMessage _ TRUE; END; END; ENDLOOP; orient _ newOrient; END; (TRUE) => BEGIN <<-- This is slow, we should really cache tiles rather than instantiating them again, especially since we don't pass any parameters down.>> tile _ Parquet.InstantiateTile[tiles, token, NIL]; IF tile = NIL THEN BEGIN TerminalIO.WriteRope["Could not find tile '"]; TerminalIO.WriteRope[token]; TerminalIO.WriteRope["'.\n"]; GOTO Punt; END; IF newRow THEN BEGIN prevRow _ prevTile _ Parquet.AdjacentTile[prevRow, tile, below, orient]; newRow _ FALSE; END ELSE prevTile _ Parquet.AdjacentTile[prevTile, tile, rightOf, orient]; END; ENDCASE; ENDLOOP; EXITS Punt => RETURN[NIL]; END; NoOp: Commander.CommandProc = BEGIN END; <<-- register this generator with Parquet>> [] _ Parquet.RegisterGenerator["Quilt", QuiltProc]; <<-- register a command so that we won't get ".load file failed to register command">> Commander.Register[key: "Quilt", proc: NoOp, doc: "Does nothing"]; END.