add parsing for things

dev-elider-3
Matthew Butterick 9 years ago
parent 07871e5526
commit 8be93208a2

@ -30,8 +30,8 @@
#''(define-verbs all-verbs #''(define-verbs all-verbs
_verb-entry ...)) _verb-entry ...))
(provide verb-entry) (provide verb-item)
(define-inverting #'(verb-entry (_name0 _transitive0?) (_name _transitive?) ... _desc) (define-inverting #'(verb-item (_name0 _transitive0?) (_name _transitive?) ... _desc)
#`[_name0 #,@(if (syntax->datum #'_transitive0?) #'(_) #'()) (= _name ...) _desc]) #`[_name0 #,@(if (syntax->datum #'_transitive0?) #'(_) #'()) (= _name ...) _desc])
(provide verb-name) (provide verb-name)
@ -47,18 +47,21 @@
#''(define-everywhere everywhere-actions #''(define-everywhere everywhere-actions
([_name _desc] ...))) ([_name _desc] ...)))
(provide everywhere-action) (provide everywhere-item)
(define-inverting #'(everywhere-action _name _desc) (define-inverting #'(everywhere-item _name _desc)
#'(_name _desc)) #'(_name _desc))
(provide things-section) (provide things-section)
(define-inverting #'(things-section _heading _thing ...) (define-inverting #'(things-section _heading _thing ...)
#'(begin _thing ...)) #'(begin _thing ...))
(provide thing-entry) (provide thing-item)
(define #'(thing-entry (thing-id _thingname) (thing-action _actionname _actiondesc) ...) (define-inverting #'(thing-item (thing-id _thingname) (_actionname _actiondesc) ...)
#''(define-thing _thingname [_actionname _actiondesc] ...)) #''(define-thing _thingname [_actionname _actiondesc] ...))
(provide thing-action)
(define-inverting #'(thing-action _actionname _actiondesc)
#'(_actionname _actiondesc))
(provide desc) (provide desc)
(define #'(desc _d) #'_d) (define #'(desc _d) #'_d)

@ -2,19 +2,19 @@
txtadv-program : [verb-section] [everywhere-section] [things-section] txtadv-program : [verb-section] [everywhere-section] [things-section]
verb-section : "===VERBS===" verb-entry+ verb-section : "===VERBS===" verb-item+
verb-entry : verb-name+ desc verb-item : verb-name+ desc
verb-name : [","] ID ["_"] verb-name : [","] ID ["_"]
everywhere-section : "===EVERYWHERE===" everywhere-action+ everywhere-section : "===EVERYWHERE===" everywhere-item+
everywhere-action : ID desc everywhere-item : ID desc
things-section : "===THINGS===" thing-entry+ things-section : "===THINGS===" thing-item+
thing-entry : thing-id thing-action+ thing-item : thing-id thing-action+
thing-id : THING-NAME thing-id : THING-NAME
@ -22,4 +22,4 @@ thing-action : ID desc
desc : s-exp desc : s-exp
s-exp : ID | STRING | ("(" "[" "{") s-exp* (")" "]" "}") s-exp : ID | STRING | ("(" | "[" | "{") s-exp* (")" | "]" | "}")

@ -18,9 +18,9 @@
[(seq "\"" (complement (seq any-string "\"" any-string)) "\"") (token 'STRING lexeme)] [(seq "\"" (complement (seq any-string "\"" any-string)) "\"") (token 'STRING lexeme)]
[(seq "---" [(seq "---"
(repetition 1 +inf.0 (union alphabetic numeric punctuation)) (repetition 1 +inf.0 (union alphabetic numeric punctuation))
"---") (token 'THING-NAME (string-trim lexeme "-" #:repeat? #t))] "---") (token 'THING-NAME (string->symbol (string-trim lexeme "-" #:repeat? #t)))]
[(repetition 1 +inf.0 (union alphabetic numeric punctuation)) [(repetition 1 +inf.0 (union alphabetic numeric (char-set "-!?.#")))
(token 'ID (string->symbol lexeme))] (token 'ID (read (open-input-string lexeme)))]
[any-char lexeme])) [any-char lexeme]))
(get-token input-port)) (get-token input-port))
next-token) next-token)

@ -66,7 +66,6 @@ look
inventory inventory
(show-inventory) (show-inventory)
*/
===THINGS=== ===THINGS===
@ -76,22 +75,16 @@ get
"Ouch!" "Ouch!"
---door---
open
(if
this
that)
/*
---door--- ---door---
open open
(if (if
(begin (begin
(set-thing-state door open) (set-thing-state! door open)
"The door is now unlocked and open.") "The door is now unlocked and open.")
"The door is locked.") "The door is locked.")
close close
(begin (begin
(set-thing-state! door #f) (set-thing-state! door #f)
@ -123,10 +116,11 @@ get
(take-thing! trophy) (take-thing! trophy)
"You win!") "You win!")
*/ */
/*
===PLACES=== ===PLACES===
---meadow--- ---meadow---
@ -176,5 +170,3 @@ west
out out
house-front house-front
*/
Loading…
Cancel
Save