Using current-read-interaction and renabling adapted tutorial

This commit is contained in:
Jay McCarthy 2010-06-25 22:36:03 -06:00
parent 0bda9efa96
commit 8afc06c096
7 changed files with 36 additions and 14 deletions

View File

@ -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)

View File

@ -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))

View File

@ -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"))
(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))

View File

@ -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)]

View File

@ -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]

View File

@ -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].

View File

@ -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.