rudimentary jsonic lexer

dev-srcloc
Matthew Butterick 8 years ago
parent 9e8135ee05
commit 9e02db875f

@ -16,6 +16,11 @@
(define-namespace-anchor nsa) (define-namespace-anchor nsa)
(eval DATUM (namespace-anchor->namespace nsa)))) (eval DATUM (namespace-anchor->namespace nsa))))
(provide really-dynamic-require)
(define-macro (really-dynamic-require . ARGS)
#'(parameterize ([current-namespace (make-base-namespace)])
(dynamic-require . ARGS)))
(module reader syntax/module-reader (module reader syntax/module-reader
#:language 'br #:language 'br
#:info br-get-info #:info br-get-info

@ -1 +1,12 @@
#lang racket/base #lang br
(require racket/class)
(provide drracket-indenter)
(define (drracket-indenter t pos)
#;(with-handlers ([exn:fail? (λ(exn) #f)]) ; this function won't work until gui-lib 1.26
(send t compute-racket-amount-to-indent pos (λ(x)
(case x
[("with-pattern" "with-shared-id") 'lambda]
[("define-macro") 'define]
[else #f]))))
#f)

@ -1,14 +1,24 @@
#lang racket/base #lang br
(require parser-tools/lex (require parser-tools/lex
syntax-color/racket-lexer
(prefix-in : parser-tools/lex-sre)) (prefix-in : parser-tools/lex-sre))
(provide default-lexer) (provide drracket-lexer)
(define drracket-lexer
(define default-lexer (let ([in-racket-expr? #f])
(lexer (lexer
[(eof) (values lexeme 'eof #f #f #f)] [(eof) (values lexeme 'eof #f #f #f)]
[(:seq "//" (:* (char-complement "\n"))) ["@$" (begin
(values lexeme 'comment #f (position-offset start-pos) (position-offset end-pos))] (set! in-racket-expr? #t)
[any-char (values lexeme 'no-color #f (position-offset start-pos) (position-offset end-pos))])) (values lexeme 'parenthesis '|(| (position-offset start-pos) (position-offset end-pos)))]
["$@" (begin
(set! in-racket-expr? #f)
(values lexeme 'parenthesis '|)| (position-offset start-pos) (position-offset end-pos)))]
[(:seq "//" (:* (char-complement #\newline)))
(values lexeme 'comment #f (position-offset start-pos) (position-offset end-pos))]
[any-char
(if in-racket-expr?
(racket-lexer (transplant-input-port (open-input-string lexeme) #f (position-offset start-pos)))
(values lexeme 'string #f (position-offset start-pos) (position-offset end-pos)))])))

@ -1,8 +1,7 @@
#lang br/demo/jsonic #lang br/demo/jsonic
{ {
"number": @$(* 6 7)$@, "string": @$(string-append "foo" "bar")$@,
"string": @$(string-append "foo" "bar")$@, "array": @$(range 5)$@,
"array": @$(range 5)$@, "object": @$(hash "k1" "valstring" (format "~a" 42) (hash "k1" (range 10) "k2" 42))$@
"object": @$(hash "k1" "valstring" (format "~a" 42) (hash "k1" (range 10) "k2" 42))$@
// "bar" : // "bar" :
} }

@ -28,9 +28,9 @@
(λ (key default) (λ (key default)
(case key (case key
[(color-lexer) [(color-lexer)
(dynamic-require 'br/demo/jsonic/drracket-lexer 'default-lexer (λ () #f))] (really-dynamic-require 'br/demo/jsonic/drracket-lexer 'drracket-lexer (λ () #f))]
[(drracket:indentation) [(drracket:indentation)
(dynamic-require 'scribble/private/indentation 'determine-spaces)] (really-dynamic-require 'br/demo/jsonic/drracket-indenter 'drracket-indenter (λ () #f))]
[else default]))) [else default])))
(define (test-tokenize str) (define (test-tokenize str)

Loading…
Cancel
Save