How does one match backslash followed by "?

I’ve tried:

and string_detect collect = parse
  | '\"' { STRING collect }
  | '\\'|'\''|'\"'|'\t'|'\n'|'\r'|'\b'|' ' as c { string_detect (collect^(String.make 1 c)) lexbuf }
  (* | ['\\' '\"'] as s { string_detect (collect^ String.make 1 s) lexbuf } *)

  | "\\\"" as s { string_detect (collect^s) lexbuf }
  (* | "," as c { string_detect (collect^String.make 1 c) lexbuf } *)
  | (alphanum | "_")* as s { string_detect (collect^s) lexbuf}

but nothing seems to work.

I want to match:

get_all_tokens "\\\"";;

ok the test was wrong this works:

get_all_tokens " \" \\\" \" ";;

You should also be able to do

get_all_tokens {| " \" " |}

without the need of escaping.

1 Like