rudimentary jsonic lexer
parent
9e8135ee05
commit
9e02db875f
@ -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
|
||||
syntax-color/racket-lexer
|
||||
(prefix-in : parser-tools/lex-sre))
|
||||
|
||||
(provide default-lexer)
|
||||
|
||||
|
||||
(define default-lexer
|
||||
(lexer
|
||||
[(eof) (values lexeme 'eof #f #f #f)]
|
||||
[(:seq "//" (:* (char-complement "\n")))
|
||||
(values lexeme 'comment #f (position-offset start-pos) (position-offset end-pos))]
|
||||
[any-char (values lexeme 'no-color #f (position-offset start-pos) (position-offset end-pos))]))
|
||||
(provide drracket-lexer)
|
||||
|
||||
(define drracket-lexer
|
||||
(let ([in-racket-expr? #f])
|
||||
(lexer
|
||||
[(eof) (values lexeme 'eof #f #f #f)]
|
||||
["@$" (begin
|
||||
(set! in-racket-expr? #t)
|
||||
(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
|
||||
{
|
||||
"number": @$(* 6 7)$@,
|
||||
"string": @$(string-append "foo" "bar")$@,
|
||||
"array": @$(range 5)$@,
|
||||
"object": @$(hash "k1" "valstring" (format "~a" 42) (hash "k1" (range 10) "k2" 42))$@
|
||||
"string": @$(string-append "foo" "bar")$@,
|
||||
"array": @$(range 5)$@,
|
||||
"object": @$(hash "k1" "valstring" (format "~a" 42) (hash "k1" (range 10) "k2" 42))$@
|
||||
// "bar" :
|
||||
}
|
Loading…
Reference in New Issue