summaryrefslogtreecommitdiff
path: root/ocamltest/tsl_lexer.mll
diff options
context:
space:
mode:
authorDavid Allsopp <david.allsopp@metastack.com>2018-06-07 13:24:49 +0100
committerDavid Allsopp <david.allsopp@metastack.com>2018-06-14 11:01:49 +0100
commitab69c53ef81375602728d58568cf5e3d2a2714c3 (patch)
treecbe7ce0df74a7566f47623d5cc2b1ab2b0397175 /ocamltest/tsl_lexer.mll
parentea9dc4e5552eac755cbbcfbd6006fa990d23c890 (diff)
downloadocaml-ab69c53ef81375602728d58568cf5e3d2a2714c3.tar.gz
Support continuation characters in ocamltest
Allows strings to be entered on multiple lines by permitting backslash to escape the newline sequence and optionally a backslash to escape a space at the start of the following line.
Diffstat (limited to 'ocamltest/tsl_lexer.mll')
-rw-r--r--ocamltest/tsl_lexer.mll30
1 files changed, 24 insertions, 6 deletions
diff --git a/ocamltest/tsl_lexer.mll b/ocamltest/tsl_lexer.mll
index 966483a3ee..0d9845df7f 100644
--- a/ocamltest/tsl_lexer.mll
+++ b/ocamltest/tsl_lexer.mll
@@ -54,12 +54,8 @@ rule token = parse
comment_start_pos := [Lexing.lexeme_start_p lexbuf];
comment lexbuf
}
- | "\"" [^'"']* "\""
- { let s = Lexing.lexeme lexbuf in
- let string_length = (String.length s) -2 in
- let s' = String.sub s 1 string_length in
- STRING s'
- }
+ | '"'
+ { STRING (string "" lexbuf) }
| _
{
let pos = Lexing.lexeme_start_p lexbuf in
@@ -70,6 +66,28 @@ rule token = parse
file line column (Lexing.lexeme lexbuf) in
lexer_error message
}
+(* Backslashes are ignored in strings except at the end of lines where they
+ cause the newline to be ignored. After an escaped newline, any blank
+ characters at the start of the line are ignored and optionally one blank
+ character may be escaped with a backslash.
+
+ In particular, this means that the following:
+script = "some-directory\\
+ \ foo"
+ is interpreted as the OCaml string "some-directory\\ foo".
+ *)
+and string acc = parse
+ | [^ '\\' '"' ]+
+ { string (acc ^ Lexing.lexeme lexbuf) lexbuf }
+ | '\\' newline blank* ('\\' (blank as blank))?
+ { let space =
+ match blank with None -> "" | Some blank -> String.make 1 blank
+ in
+ string (acc ^ space) lexbuf }
+ | '\\'
+ {string (acc ^ "\\") lexbuf}
+ | '"'
+ {acc}
and comment = parse
| "(*"
{