Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed parser bug whith comments within verbatim block

  • Loading branch information...
commit e6c577cc9e132464b2c695fa8fd9ddf34ffb481a 1 parent f9d0a37
@AltGr AltGr authored
View
43 src/approx_lexer.mll
@@ -182,6 +182,7 @@ let in_comment () = match !comment_stack with
| (Comment | CommentCont | Verbatim) :: _ -> true
| Code :: _ | [] -> false
;;
+let in_verbatim () = List.mem Verbatim !comment_stack
let init () =
lines_starts := [];
@@ -508,30 +509,32 @@ and comment = parse
}
| "*)"
{ let tok = close_comment () in
- match !comment_stack with
+ if in_verbatim () then verbatim lexbuf
+ else match !comment_stack with
| (Comment | CommentCont) :: _ -> comment lexbuf
| _ -> tok
}
| newline? blank* '{' [ '[' 'v' ]
- { let tok = match !comment_stack with
- | CommentCont::_ -> COMMENTCONT
- | Comment::r ->
- comment_stack := CommentCont::r;
- COMMENT
- | _s -> assert false
- in
- let block =
- match lexbuf.lex_buffer.[lexbuf.lex_curr_pos - 1] with
- | '[' -> Code
- | 'v' -> Verbatim
- | _ -> assert false
- in
- comment_stack := block :: !comment_stack;
- entering_inline_code_block := true;
- (* unparse the token, to be parsed again as code *)
- lexbuf.Lexing.lex_curr_p <- lexbuf.Lexing.lex_start_p;
- lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_start_pos;
- tok
+ { if in_verbatim() then comment lexbuf else
+ let tok = match !comment_stack with
+ | CommentCont::_ -> COMMENTCONT
+ | Comment::r ->
+ comment_stack := CommentCont::r;
+ COMMENT
+ | _s -> assert false
+ in
+ let block =
+ match lexbuf.lex_buffer.[lexbuf.lex_curr_pos - 1] with
+ | '[' -> Code
+ | 'v' -> Verbatim
+ | _ -> assert false
+ in
+ comment_stack := block :: !comment_stack;
+ entering_inline_code_block := true;
+ (* unparse the token, to be parsed again as code *)
+ lexbuf.Lexing.lex_curr_p <- lexbuf.Lexing.lex_start_p;
+ lexbuf.Lexing.lex_curr_pos <- lexbuf.Lexing.lex_start_pos;
+ tok
}
| "\""
{ reset_string_buffer();
View
2  tests/failing-output/js-comment.ml
@@ -113,7 +113,7 @@ verbatim block is. But how will this be done in vim?
(* {v
- (* comments embedded in verbatim sections *)
+(* comments embedded in verbatim sections *)
(* want to be able to verbatim-out big chunks of code *)
v} *)
View
26 tests/failing.html
@@ -2,7 +2,7 @@
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
- <title>Failing tests, ocp-indent version 1.0.2+6 (2013-03-14)</title>
+ <title>Failing tests, ocp-indent version 1.0.2+7 (2013-03-14)</title>
<style>
BODY { font-family: monospace; }
TABLE { border-collapse: collapse; border-spacing: 0px; margin: auto; }
@@ -22,14 +22,14 @@
</style>
</head>
<body>
-<h1>Failing tests, ocp-indent version 1.0.2+6 (2013-03-14)</h1>
+<h1>Failing tests, ocp-indent version 1.0.2+7 (2013-03-14)</h1>
<p>Left is expected result, right shows actual indentation by ocp-indent</p>
<table>
<tr><td width="70%">
<table>
<tr>
<td class="modified">Modified line(s):&nbsp;</td>
- <td class="modified"><a href='#failing/js-comment.ml.ref_60'>60</a>&nbsp; <a href='#failing/js-comment.ml.ref_61'>61</a>&nbsp; <a href='#failing/js-comment.ml.ref_62'>62</a>&nbsp; <a href='#failing/js-comment.ml.ref_63'>63</a>&nbsp; <a href='#failing/js-comment.ml.ref_72'>72</a>&nbsp; <a href='#failing/js-comment.ml.ref_73'>73</a>&nbsp; <a href='#failing/js-comment.ml.ref_74'>74</a>&nbsp; <a href='#failing/js-comment.ml.ref_75'>75</a>&nbsp; <a href='#failing/js-comment.ml.ref_98'>98</a>&nbsp; <a href='#failing/js-comment.ml.ref_116'>116</a>&nbsp; </td>
+ <td class="modified"><a href='#failing/js-comment.ml.ref_60'>60</a>&nbsp; <a href='#failing/js-comment.ml.ref_61'>61</a>&nbsp; <a href='#failing/js-comment.ml.ref_62'>62</a>&nbsp; <a href='#failing/js-comment.ml.ref_63'>63</a>&nbsp; <a href='#failing/js-comment.ml.ref_72'>72</a>&nbsp; <a href='#failing/js-comment.ml.ref_73'>73</a>&nbsp; <a href='#failing/js-comment.ml.ref_74'>74</a>&nbsp; <a href='#failing/js-comment.ml.ref_75'>75</a>&nbsp; <a href='#failing/js-comment.ml.ref_98'>98</a>&nbsp; </td>
</tr>
<tr>
<td class="added">Added line(s):&nbsp;</td>
@@ -62,15 +62,15 @@
<td>
128 lines<br/>
2512 bytes<br/>
- Last modified : 2013-03-14 10:13:01 <br>
+ Last modified : 2013-03-14 17:55:34 <br>
<hr/>
</td>
<td width="16">&nbsp;</td>
<td width="16">&nbsp;</td>
<td>
128 lines<br/>
- 2530 bytes<br/>
- Last modified : 2013-03-14 10:13:01 <br>
+ 2525 bytes<br/>
+ Last modified : 2013-03-14 17:55:34 <br>
<hr/>
</td>
</tr>
@@ -879,12 +879,12 @@
<td class="linenum">115</td>
<td class="normal"></td>
</tr>
- <tr>
- <td class="linenum"><a name="failing/js-comment.ml.ref_116">116</a></td>
- <td class="modified">(* comments embedded in verbatim sections *)</td>
+ <tr>
+ <td class="linenum">116</td>
+ <td class="normal">(* comments embedded in verbatim sections *)</td>
<td width="16">&nbsp;</td>
<td class="linenum">116</td>
- <td class="modified">&nbsp;&nbsp;&nbsp;&nbsp; (* comments embedded in verbatim sections *)</td>
+ <td class="normal">(* comments embedded in verbatim sections *)</td>
</tr>
<tr>
<td class="linenum">117</td>
@@ -972,7 +972,7 @@
</tr>
</table>
<hr/>
-<i>Generated by <b>diff2html</b> on 2013-03-14 10:14:33</i>
+<i>Generated by <b>diff2html</b> on 2013-03-14 17:55:59</i>
<table>
<tr><td width="70%">
<table>
@@ -1019,7 +1019,7 @@
<td>
121 lines<br/>
2775 bytes<br/>
- Last modified : 2013-03-14 10:13:31 <br>
+ Last modified : 2013-03-14 17:55:34 <br>
<hr/>
</td>
</tr>
@@ -1872,6 +1872,6 @@
</tr>
</table>
<hr/>
-<i>Generated by <b>diff2html</b> on 2013-03-14 10:14:35</i>
+<i>Generated by <b>diff2html</b> on 2013-03-14 17:56:01</i>
</body>
</html>
Please sign in to comment.
Something went wrong with that request. Please try again.