summaryrefslogtreecommitdiff
path: root/ocamltest/tsl_lexer.mll
diff options
context:
space:
mode:
authorSébastien Hinderer <Sebastien.Hinderer@inria.fr>2017-07-21 16:43:36 +0200
committerDamien Doligez <damien.doligez@gmail.com>2017-09-18 17:40:14 +0200
commit635b5edcc1a0ce40d974295a696fbb3dea2f0766 (patch)
treea7ca13c2a2e09d1ce027748281729a2de60a6e31 /ocamltest/tsl_lexer.mll
parentb08deacf182decf4fef22900371ddc860b666447 (diff)
downloadocaml-635b5edcc1a0ce40d974295a696fbb3dea2f0766.tar.gz
ocamltest: the test driver for the OCaml compiler
This commit contains: - The initial version of the tool itself, in the ocamltest directory - The required additions to the main .gitignore and .merlin files. The integration of ocamltest in OCaml's main build system and its use in the testsuite are not part of this commit. Credits go to David Allsopp for - Extending the computation of ocamlsrcdir to the Windows case - Making ocamltest compile when flexlink is being bootstrapped.
Diffstat (limited to 'ocamltest/tsl_lexer.mll')
-rw-r--r--ocamltest/tsl_lexer.mll96
1 files changed, 96 insertions, 0 deletions
diff --git a/ocamltest/tsl_lexer.mll b/ocamltest/tsl_lexer.mll
new file mode 100644
index 0000000000..b14cee89bb
--- /dev/null
+++ b/ocamltest/tsl_lexer.mll
@@ -0,0 +1,96 @@
+(**************************************************************************)
+(* *)
+(* OCaml *)
+(* *)
+(* Sebastien Hinderer, projet Gallium, INRIA Paris *)
+(* *)
+(* Copyright 2016 Institut National de Recherche en Informatique et *)
+(* en Automatique. *)
+(* *)
+(* All rights reserved. This file is distributed under the terms of *)
+(* the GNU Lesser General Public License version 2.1, with the *)
+(* special exception on linking described in the file LICENSE. *)
+(* *)
+(**************************************************************************)
+
+(* Lexer definitions for the Tests Specification Language *)
+
+{
+open Tsl_parser
+
+let comment_start_pos = ref []
+
+let lexer_error message =
+ Printf.eprintf "%s\n%!" message;
+ exit 2
+
+}
+
+let newline = ('\013'* '\010')
+let blank = [' ' '\009' '\012']
+let identchar = ['A'-'Z' 'a'-'z' '_' '\'' '0'-'9']
+
+rule token = parse
+ | blank * { token lexbuf }
+ | newline { Lexing.new_line lexbuf; token lexbuf }
+ | "/*" blank* "TEST" { TSL_BEGIN_C_STYLE }
+ | "*/" { TSL_END_C_STYLE }
+ | "(*" blank* "TEST" { TSL_BEGIN_OCAML_STYLE }
+ | "*)" { TSL_END_OCAML_STYLE }
+ | "," { COMA }
+ | '*'+ { TEST_DEPTH (String.length (Lexing.lexeme lexbuf)) }
+ | "=" { EQUAL }
+ | identchar *
+ { let s = Lexing.lexeme lexbuf in
+ match s with
+ | "include" -> INCLUDE
+ | "with" -> WITH
+ | _ -> IDENTIFIER s
+ }
+ | "(*"
+ {
+ 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'
+ }
+ | _
+ {
+ let pos = Lexing.lexeme_start_p lexbuf in
+ let file = pos.Lexing.pos_fname in
+ let line = pos.Lexing.pos_lnum in
+ let column = pos.Lexing.pos_cnum - pos.Lexing.pos_bol in
+ let message = Printf.sprintf "%s:%d:%d: unexpected character %s"
+ file line column (Lexing.lexeme lexbuf) in
+ lexer_error message
+ }
+and comment = parse
+ | "(*"
+ {
+ comment_start_pos :=
+ (Lexing.lexeme_start_p lexbuf) :: !comment_start_pos;
+ comment lexbuf
+ }
+ | "*)"
+ {
+ comment_start_pos := List.tl !comment_start_pos;
+ if !comment_start_pos = [] then token lexbuf else comment lexbuf
+ }
+ | eof
+ {
+ let pos = List.hd !comment_start_pos in
+ let file = pos.Lexing.pos_fname in
+ let line = pos.Lexing.pos_lnum in
+ let column = pos.Lexing.pos_cnum - pos.Lexing.pos_bol in
+ let message = Printf.sprintf "%s:%d:%d: unterminated comment"
+ file line column in
+ lexer_error message
+ }
+ | _
+ {
+ comment lexbuf
+ }