summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJessica Clarke2020-09-21 03:13:19 +0100
committerJessica Clarke2020-09-21 03:13:19 +0100
commit1c14f5e373059fb00fce46f92ec75522f562aca1 (patch)
treef36f0037def0ec682ae7e2ddfc2bbcf3543ee35e /src
parent43612633c7df7a3c96ae463e402d9a0e2c6e121a (diff)
Strip leading *'s from saildoc
We now parse /*! * Paragraph */ and /*! *Paragraph */ the same as /*! Paragraph */ since the first form is prettier, and similar to what Doxygen, Javadoc and other such tools allow. This can cause mild confusion, as if the start of a line in the final form happens to have a * then it will unexpectedly remove it, but this is a problem shared by those tools too and the intent is that everyone just use the first form and never need to worry about it.
Diffstat (limited to 'src')
-rw-r--r--src/lexer.mll24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/lexer.mll b/src/lexer.mll
index d2901bdb..153467c1 100644
--- a/src/lexer.mll
+++ b/src/lexer.mll
@@ -195,7 +195,8 @@ let comments = ref []
}
-let ws = [' ''\t']+
+let wsc = [' ''\t']
+let ws = wsc+
let letter = ['a'-'z''A'-'Z''?']
let digit = ['0'-'9']
let binarydigit = ['0'-'1''_']
@@ -260,7 +261,7 @@ rule token = parse
| "<-" { LtMinus }
| "=>" { EqGt(r "=>") }
| "<=" { (LtEq(r"<=")) }
- | "/*!" { Doc (doc_comment (Lexing.lexeme_start_p lexbuf) (Buffer.create 10) 0 lexbuf) }
+ | "/*!" wsc* { Doc (doc_comment (Lexing.lexeme_start_p lexbuf) (Buffer.create 10) 0 false lexbuf) }
| "//" { line_comment (Lexing.lexeme_start_p lexbuf) (Buffer.create 10) lexbuf; token lexbuf }
| "/*" { comment (Lexing.lexeme_start_p lexbuf) (Buffer.create 10) 0 lexbuf; token lexbuf }
| "*/" { raise (LexError("Unbalanced comment", Lexing.lexeme_start_p lexbuf)) }
@@ -308,15 +309,20 @@ and line_comment pos b = parse
| _ as c { Buffer.add_string b (String.make 1 c); line_comment pos b lexbuf }
| eof { raise (LexError("File ended before newline in comment", pos)) }
-and doc_comment pos b depth = parse
- | "/*!" { doc_comment pos b (depth + 1) lexbuf }
- | "/*" { doc_comment pos b (depth + 1) lexbuf }
- | "*/" { if depth = 0 then Buffer.contents b
- else if depth > 0 then doc_comment pos b (depth - 1) lexbuf
+and doc_comment pos b depth lstart = parse
+ | "/*!" { doc_comment pos b (depth + 1) false lexbuf }
+ | "/*" { doc_comment pos b (depth + 1) false lexbuf }
+ | wsc* "*/" { if depth = 0 then Buffer.contents b
+ else if depth > 0 then doc_comment pos b (depth - 1) false lexbuf
else assert false }
| eof { raise (LexError("Unbalanced comment", pos)) }
- | "\n" { Buffer.add_string b "\n"; Lexing.new_line lexbuf; doc_comment pos b depth lexbuf }
- | _ as c { Buffer.add_string b (String.make 1 c); doc_comment pos b depth lexbuf }
+ | "\n" { Buffer.add_string b "\n"; Lexing.new_line lexbuf; doc_comment pos b depth true lexbuf }
+ | wsc* "*" wsc? as prefix { if lstart then (
+ doc_comment pos b depth false lexbuf
+ ) else (
+ Buffer.add_string b prefix; doc_comment pos b depth false lexbuf
+ ) }
+ | _ as c { Buffer.add_string b (String.make 1 c); doc_comment pos b depth false lexbuf }
and comment pos b depth = parse
| "/*" { comment pos b (depth + 1) lexbuf }