<> <> <> <> <<-- 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["PQuilt 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 _ CDOrient.ComposeOrient[newOrient, orient]; '1 => newOrient _ CDOrient.ComposeOrient[newOrient, CDOrient.rotate180]; '2 => newOrient _ CDOrient.ComposeOrient[newOrient, CDOrient.rotate90]; '9 => newOrient _ CDOrient.ComposeOrient[newOrient, CDOrient.rotate270]; 'x, 'X => newOrient _ CDOrient.ComposeOrient[newOrient, CDOrient.mirrorX]; 'y, 'Y => newOrient _ CDOrient.ComposeOrient[newOrient, 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 tile _ Parquet.GetTile[tiles, token]; 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; <<-- register this generator with Parquet>> [] _ Parquet.RegisterCommand["PQuilt", PQuiltProc]; END.