@@ -71,7 +71,9 @@ Our initial specification with @racket[syntax-spec] supplies the grammar:
7171
7272 (nonterminal state-spec
7373 (state name:id transitions:transition-spec ... )
74- (state name:id ((~datum on-enter) body:action-spec ...+) transitions:transition-spec ... ))
74+ (state name:id
75+ ((~datum on-enter) body:action-spec ...+)
76+ transitions:transition-spec ... ))
7577
7678 (nonterminal transition-spec
7779 (on (event-name:id arg:id ... )
@@ -196,7 +198,9 @@ Now let's add binding rules for state names. We can't just use @racket[scope] an
196198 (error 'machine "compiler not yet implemented " ))
197199
198200 (nonterminal/exporting state-spec
199- (state name:state-name ((~datum on-enter) body:action-spec ...+) transition:transition-spec ... )
201+ (state name:state-name
202+ ((~datum on-enter) body:action-spec ...+)
203+ transition:transition-spec ... )
200204 #:binding (export name)
201205
202206 (state name:state-name transition:transition-spec ... )
@@ -252,7 +256,9 @@ An action expression can only @racket[displayln] the value of a variable. What i
252256 ...
253257
254258 (nonterminal/exporting state-spec
255- (state name:state-name ((~datum on-enter) body:racket-body ...+) transition:transition-spec ... )
259+ (state name:state-name
260+ ((~datum on-enter) body:racket-body ...+)
261+ transition:transition-spec ... )
256262 #:binding [(export name) (scope (import body) ... )]
257263
258264 (state name:state-name transition:transition-spec ... )
@@ -362,11 +368,12 @@ We'll create a class for the state machine, which acts as a context class, and a
362368
363369The @racket[machine%] class stores the current state instance and delegates to it. Each state class has methods for each defined transition. Transition actions go in the transition's method and @racket[on-enter] actions go in the class body. When a state is entered, the @racket[machine%] class creates a fresh instance of it, which runs the class body, and sets the current state to that instance. Finally, we return an instance of the machine class.
364370
365- Now Let 's start to write the compiler:
371+ Now let 's start to write the compiler:
366372
367373@racketblock[
368374(syntax-spec
369- (binding-class event-var #:reference-compiler mutable-reference-compiler)
375+ (binding-class event-var
376+ #:reference-compiler mutable-reference-compiler)
370377 ...
371378 (host-interface/expression
372379 (machine #:initial initial-state:state-name s:state-spec ... )
@@ -379,7 +386,8 @@ Now Let's start to write the compiler:
379386 #:datum-literals (machine state on-enter)
380387 [(_ initial-state
381388 (state state-name
382- (~optional (on-enter action ... ) #:defaults ([(action 1 ) '() ]))
389+ (~optional (on-enter action ... )
390+ #:defaults ([(action 1 ) '() ]))
383391 e ... )
384392 ... )
385393 #'(let ()
@@ -495,8 +503,10 @@ In our language's compiler, we can use symbol set to raise an error when a state
495503 (define (check-for-inaccessible-states initial-state-id state-specs)
496504 (define accessible-states (get-accessible-states initial-state-id state-specs))
497505 (for/list ([state-spec state-specs]
498- #:unless (symbol-set-member? accessible-states (state-spec-name state-spec)))
499- (error 'machine "Inaccessible state: ~a " (syntax->datum (state-spec-name state-spec)))))
506+ #:unless (symbol-set-member? accessible-states
507+ (state-spec-name state-spec)))
508+ (error 'machine "Inaccessible state: ~a "
509+ (syntax->datum (state-spec-name state-spec)))))
500510
501511 (define (get-accessible-states initial-state-id state-specs)
502512 (define accessible-states (local-symbol-set))
0 commit comments