From 499fc08d0d0dcbc715ddccef1a56f73ca3afe9cb Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Mon, 6 Oct 2008 17:24:16 +0000 Subject: [PATCH] set props and a little better code for syntax in scribble file svn: r11952 --- collects/games/scribblings/chat-noir.scrbl | 67 +++++++++++----------- 1 file changed, 32 insertions(+), 35 deletions(-) diff --git a/collects/games/scribblings/chat-noir.scrbl b/collects/games/scribblings/chat-noir.scrbl index 15c4ce7e44..94f46d8a45 100644 --- a/collects/games/scribblings/chat-noir.scrbl +++ b/collects/games/scribblings/chat-noir.scrbl @@ -1,6 +1,6 @@ #lang scribble/doc @(require "common.ss") -@(require scheme/runtime-path (for-syntax scheme/port scheme/base)) +@(require scheme/runtime-path (for-syntax scheme/port scheme/base scheme/path)) @(define-runtime-path cn "../chat-noir/chat-noir.ss") @gametitle["Chat Noir" "chat-noir" "Puzzle Game"] @@ -15,45 +15,42 @@ The game was inspired by this one the one at @link["http://www.gamedesign.jp/flash/chatnoir/chatnoir.html"]{Game Design} and has essentailly the same rules. -This game is written in the +This game is written in the @link["http://www.htdp.org/"]{How to Design Programs} Intermediate language. It is a model solution to the final project for the introductory programming course at the University of Chicago in the fall of 2008, as below. @(define-syntax (m stx) - (syntax-case stx () - [(_) - (call-with-input-file (build-path (current-load-relative-directory) - 'up - "chat-noir" - "chat-noir.ss") - (lambda (port) - (port-count-lines! port) - #`(schemeblock - #,@ - (let loop () - (let* ([p (peeking-input-port port)] - [l (read-line p)]) - (cond - [(eof-object? l) '()] - [(regexp-match #rx"^[ \t]*$" l) - (read-line port) - (loop)] - [(regexp-match #rx"^ *;+" l) - => - (lambda (m) - (let-values ([(line col pos) (port-next-location port)]) - (read-line port) - (let-values ([(line2 col2 pos2) (port-next-location port)]) - (cons (datum->syntax - #f - `(code:comment ,(regexp-replace* #rx" " l "\u00a0")) - (list "chat-noir.ss" line col pos (- pos2 pos))) - (loop)))))] - [else - (cons (read-syntax "chat-noir.ss" port) - (loop))]))))) - #:mode 'text)])) + (call-with-input-file + (build-path (path-only (syntax-source stx)) + 'up "chat-noir" "chat-noir.ss") + (lambda (port) + (port-count-lines! port) + #`(schemeblock + #,@ + (let loop () + (let* ([p (peeking-input-port port)] + [l (read-line p)]) + (cond + [(eof-object? l) '()] + [(regexp-match #rx"^[ \t]*$" l) + (read-line port) + (loop)] + [(regexp-match #rx"^ *;+" l) + => + (lambda (m) + (let-values ([(line col pos) (port-next-location port)]) + (read-line port) + (let-values ([(line2 col2 pos2) (port-next-location port)]) + (cons (datum->syntax + #f + `(code:comment ,(regexp-replace* #rx" " l "\u00a0")) + (list "chat-noir.ss" line col pos (- pos2 pos))) + (loop)))))] + [else + (cons (read-syntax "chat-noir.ss" port) + (loop))]))))) + #:mode 'text)) @m[]