Skip to content

Commit

Permalink
fixing issue #100
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 9, 2011
1 parent 4cc1a4b commit d443299
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 23 deletions.
2 changes: 1 addition & 1 deletion j/client.j
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ jl_banner_color =
$(jl)_ _ _| |_ __ _$(tx) | pre-release version
$(jl)| | | | | | |/ _` |$(tx) |
$(jl)| | |_| | | | (_| |$(tx) |
$(jl)_/ |\\\\__'_|_|_|\\\\__'_|$(tx) |
$(jl)_/ |\\__'_|_|_|\\__'_|$(tx) |
$(jl)|__/$(tx) |

\033[0m"
Expand Down
26 changes: 4 additions & 22 deletions src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@
(not (ts:space? s)))
;; custom prefixed string literals, x"s" => @x_str "s"
(let ((str (begin (take-token s)
(parse-string-literal s #t)))
(parse-string-literal s)))
(macname (symbol (string ex '_str))))
(loop `(macrocall ,macname ,(car str))))
ex))
Expand Down Expand Up @@ -856,26 +856,10 @@
(error "incomplete: invalid string syntax")
c))

(define (unescape-quotes buf)
(let ((b (open-output-string)))
(io.seek buf 0)
(let loop ((c (read-char buf)))
(if (eof-object? c)
#t
(begin (if (eqv? c #\\)
(let ((nextch (read-char buf)))
(if (or (eqv? nextch #\") (eqv? nextch #\\))
(write-char nextch b)
(begin (write-char #\\ b)
(write-char nextch b))))
(write-char c b))
(loop (read-char buf)))))
(io.tostring! b)))

; reads a raw string literal with no processing.
; quote can be escaped with \, but the \ is left in place.
; returns ("str" . b), b is a boolean telling whether interpolation is used
(define (parse-string-literal s unescape-q)
(define (parse-string-literal s)
(let ((b (open-output-string))
(p (ts:port s))
(interpolate #f)
Expand All @@ -894,9 +878,7 @@
(set! interpolate #t))
(write-char (not-eof-3 c) b)))
(loop (read-char p)))))
(if (and hasquotes (or unescape-q interpolate))
(cons (unescape-quotes b) interpolate)
(cons (io.tostring! b) interpolate))))
(cons (io.tostring! b) interpolate)))

(define (not-eof-1 c)
(if (eof-object? c)
Expand Down Expand Up @@ -1035,7 +1017,7 @@
;; string literal
((eqv? t #\")
(take-token s)
(let ((ps (parse-string-literal s #f)))
(let ((ps (parse-string-literal s)))
(if (cdr ps)
`(macrocall str ,(car ps))
(unescape-string (car ps)))))
Expand Down

3 comments on commit d443299

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good. It's easy to reason about. If we encounter any problems in the future, we can deal with those then.

@JeffBezanson
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you can tell by the big red area that this makes the system simpler. But actually nothing will make L strings work, since you need to escape quotes but those escape characters don't get removed, so you basically can't have quotes in L strings. The next problem is L"\", and for that to work the parser would have to implement L strings since otherwise it thinks the second quote is being escaped.

@StefanKarpinski
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine :-). There's just some things you can't express in L strings — but a bunch of things that are annoying/confusing to write in other types of strings get easy to write. It's a reasonable tradeoff and relatively simple to understand. It's also handy for debugging because L strings return exactly what other str_X macros get as their input.

Please sign in to comment.