From 8afc06c09679827189aa8f5918cb914f6a02d731 Mon Sep 17 00:00:00 2001 From: Jay McCarthy Date: Fri, 25 Jun 2010 22:36:03 -0600 Subject: [PATCH] Using current-read-interaction and renabling adapted tutorial --- collects/datalog/lang/lang.rkt | 10 +++++----- collects/datalog/lang/module.rkt | 3 +-- collects/datalog/lang/reader.rkt | 18 ++++++++++++++++-- collects/datalog/parse.rkt | 1 + collects/datalog/scribblings/datalog.scrbl | 6 +++++- collects/datalog/scribblings/racket.scrbl | 2 ++ collects/datalog/scribblings/tutorial.scrbl | 10 ++++++---- 7 files changed, 36 insertions(+), 14 deletions(-) diff --git a/collects/datalog/lang/lang.rkt b/collects/datalog/lang/lang.rkt index 3ef85a3175..03acffa5da 100644 --- a/collects/datalog/lang/lang.rkt +++ b/collects/datalog/lang/lang.rkt @@ -17,12 +17,12 @@ #'(#%module-begin (begin (print-result rs) ...)))])) -#;(compile-module (syntax->datum #'(ast ...))) -#;(compile-stmt (syntax->datum #'ast)) - (define-syntax (top-interaction stx) - (printf "~S\n" stx) - #'(void)) + (syntax-case stx () + [(_ . stmt) + (quasisyntax/loc stx + (print-result + #,(compile-stmt (syntax->datum #'stmt))))])) (provide module-begin top-interaction) \ No newline at end of file diff --git a/collects/datalog/lang/module.rkt b/collects/datalog/lang/module.rkt index c0e49abc65..ddc3f2c7f4 100644 --- a/collects/datalog/lang/module.rkt +++ b/collects/datalog/lang/module.rkt @@ -2,8 +2,7 @@ (require "lang.rkt") (provide (rename-out [module-begin #%module-begin] - ; XXX Because the REPL doesn't use the correct reader, I can't really test this - #;[top-interaction #%top-interaction]) + [top-interaction #%top-interaction]) (except-out (all-from-out racket/base) #%top-interaction #%module-begin)) \ No newline at end of file diff --git a/collects/datalog/lang/reader.rkt b/collects/datalog/lang/reader.rkt index 701c0c8772..7394896695 100644 --- a/collects/datalog/lang/reader.rkt +++ b/collects/datalog/lang/reader.rkt @@ -11,8 +11,22 @@ ; XXX Should have different comment character key (case key [(drracket:submit-predicate) - (dynamic-require `datalog/tool/submit 'repl-submit?)] + repl-submit?] [(color-lexer) (dynamic-require `datalog/tool/syntax-color 'get-syntax-token)] [else (default key defval)])) - (require "../parse.rkt")) \ No newline at end of file + (require datalog/parse + datalog/tool/submit) + + ; XXX This is almost certainly wrong. + (define (even-read src ip) + (begin0 + (parameterize ([current-source-name src]) + (datum->syntax #f (parse-statement ip))) + (current-read-interaction odd-read))) + (define (odd-read src ip) + (current-read-interaction even-read) + eof) + + (current-read-interaction + even-read)) \ No newline at end of file diff --git a/collects/datalog/parse.rkt b/collects/datalog/parse.rkt index 5c3f116c21..f846055db0 100644 --- a/collects/datalog/parse.rkt +++ b/collects/datalog/parse.rkt @@ -104,6 +104,7 @@ A Datalog reader consumes a Datalog program. A program is a sequence of zero or (define parse-program (mk-parser program-parser)) (provide/contract + [current-source-name (parameter/c any/c)] [parse-literal (input-port? . -> . literal?)] [parse-clause (input-port? . -> . clause?)] [parse-statement (input-port? . -> . statement/c)] diff --git a/collects/datalog/scribblings/datalog.scrbl b/collects/datalog/scribblings/datalog.scrbl index 415929e83b..6aebe6f6b7 100644 --- a/collects/datalog/scribblings/datalog.scrbl +++ b/collects/datalog/scribblings/datalog.scrbl @@ -125,7 +125,9 @@ The following is a program: END ] -Currently, REPL interaction is not supported. +The Datalog REPL accepts new statements that are executed as if they were in the original program text. + +@include-section["tutorial.scrbl"] @section{Parenthetical Datalog Module Language} @(require (for-label datalog/sexp/lang)) @@ -152,6 +154,8 @@ The following is a program: (path ,Z ,Y))) (? (path ,X ,Y))] +The Parenthetical Datalog REPL accepts new statements that are executed as if they were in the original program text. + @subsection[#:tag "parenstx"]{Parenthetical Syntax} @defmodule[datalog/sexp/lang] diff --git a/collects/datalog/scribblings/racket.scrbl b/collects/datalog/scribblings/racket.scrbl index 484bdd694a..1c84a5c5e3 100644 --- a/collects/datalog/scribblings/racket.scrbl +++ b/collects/datalog/scribblings/racket.scrbl @@ -197,6 +197,8 @@ This library provides facilities for parsing Datalog source. It can be required @defmodule[datalog/parse] +@defparam[current-source-name name any/c]{ A parameter used by the parsing functions to set the source name on the read ASTs. } + @defproc[(parse-literal [ip input-port?]) literal?]{ Parses a @racket[literal] from @racket[ip]. diff --git a/collects/datalog/scribblings/tutorial.scrbl b/collects/datalog/scribblings/tutorial.scrbl index 0bc80ebf01..e4c24bc98d 100644 --- a/collects/datalog/scribblings/tutorial.scrbl +++ b/collects/datalog/scribblings/tutorial.scrbl @@ -10,9 +10,11 @@ @title{Tutorial} -Start DrScheme and choose the @tt{Datalog} language from DrScheme's -@tt{Language} menu under @tt{Experimental Languages}. Click @onscreen{Run}, then -click in the REPL. +Start DrRacket and type + +@racketmod[datalog] + +in the Definitions window. Click @onscreen{Run}, then click in the REPL. @racketinput[] @@ -72,7 +74,7 @@ C is an ancestor of B, then A is an ancestor of B. #,(tt " parent(A, C),") #,(tt " ancestor(C, B).")] -In the interpreter, DrScheme knows that the clause is not complete, so by pressing Return, it doesn't interpret the line. +In the interpreter, DrRacket knows that the clause is not complete, so by pressing Return, it doesn't interpret the line. Rules are used to answer queries just as is done for facts.