From f03690fc1b1a322f3abff7e55ec9a4fee4ecd81d Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Fri, 25 May 2018 21:59:59 -0400 Subject: [PATCH] Re-org testing code --- tiger/src/exe/tiger_tests.ml | 42 ++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/tiger/src/exe/tiger_tests.ml b/tiger/src/exe/tiger_tests.ml index 266797e..2def01a 100644 --- a/tiger/src/exe/tiger_tests.ml +++ b/tiger/src/exe/tiger_tests.ml @@ -147,27 +147,6 @@ let test_09 = (* TODO: Type error test case *) (name, code, tokens) -let tokens_of_code code = - let lexbuf = Lexing.from_string code in - let rec tokens () = - let token = Tiger.Lexer.token lexbuf in - (* Avoiding fragile pattern-matching *) - if token = Tiger.Parser.EOF then [] else token :: tokens () - in - tokens () - -let parsetree_of_code code = - let lb = Lexing.from_string code in - (match Tiger.Parser.program Tiger.Lexer.token lb with - | exception Parsing.Parse_error -> - let module L = Lexing in - let L.({lex_curr_p = {pos_lnum=l; pos_bol=b; pos_cnum=c; _}; _}) = lb in - let msg = sprintf "Syntax error around line: %d, column: %d" l (c - b) in - Error msg - | parsetree -> - Ok parsetree - ) - let tests = [ test_01 ; test_02 @@ -177,6 +156,27 @@ let tests = ] let () = + let tokens_of_code code = + let lexbuf = Lexing.from_string code in + let rec tokens () = + let token = Tiger.Lexer.token lexbuf in + (* Avoiding fragile pattern-matching *) + if token = Tiger.Parser.EOF then [] else token :: tokens () + in + tokens () + in + let parsetree_of_code code = + let lb = Lexing.from_string code in + (match Tiger.Parser.program Tiger.Lexer.token lb with + | exception Parsing.Parse_error -> + let module L = Lexing in + let L.({lex_curr_p = {pos_lnum=l; pos_bol=b; pos_cnum=c; _}; _}) = lb in + let msg = sprintf "Syntax error around line: %d, column: %d" l (c - b) in + Error msg + | parsetree -> + Ok parsetree + ) + in let bar_sep = String.make 80 '-' in let bar_end = String.make 80 '=' in let indent n = String.make (2 * n) ' ' in -- 2.20.1