dev-srcloc
Matthew Butterick 8 years ago
parent 83c83dd350
commit 8e32cf31f7

@ -4,14 +4,15 @@
#'(#%module-begin #'(#%module-begin
(define result-string PARSE-TREE) (define result-string PARSE-TREE)
(define validated-jsexpr (string->jsexpr result-string)) (define validated-jsexpr (string->jsexpr result-string))
(display (jsexpr->string validated-jsexpr)))) (display result-string)))
(provide (rename-out [js-module-begin #%module-begin])) (provide (rename-out [js-module-begin #%module-begin]))
(define-macro (jsonic-program S-EXP-OR-JSON-CHAR ...) (define-macro (jsonic-program SEXP-OR-JSON-STR ...)
#'(string-append S-EXP-OR-JSON-CHAR ...)) #'(string-trim (string-append SEXP-OR-JSON-STR ...)))
(provide jsonic-program) (provide jsonic-program)
(define-macro (json-char CHAR-STR) #'CHAR-STR) (define-macro (json-char CHAR-STR)
#'CHAR-STR)
(provide json-char) (provide json-char)
(define-macro (s-exp SEXP-STR) (define-macro (s-exp SEXP-STR)

@ -5,8 +5,8 @@
(define our-lexer (define our-lexer
(lexer (lexer
[(eof) eof] [(eof) eof]
[(between "//" "\n") (next-token)] [(from/to "//" "\n") (next-token)]
[(between "@$" "$@") [(from/to "@$" "$@")
(token 'SEXP-TOK (trim-ends "@$" lexeme "$@"))] (token 'SEXP-TOK (trim-ends "@$" lexeme "$@"))]
[any-char (token 'CHAR-TOK lexeme)])) [any-char (token 'CHAR-TOK lexeme)]))
(our-lexer port)) (our-lexer port))

@ -987,7 +987,7 @@ Repeatedly apply @racket[tokenizer] to @racket[source-string], gathering the res
[str string?] [str string?]
[right-str string?]) [right-str string?])
string?]{ string?]{
Remove @racket[left-str] from the left side of @racket[str], and @racket[right-str] from its right side. Intended as a helper function for @racket[between]. Remove @racket[left-str] from the left side of @racket[str], and @racket[right-str] from its right side. Intended as a helper function for @racket[from/to].
} }
@ -1050,7 +1050,7 @@ one character.}
Character ranges, matching characters between successive pairs of Character ranges, matching characters between successive pairs of
characters.} characters.}
@defform[(between open close)]{ @defform[(from/to open close)]{
A string that is bounded by @racket[open] and @racket[close]. Matching is non-greedy (meaning, it stops at the first occurence of @racket[close]). The resulting lexeme includes @racket[open] and @racket[close]. To remove them, see @racket[trim-ends].} A string that is bounded by @racket[open] and @racket[close]. Matching is non-greedy (meaning, it stops at the first occurence of @racket[close]). The resulting lexeme includes @racket[open] and @racket[close]. To remove them, see @racket[trim-ends].}

@ -10,7 +10,7 @@
[struct-out exn:fail:parsing] [struct-out exn:fail:parsing]
apply-tokenizer apply-tokenizer
trim-ends trim-ends
between) from/to)
(struct token-struct (type val offset line column span skip?) (struct token-struct (type val offset line column span skip?)
@ -53,7 +53,7 @@
(define (trim-ends left lexeme right) (define (trim-ends left lexeme right)
(string-trim (string-trim lexeme left #:right? #f) right #:left? #f)) (string-trim (string-trim lexeme left #:right? #f) right #:left? #f))
(define-lex-trans between (define-lex-trans from/to
(λ(stx) (λ(stx)
(syntax-case stx () (syntax-case stx ()
[(_ OPEN CLOSE) [(_ OPEN CLOSE)

Loading…
Cancel
Save