Skip to content

Commit

Permalink
[fix] jsparse: discard unused tokens in junk.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthuraa committed Aug 17, 2012
1 parent f60e101 commit 5198482
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions compiler/jslang/jsParse.ml
Expand Up @@ -139,17 +139,21 @@ struct
with Queue.Empty -> Stream.junk stream.stream
)

let rec junk stream =
match Stream.peek stream.stream with
| Some (LT _ as s) ->
stream.waiting_newline <- Some s;
Stream.junk stream.stream;
junk stream
| Some (DocComment _ as s) when stream.ignore_comments ->
Queue.add s stream.waiting_comments;
Stream.junk stream.stream;
junk stream
| _ -> Stream.junk stream.stream
let junk stream =
(* At junk, we assume that all tokens that have been ignored and
held can be discarded *)
stream.waiting_newline <- None;
Queue.clear stream.waiting_comments;
let rec loop () =
match Stream.peek stream.stream with
| Some (LT _) ->
Stream.junk stream.stream;
loop ()
| Some (DocComment _) when stream.ignore_comments ->
Stream.junk stream.stream;
loop ()
| _ -> Stream.junk stream.stream
in loop ()

(* redefining empty because a stream with only a newline must be considered
* as empty *)
Expand Down

0 comments on commit 5198482

Please sign in to comment.