Permalink
Browse files

Lex unsafe comments

Summary:
We now lex

    // UNSAFE

as a special comment kind.

Reviewed By: savil

Differential Revision: D4397942

fbshipit-source-id: dc3cb7cb8e6ccf9ec49edc9c34a932a0b1e9b267
  • Loading branch information...
1 parent 2a34ff3 commit 30d57de58dc63a3a2bbbf815b50535c43c7f9851 @ericlippert ericlippert committed with hhvm-bot Jan 12, 2017
@@ -933,16 +933,21 @@ let scan_whitespace lexer =
let scan_single_line_comment lexer =
(* A fallthrough comment is two slashes, any amount of whitespace,
FALLTHROUGH, and the end of the line.
- TODO: Consider allowing trailing space.
+ An unsafe comment is two slashes, any amount of whitespace,
+ UNSAFE, and then any characters may follow.
+ TODO: Consider allowing trailing space for fallthrough.
TODO: Consider allowing lowercase fallthrough.
*)
let lexer = advance lexer 2 in
let lexer_ws = skip_whitespace lexer in
let lexer = skip_to_end_of_line lexer_ws in
let w = width lexer in
- let c = if lexer.offset - lexer_ws.offset = 11 &&
- peek_string lexer_ws 11 = "FALLTHROUGH" then
+ let remainder = lexer.offset - lexer_ws.offset in
+ let c =
+ if remainder = 11 && peek_string lexer_ws 11 = "FALLTHROUGH" then
Trivia.make_fallthrough w
+ else if remainder >= 6 && peek_string lexer_ws 6 = "UNSAFE" then
+ Trivia.make_unsafe w
else
Trivia.make_single_line_comment w in
(lexer, c)
@@ -34,6 +34,9 @@ let make_single_line_comment width =
let make_fallthrough width =
{ kind = FallThrough; width }
+let make_unsafe width =
+ { kind = Unsafe; width }
+
let make_delimited_comment width =
{ kind = DelimitedComment; width }

0 comments on commit 30d57de

Please sign in to comment.