@ -4,6 +4,7 @@
;; create and use the buffer that the lexer reads from. See docs.
;; create and use the buffer that the lexer reads from. See docs.
( require ( for-syntax racket/list
( require ( for-syntax racket/list
racket/syntax
syntax/stx
syntax/stx
syntax/define
syntax/define
syntax/boundmap
syntax/boundmap
@ -70,11 +71,19 @@
[ lexeme-srcloc ( make-rename-transformer #' lexeme-srcloc-p ) ] )
[ lexeme-srcloc ( make-rename-transformer #' lexeme-srcloc-p ) ] )
action-stx ) ) ) ) )
action-stx ) ) ) ) )
( begin-for-syntax
; This macro only exists to keep the indentation below the same,
; in order to make the diff easier to read. So it probably makes
; sense to inline it after reading.
( define-syntax-rule ( begin-with-disappeared-uses body0 body ... )
( with-disappeared-uses
( let ( ) body0 body ... ) ) ) )
( define-for-syntax ( make-lexer-macro caller src-loc-style )
( define-for-syntax ( make-lexer-macro caller src-loc-style )
( λ ( stx )
( λ ( stx )
( syntax-case stx ( )
( syntax-case stx ( )
[ ( _ . RE+ACTS )
[ ( _ . RE+ACTS )
( let ( )
( begin-with-disappeared-uses
( define spec/re-acts ( syntax->list #' RE+ACTS ) )
( define spec/re-acts ( syntax->list #' RE+ACTS ) )
( for/and ( [ x ( in-list spec/re-acts ) ] )
( for/and ( [ x ( in-list spec/re-acts ) ] )
( syntax-case x ( )
( syntax-case x ( )
@ -101,7 +110,7 @@
( define re-actnames ( map ( λ ( re-act name ) ( list ( stx-car re-act ) name ) ) re-acts names ) )
( define re-actnames ( map ( λ ( re-act name ) ( list ( stx-car re-act ) name ) ) re-acts names ) )
( when ( null? spec/re-acts )
( when ( null? spec/re-acts )
( raise-syntax-error caller " expected at least one action " stx ) )
( raise-syntax-error caller " expected at least one action " stx ) )
( define-values ( trans start action-names no-look disappeared-uses ) ( build-lexer re-actnames ) )
( define-values ( trans start action-names no-look ) ( build-lexer re-actnames ) )
( when ( vector-ref action-names start ) ;; Start state is final
( when ( vector-ref action-names start ) ;; Start state is final
( unless ( and
( unless ( and
;; All the successor states are final
;; All the successor states are final
@ -130,19 +139,17 @@
[ HAS-COMMENT-ACT?-STX ( if ( syntax-e spec-comment-act ) #t #f ) ]
[ HAS-COMMENT-ACT?-STX ( if ( syntax-e spec-comment-act ) #t #f ) ]
[ SPEC-COMMENT-ACT-STX ( wrap-action spec-comment-act src-loc-style ) ]
[ SPEC-COMMENT-ACT-STX ( wrap-action spec-comment-act src-loc-style ) ]
[ EOF-ACT-STX ( wrap-action eof-act src-loc-style ) ] )
[ EOF-ACT-STX ( wrap-action eof-act src-loc-style ) ] )
( syntax-property
( syntax/loc stx ( let ( [ NAME ACT ] ... )
( syntax/loc stx ( let ( [ NAME ACT ] ... )
( let ( [ proc ( lexer-body START-STATE-STX
( let ( [ proc ( lexer-body START-STATE-STX
TRANS-TABLE-STX
TRANS-TABLE-STX
( vector ACT-NAME ... )
( vector ACT-NAME ... )
NO-LOOKAHEAD-STX
NO-LOOKAHEAD-STX
SPEC-ACT-STX
SPEC-ACT-STX
HAS-COMMENT-ACT?-STX
HAS-COMMENT-ACT?-STX
SPEC-COMMENT-ACT-STX
SPEC-COMMENT-ACT-STX
EOF-ACT-STX ) ] )
EOF-ACT-STX ) ] )
;; reverse eta to get named procedures:
;; reverse eta to get named procedures:
( λ ( port ) ( proc port ) ) ) ) ) ) ) ] ) ) )
( λ ( port ) ( proc port ) ) ) ) )
' disappeared-use disappeared-uses ) ) ) ] ) ) )
( define-syntax lexer ( make-lexer-macro ' lexer #f ) )
( define-syntax lexer ( make-lexer-macro ' lexer #f ) )
( define-syntax lexer-src-pos ( make-lexer-macro ' lexer-src-pos ' lexer-src-pos ) )
( define-syntax lexer-src-pos ( make-lexer-macro ' lexer-src-pos ' lexer-src-pos ) )