Using current-read-interaction and renabling adapted tutorial

original commit: 8afc06c09679827189aa8f5918cb914f6a02d731
This commit is contained in:
Jay McCarthy 2010-06-25 22:36:03 -06:00
parent 5287b0c6cf
commit 1e0f7514bc
5 changed files with 30 additions and 7 deletions

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.