Permalink
Browse files

employ the full parser, as the lexer alone can't properly detect rege…

…xps at

beginning of statement (requires
marijnh/parse-js@5fbfeee )
  • Loading branch information...
1 parent 53fe06e commit f92b62d8477f7e544c39cfb26c09f5bee84fd887 @mishoo committed Feb 11, 2011
Showing with 14 additions and 17 deletions.
  1. +14 −17 src/split.lisp
View
@@ -9,25 +9,22 @@ never splits *after* a :KEYWORD (in order not to break the JS
semantics, which say that no newline is allowed between return or
throw and their arguments)."
(with-input-from-string (stream code)
- (let ((tokenizer (lex-js stream :include-comments t))
- (this-token nil)
+ (let ((this-token nil)
(prev-token nil)
- (splits (list 0)))
- (labels ((next-token ()
- (setf prev-token this-token
- this-token (funcall tokenizer)))
- (current-length ()
+ (splits (list 0))
+ (next-token (lex-js stream :include-comments t)))
+ (labels ((current-length ()
(- (token-pos this-token) (car splits)))
(split-here ()
(push (token-pos this-token) splits)))
- (iter (for i = (next-token))
- (until (eq :eof (token-type i)))
- (when (and prev-token
- (eq :keyword (token-type prev-token)))
- (next-iteration))
- (when (> (current-length) maxlen)
- (when (member (token-type this-token) '(:keyword :atom :name :punc))
- (split-here))))
+ (parse-js (lambda (&rest args)
+ (setf this-token (apply next-token args))
+ (unless (and prev-token
+ (eq :keyword (token-type prev-token)))
+ (when (> (current-length) maxlen)
+ (case (token-type this-token)
+ ((:keyword :atom :name :punc) (split-here)))))
+ (setf prev-token this-token)) :ecma-version 5)
(format nil "~{~A~^~%~}"
- (iter (for (from to) on (nreverse splits))
- (collect (subseq code from to))))))))
+ (loop :for (from to) :on (nreverse splits)
+ :collecting (subseq code from to)))))))

0 comments on commit f92b62d

Please sign in to comment.