From d4fe2c92ea80550badbd114478ae50129d4f3772 Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Sun, 29 Jan 2017 23:22:53 -0800 Subject: [PATCH] return-without-srcloc --- beautiful-racket-demo/basic-demo/lexer.rkt | 15 +++++++++------ beautiful-racket-demo/basic-demo/tokenizer.rkt | 6 +----- .../parser-tools/br-parser-tools.scrbl | 11 ++++++----- .../br-parser-tools-lib/br-parser-tools/lex.rkt | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/beautiful-racket-demo/basic-demo/lexer.rkt b/beautiful-racket-demo/basic-demo/lexer.rkt index 6ce1bf2..fc98294 100644 --- a/beautiful-racket-demo/basic-demo/lexer.rkt +++ b/beautiful-racket-demo/basic-demo/lexer.rkt @@ -3,7 +3,7 @@ (define basic-lexer (lexer-srcloc - [(eof) eof] + [(eof) (return-without-srcloc eof)] [whitespace (token lexeme #:skip? #t)] [(from/to "rem" "\n") (token 'REM lexeme)] [(:or "print" "goto" "end" "+" ":") lexeme] @@ -14,8 +14,11 @@ [(from/to "\"" "\"") (token 'STRING (trim-ends "\"" lexeme "\""))])) -(provide - (contract-out - [basic-lexer - (input-port? . -> . - (or/c eof-object? string? srcloc-token?))])) \ No newline at end of file +(provide basic-lexer) + + +(define (apply-lexer lexer str) +(for/list ([t (in-port lexer (open-input-string str))]) + t)) + +(apply-lexer basic-lexer "10 rem") diff --git a/beautiful-racket-demo/basic-demo/tokenizer.rkt b/beautiful-racket-demo/basic-demo/tokenizer.rkt index cb8cd04..79191e8 100644 --- a/beautiful-racket-demo/basic-demo/tokenizer.rkt +++ b/beautiful-racket-demo/basic-demo/tokenizer.rkt @@ -7,8 +7,4 @@ (define (next-token) (basic-lexer ip)) next-token) -(provide - (contract-out - [make-tokenizer - ((input-port?) (path?) . ->* . - (-> (or/c eof-object? string? srcloc-token?)))])) \ No newline at end of file +(provide make-tokenizer) \ No newline at end of file diff --git a/br-parser-tools/br-parser-tools-doc/parser-tools/br-parser-tools.scrbl b/br-parser-tools/br-parser-tools-doc/parser-tools/br-parser-tools.scrbl index 50a3da3..33b195d 100644 --- a/br-parser-tools/br-parser-tools-doc/parser-tools/br-parser-tools.scrbl +++ b/br-parser-tools/br-parser-tools-doc/parser-tools/br-parser-tools.scrbl @@ -167,14 +167,14 @@ are a few examples, using @racket[:] prefixed SRE syntax: @item{@racket[input-port] --- the input-port being processed (this is useful for matching input with multiple lexers).} - @item{@racket[(return-without-pos x)] is a function (continuation) that - immediately returns the value of @racket[x] from the lexer. This useful - in a src-pos lexer to prevent the lexer from adding source + @item{@racket[(return-without-pos x)] and @racket[(return-without-srcloc x)] are functions (continuations) that + immediately return the value of @racket[x] from the lexer. This useful + in a src-pos or src-loc lexer to prevent the lexer from adding source information. For example: @racketblock[ (define get-token - (lexer-src-pos + (lexer-srcloc ... ((comment) (get-token input-port)) ...)) @@ -182,7 +182,7 @@ are a few examples, using @racket[:] prefixed SRE syntax: would wrap the source location information for the comment around the value of the recursive call. Using - @racket[((comment) (return-without-pos (get-token input-port)))] + @racket[((comment) (return-without-srcloc (get-token input-port)))] will cause the value of the recursive call to be returned without wrapping position around it.} ] @@ -262,6 +262,7 @@ _action-result lexeme-srcloc)] instead of simply @defidform[lexeme-srcloc] @defidform[input-port] @defidform[return-without-pos] +@defidform[return-without-srcloc] )]{ Use of these names outside of a @racket[lexer] action is a syntax diff --git a/br-parser-tools/br-parser-tools-lib/br-parser-tools/lex.rkt b/br-parser-tools/br-parser-tools-lib/br-parser-tools/lex.rkt index fc8e359..2f0a22e 100644 --- a/br-parser-tools/br-parser-tools-lib/br-parser-tools/lex.rkt +++ b/br-parser-tools/br-parser-tools-lib/br-parser-tools/lex.rkt @@ -46,7 +46,7 @@ [(eq? src-loc-style 'lexer-srcloc) #`(let/ec ret (syntax-parameterize - ([return-without-pos (make-rename-transformer #'ret)]) + ([return-without-srcloc (make-rename-transformer #'ret)]) (make-srcloc-token #,action lexeme-srcloc)))] [else action]))) (syntax/loc action @@ -405,6 +405,6 @@ ... (provide id ...))])) - (provide-lex-keyword start-pos end-pos lexeme lexeme-srcloc input-port return-without-pos) + (provide-lex-keyword start-pos end-pos lexeme lexeme-srcloc input-port return-without-pos return-without-srcloc) )