|
|
@ -1,6 +1,7 @@
|
|
|
|
#lang racket/base
|
|
|
|
#lang racket/base
|
|
|
|
(require parser-tools/lex
|
|
|
|
(require parser-tools/lex
|
|
|
|
racket/string
|
|
|
|
racket/string
|
|
|
|
|
|
|
|
racket/struct
|
|
|
|
(prefix-in : parser-tools/lex-sre)
|
|
|
|
(prefix-in : parser-tools/lex-sre)
|
|
|
|
(for-syntax racket/base))
|
|
|
|
(for-syntax racket/base))
|
|
|
|
(provide (all-from-out parser-tools/lex)
|
|
|
|
(provide (all-from-out parser-tools/lex)
|
|
|
@ -11,7 +12,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(struct token-struct (type val offset line column span skip?)
|
|
|
|
(struct token-struct (type val offset line column span skip?)
|
|
|
|
#:transparent)
|
|
|
|
#:auto-value #f
|
|
|
|
|
|
|
|
#:transparent
|
|
|
|
|
|
|
|
#:methods gen:custom-write
|
|
|
|
|
|
|
|
[(define write-proc
|
|
|
|
|
|
|
|
(make-constructor-style-printer
|
|
|
|
|
|
|
|
(lambda (obj) 'token)
|
|
|
|
|
|
|
|
(lambda (obj) (map (λ(proc) (proc obj))
|
|
|
|
|
|
|
|
(list
|
|
|
|
|
|
|
|
token-struct-type
|
|
|
|
|
|
|
|
token-struct-val
|
|
|
|
|
|
|
|
token-struct-line
|
|
|
|
|
|
|
|
token-struct-column
|
|
|
|
|
|
|
|
token-struct-offset
|
|
|
|
|
|
|
|
token-struct-span
|
|
|
|
|
|
|
|
token-struct-skip?)))))])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Token constructor.
|
|
|
|
;; Token constructor.
|
|
|
@ -64,22 +79,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
;; change names of lexer abbreviations to be consistent with Racket srcloc conventions
|
|
|
|
;; change names of lexer abbreviations to be consistent with Racket srcloc conventions
|
|
|
|
|
|
|
|
|
|
|
|
(provide start-loc)
|
|
|
|
(provide lexeme-start)
|
|
|
|
(define-syntax start-loc (make-rename-transformer #'start-pos))
|
|
|
|
(define-syntax lexeme-start (make-rename-transformer #'start-pos))
|
|
|
|
|
|
|
|
|
|
|
|
(provide end-loc)
|
|
|
|
(provide lexeme-end)
|
|
|
|
(define-syntax end-loc (make-rename-transformer #'end-pos))
|
|
|
|
(define-syntax lexeme-end (make-rename-transformer #'end-pos))
|
|
|
|
|
|
|
|
|
|
|
|
(provide loc-line)
|
|
|
|
(provide line)
|
|
|
|
(define-syntax loc-line (make-rename-transformer #'position-line))
|
|
|
|
(define-syntax line (make-rename-transformer #'position-line))
|
|
|
|
|
|
|
|
|
|
|
|
(provide loc-column)
|
|
|
|
(provide column)
|
|
|
|
(define-syntax loc-column (make-rename-transformer #'position-col))
|
|
|
|
(define-syntax column (make-rename-transformer #'position-col))
|
|
|
|
|
|
|
|
|
|
|
|
(provide loc-position)
|
|
|
|
(provide position)
|
|
|
|
(define-syntax loc-position (make-rename-transformer #'position-offset))
|
|
|
|
(define-syntax position (make-rename-transformer #'position-offset))
|
|
|
|
|
|
|
|
|
|
|
|
(provide loc-span)
|
|
|
|
(provide span)
|
|
|
|
(define (loc-span start-loc end-loc)
|
|
|
|
(define (span lexeme-start lexeme-end)
|
|
|
|
(- (loc-position end-loc)
|
|
|
|
(abs ; thus same result in reverse order
|
|
|
|
(loc-position start-loc)))
|
|
|
|
(- (position lexeme-end)
|
|
|
|
|
|
|
|
(position lexeme-start))))
|