From 87218276a42635aad90a91757d431a9cb61983a4 Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Tue, 22 Apr 2003 10:17:04 +0000 Subject: [PATCH] The two lexers now raise CicTextualParser0.LexerFailure instead of Failure "int_of_string". Easier to catch. --- .../cic_textual_parser/cicTextualLexer.mll | 26 ++++++++++++------- .../cic_textual_parser/cicTextualParser0.ml | 1 + .../texCicTextualLexer.mll | 26 ++++++++++++------- 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/helm/ocaml/cic_textual_parser/cicTextualLexer.mll b/helm/ocaml/cic_textual_parser/cicTextualLexer.mll index 58e6cf35b..6db492ee1 100644 --- a/helm/ocaml/cic_textual_parser/cicTextualLexer.mll +++ b/helm/ocaml/cic_textual_parser/cicTextualLexer.mll @@ -31,21 +31,29 @@ let indtyuri_of_uri uri = let index_sharp = String.index uri '#' in let index_num = index_sharp + 3 in - (UriManager.uri_of_string (String.sub uri 0 index_sharp), - int_of_string (String.sub uri index_num (String.length uri - index_num)) - 1 - ) + try + (UriManager.uri_of_string (String.sub uri 0 index_sharp), + int_of_string(String.sub uri index_num (String.length uri - index_num)) - 1 + ) + with + Failure msg -> + raise (CicTextualParser0.LexerFailure "Not an inductive URI") ;; let indconuri_of_uri uri = let index_sharp = String.index uri '#' in let index_div = String.rindex uri '/' in let index_con = index_div + 1 in - (UriManager.uri_of_string (String.sub uri 0 index_sharp), - int_of_string - (String.sub uri (index_sharp + 3) (index_div - index_sharp - 3)) - 1, - int_of_string - (String.sub uri index_con (String.length uri - index_con)) - ) + try + (UriManager.uri_of_string (String.sub uri 0 index_sharp), + int_of_string + (String.sub uri (index_sharp + 3) (index_div - index_sharp - 3)) - 1, + int_of_string + (String.sub uri index_con (String.length uri - index_con)) + ) + with + Failure msg -> + raise (CicTextualParser0.LexerFailure "Not a constructor URI") ;; } let num = ['1'-'9']['0'-'9']* | '0' diff --git a/helm/ocaml/cic_textual_parser/cicTextualParser0.ml b/helm/ocaml/cic_textual_parser/cicTextualParser0.ml index e75f61bd7..7a53057e2 100644 --- a/helm/ocaml/cic_textual_parser/cicTextualParser0.ml +++ b/helm/ocaml/cic_textual_parser/cicTextualParser0.ml @@ -24,6 +24,7 @@ *) exception Eof;; +exception LexerFailure of string;; type uri = ConUri of UriManager.uri diff --git a/helm/ocaml/tex_cic_textual_parser/texCicTextualLexer.mll b/helm/ocaml/tex_cic_textual_parser/texCicTextualLexer.mll index 25fc01311..7f70b8e88 100644 --- a/helm/ocaml/tex_cic_textual_parser/texCicTextualLexer.mll +++ b/helm/ocaml/tex_cic_textual_parser/texCicTextualLexer.mll @@ -31,21 +31,29 @@ let indtyuri_of_uri uri = let index_sharp = String.index uri '#' in let index_num = index_sharp + 3 in - (UriManager.uri_of_string (String.sub uri 0 index_sharp), - int_of_string (String.sub uri index_num (String.length uri - index_num)) - 1 - ) + try + (UriManager.uri_of_string (String.sub uri 0 index_sharp), + int_of_string(String.sub uri index_num (String.length uri - index_num)) - 1 + ) + with + Failure msg -> + raise (CicTextualParser0.LexerFailure "Not an inductive URI") ;; let indconuri_of_uri uri = let index_sharp = String.index uri '#' in let index_div = String.rindex uri '/' in let index_con = index_div + 1 in - (UriManager.uri_of_string (String.sub uri 0 index_sharp), - int_of_string - (String.sub uri (index_sharp + 3) (index_div - index_sharp - 3)) - 1, - int_of_string - (String.sub uri index_con (String.length uri - index_con)) - ) + try + (UriManager.uri_of_string (String.sub uri 0 index_sharp), + int_of_string + (String.sub uri (index_sharp + 3) (index_div - index_sharp - 3)) - 1, + int_of_string + (String.sub uri index_con (String.length uri - index_con)) + ) + with + Failure msg -> + raise (CicTextualParser0.LexerFailure "Not a constructor URI") ;; (* TeX unquoting for "_" *) -- 2.39.2